Skip to content

Latest commit

 

History

History
457 lines (371 loc) · 16.6 KB

config.org

File metadata and controls

457 lines (371 loc) · 16.6 KB

### Non-config ###

Discussion about config and helpful emacs tips

Tips

Edit src block in major mode

“Protip: C-c ’ opens up the org src block under the cursor into its major mode, which allows you to edit as if it was in a .el file. C-c ’ again saves the block.”

Vim Registers

  1. Yank to a register by doing "ay that is [S-’ a y] this would copy whatever region is yanked to register a

### CONFIG STARTS ###

Personal Config

;;; EMAIL
(setq user-full-name "Maxwell Morris"
      user-mail-address "[email protected]")

;;; FONTS
;; (setq doom-font (font-spec :family "Jetbrains Mono" :size 13 :weight 'semi-light)
;;       doom-variable-pitch-font (font-spec :family "Noto Serif" :size 13))
(after! doom-themes
  (setq doom-themes-enable-bold t
        doom-themes-enable-italic t))
(custom-set-faces!
  '(font-lock-comment-face :slant italic)
  '(font-lock-comment-face :slant italic))

Org

Org Mode

;;; THEME

(add-to-list 'default-frame-alist '(inhibit-double-buffering . t))

;;;ORG SUPERSTAR
(with-eval-after-load 'org-superstar
  (set-face-attribute 'org-superstar-item nil :height 1.3)
  (set-face-attribute 'org-superstar-header-bullet nil :height 1.3)
  (set-face-attribute 'org-superstar-leading nil :height 1.4));; Set different bullets, with one getting a terminal fallback.
(setq org-superstar-headline-bullets-list
      '("" "" "" ""))
;; Set up a different marker for graphic display.
(setq org-superstar-first-inlinetask-bullet ?🞸)
;; Stop cycling bullets to emphasize hierarchy of headlines.
(setq org-superstar-cycle-headline-bullets nil)
;; A simple period works fine, too.
(setq org-superstar-leading-fallback ?.)
(setq org-ellipsis "")


;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type nil)

Org Latex Config

;; LATEX CONFIG

;; Place to put the latex class files, e.g.
(setenv "TEXINPUTS"
        (concat "~/Dropbox/org/latexclasses//:"
                (getenv "TEXINPUTS")))

(with-eval-after-load 'ox-latex
(add-to-list 'org-latex-classes
        '("ieee"
                "\\documentclass{IEEEtran}"
                ("\\section{%s}" . "\\section*{%s}")
                ("\\subsection{%s}" . "\\subsection*{%s}")
                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                ("\\paragraph{%s}" . "\\paragraph*{%s}")
                ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(add-to-list 'org-latex-classes
        '("thesis"
               "\\documentclass{mitthesis}"
                ("\\section{%s}" . "\\section*{%s}")
                ("\\subsection{%s}" . "\\subsection*{%s}")
                ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                ("\\paragraph{%s}" . "\\paragraph*{%s}")
                ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(add-to-list 'org-latex-classes
             '("epj-svjour"
               "\\documentclass[epj]{svjour}"
               ("\\section{%s}" . "\\section*{%s}")
               ("\\subsection{%s}" . "\\subsection*{%s}")
               ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
               ("\\paragraph{%s}" . "\\paragraph*{%s}")
               ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(add-to-list 'org-latex-classes
             '("maxtn"
               "\\documentclass{max_tn}"
               ("\\section{%s}" . "\\section*{%s}")
               ("\\subsection{%s}" . "\\subsection*{%s}")
               ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
               ("\\paragraph{%s}" . "\\paragraph*{%s}")
               ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
)

Org Config

;; Here are some additional functions/macros that could help you configure Doom:
;;
;; - `load!' for loading external *.el files relative to this one
;; - `use-package!' for configuring packages
;; - `after!' for running code after a package has loaded
;; - `add-load-path!' for adding directories to the `load-path', relative to
;;   this file. Emacs searches the `load-path' when you load packages with
;;   `require' or `use-package'.
;; - `map!' for binding new keys
;;
;; To get information about any of these functions/macros, move the cursor over
;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k').
;; This will open documentation for it, including demos of how they are used.
;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented.
;; (load! "~/.hammerspoon/Spoons/editWithEmacs.spoon/hammerspoon.el")
(add-hook! 'org-mode-hook '+org-pretty-mode)

(setq captain-predicate 1 )
(after! org
  (setq org-directory "/Users/maxwellmorris/Dropbox/org"))
(use-package lsp-grammarly
  :ensure t
  :hook (org-mode . (lambda ()
                       (require 'lsp-grammarly)
                       (lsp))))  ; or lsp-deferred


(add-to-list 'load-path "~/.emacs.d/.local/straight/repos/org-mode/contrib/lisp/")
(eval-after-load 'ox '(require 'ox-koma-letter))

(setq! mm/Bibliographies '("~/Dropbox/org/references/cira_references.bib"))
(setq! citar-bibliography mm/Bibliographies)

(setq org-cite-csl-styles-dir "~/Dropbox/org/styles/")

(setq! org-download-image-dir '("."))

(use-package all-the-icons
  :ensure t)

(after! citar
(setq! citar-templates
      '((main . "${author editor:30}     ${date year issued:4}     ${title:48}")
        (suffix . "          ${=key= id:15}    ${=type=:12}    ${tags keywords:*}")
        (preview . "${author editor} (${year issued date}) ${title}, ${journal journaltitle publisher container-title collection-title}.\n")
        (note . "Notes on ${author editor}, ${title}")))
(setq citar-symbols
      `((file ,(all-the-icons-faicon "file-o" :face 'all-the-icons-green :v-adjust -0.1) . " ")
        (note ,(all-the-icons-material "speaker_notes" :face 'all-the-icons-blue :v-adjust -0.3) . " ")
        (link ,(all-the-icons-octicon "link" :face 'all-the-icons-orange :v-adjust 0.01) . " ")))
(setq citar-symbol-separator "  "))

(after! org
     (setq org-latex-pdf-process
       (let
           ((cmd (concat "lualatex -shell-escape -interaction nonstopmode"
                 " --synctex=1"
                 " -output-directory %o %f")))
         (list cmd
           "cd %o; if test -r %b.idx; then makeindex %b.idx; fi"
           "cd %o; bibtex %b"
           cmd
           cmd)))
)

(setq org-latex-listings 'minted
      org-latex-packages-alist '(("" "minted"))
      org-latex-pdf-process
      '("lualatex -shell-escape -interaction nonstopmode -output-directory %o %f"
        "lualatex -shell-escape -interaction nonstopmode -output-directory %o %f"))

(setq org-journal-date-prefix "#+TITLE: "
      org-journal-time-prefix "* "
      org-journal-date-format "%a, %d %m %Y"
      org-journal-file-format "%Y-%m-%d.org")
(setq org-babel-python-command "/Users/maxwellmorris/anaconda3/bin/python3")

;; (setq org-ditaa-jar-path "/opt/homebrew/bin/ditaa")
(org-babel-do-load-languages
 'org-babel-load-languages
 '((ditaa . t))) ; this line activates ditaa


(after! org
  (setq org-ditaa-jar-path "")
  (setq org-babel-ditaa-java-cmd "ditaa")
  (setq org-ditaa-jar-option "")
  (defun my-org-ditaa-copy-and-run (orig-fun &rest args)
    (let* ((cmd (car args))
           (temp-dir "/tmp/org-ditaa/")
           (in-file (nth 1 (split-string cmd " ")))
           (out-file (nth 2 (split-string cmd " "))))
      (make-directory temp-dir :parents)
      (copy-file in-file (concat temp-dir "input.ditaa") t)
      (setf (car args) (format "ditaa %s %s" (concat temp-dir "input.ditaa") out-file))
      (apply orig-fun args)))
  (advice-add 'org-babel-execute:ditaa :around #'my-org-ditaa-copy-and-run))

(setq org-plantuml-jar-path "/opt/homebrew/bin/plantuml")
(use-package! cmake-ide
  :commands (cmake-ide-setup)
  :init
  (add-hook 'c++-mode-hook (lambda () (cmake-ide-setup))))

(setq flycheck-c/c++-clang-executable "/usr/bin/clang")
(after! flycheck
  (add-to-list 'flycheck-clang-include-path "/opt/local/include/"))

(after! persp-mode
  ;; Auto-save current session before quitting
  (add-hook 'kill-emacs-hook #'persp-state-save)

  ;; Load last session on startup
  (add-hook 'after-init-hook #'persp-state-load))

(when (fboundp 'persp-state-save)
 (desktop-save-mode 1))

(setenv "PATH" (concat "/opt/homebrew/bin:" (getenv "PATH")))
(setq exec-path (append exec-path '("/opt/homebrew/bin")))
(setq ccls-executable "/opt/homebrew/bin/ccls")  ; usually "/usr/local/bin/ccls" or "/opt/homebrew/bin/ccls"

(after! ccls
  (setq ccls-initialization-options '(:index (:comments 2) :completion (:detailedLabel t)))
  (set-lsp-priority! 'ccls 2)) ; optional as ccls is the default in Doom

(with-eval-after-load 'eglot
    (setenv "PATH" (concat (getenv "PATH") ":/home/maxwell/.npm-global/bin"))
    (setq exec-path (append exec-path '("/home/maxwell/.npm-global/bin")))
    (add-to-list 'eglot-server-programs '(python-mode . ("pyright-langserver" "--stdio")))
    (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
    )
(defun my/remote-eglot-hook ()
  "Configure eglot for remote Python development."
  (when (file-remote-p default-directory)
    (add-to-list 'eglot-server-programs
                 `(python-mode . ("/snap/pyright/684/bin/pyright")))))

(add-hook 'eglot--managed-mode-hook #'my/remote-eglot-hook)
(add-hook 'python-mode-hook 'anaconda-mode)
(add-hook 'python-mode-hook 'anaconda-eldoc-mode)
(eval-after-load "company"
  '(add-to-list 'company-backends 'company-anaconda))

(defun my-set-python-interpreter ()
  "Set the Python interpreter based on the location of the file."
  (if (file-remote-p default-directory)
      (setq-local python-shell-interpreter "/ssh:[email protected]:/usr/bin/python")
    (setq-local python-shell-interpreter "python3"))) ; or whatever your local interpreter is

(add-hook 'python-mode-hook #'my-set-python-interpreter)

(setq lsp-enable-indentation nil)

(after! tex
  (setq TeX-engine 'luatex))
(setq undo-tree-visualizer-timestamps t)
(setq undo-tree-visualizer-relative-timestamps t)
(setq undo-in-region t)
;; (after! calc
;;   (map! :map calc-mode-map
;;         "C-o" #'casual-main-menu))
(setq org-element-use-cache nil)
(setq delete-by-moving-to-trash t)


;; Yas snippet templates from latex doc templates
;; (setq yas-snippet-dirs (append yas-snippet-dirs
;;                                '("~/dropbox/org/latexclasses")))


(after! org
  (org-link-set-parameters
   "sec"
   :follow (lambda (path)
             (org-id-goto path))
   :export (lambda (path desc backend)
             (cond
              ((eq backend 'html) (format "<a href=\"#%s\">%s</a>" path (or desc path)))
              ((eq backend 'latex) (format "\\ref{%s}" path))))))


;; (use-package! evil-owl
;;         :config
;;         (setq evil-owl-max-string-length 500)
;;         (add-to-list 'display-buffer-alist
;;                 '("*evil-owl*"
;;                         (display-buffer-in-side-window)
;;                         (side . bottom)
;;                         (window-height . 0.3)))
;;                         (evil-owl-mode))


(use-package evil-owl
  :config
  (setq evil-owl-display-method 'posframe
        evil-owl-extra-posframe-args '(:width 50 :height 20)
        evil-owl-max-string-length 50)
  (evil-owl-mode))



;; (setq matlab-confirm-functionname-match nil)

Custom Personel Emacs Functions

(defun mm/PushWebsite()
  "This function runs the functions required to update my site.
   Exports the file to HTML.
   Then starts a magit commit"
  (interactive)
  (org-html-export-to-html)
  (magit)
)

(defun mm/org-save-and-export-koma-letter-pdf ()
  (if (eq major-mode 'org-mode)
    (org-koma-letter-export-to-pdf)))



;; # Function to create a new file from personel org templates
(defvar my-template-directory "~/dropbox/org/doctemplates/"
  "Directory where your template files are stored.")

(defun mjm-insert-template (new-file-name)
  "Prompt the user to select a template file and insert its contents into a new file.
Argument NEW-FILE-NAME is the name of the new file to create."
  (interactive "FCreate new file from template: ")
  (let* ((templates (directory-files my-template-directory nil "\\.org$"))
         (template (completing-read "Select template: " templates nil t)))
    (if (and template (not (string= template "")))
        (let ((template-file (concat (file-name-as-directory my-template-directory) template)))
          (copy-file template-file new-file-name)
          (find-file new-file-name)
          (message "New file created from template: %s" new-file-name))
      (message "No template selected or template file does not exist"))))



;; # Helps with referencing appendicies in org mode docs
(with-eval-after-load 'ox
  (defun my/org-latex-nameautoref-filter (text backend info)
    "Replace \\ref commands with \\nameautorefB in LaTeX export for sections only."
    (when (org-export-derived-backend-p backend 'latex)
      (let ((section-labels '("sec:" "chap:" "Appendix:"))) ; Add your section prefixes here
        (dolist (prefix section-labels)
          (setq text (replace-regexp-in-string
                      (format "\\\\ref{%s\\([a-zA-Z0-9:-]+\\)}" prefix)
                      (format "\\\\nameautorefB{%s\\1}" prefix)
                      text))))
      text))

  (add-to-list 'org-export-filter-link-functions
               'my/org-latex-nameautoref-filter))


;; (defun deft-daily-note ()
;;   "Create or open a unique daily note for today, using a template file if the note is new."
;;   (interactive)
;;   (let* ((template-file "~/Dropbox/org/doctemplates/daily-template.org") ; Adjust the path as necessary
;;          (daily-file (expand-file-name (format-time-string "%Y-%m-%d.org") deft-directory)))
;;     (if (file-exists-p daily-file)
;;         (find-file daily-file) ; Open the existing file
;;       (progn
;;         (copy-file template-file daily-file) ; Copy template to new file
;;         (find-file daily-file) ; Open the new file
;;         (message "New daily note created from template.")))))

(after! deft

;; Correct the prefix definition for Deft-related commands
;; Define 'n d' as a prefix and then bind specific commands under it
;; Adjust your Doom Emacs configuration to properly define 'n d' as a prefix
(map! :leader
      (:prefix ("n" . "Notes")
       (:prefix-map ("d" . "Deft")
        :desc "Open Deft" "o" #'deft
        :desc "New Deft Daily" "d" #'deft-daily-note)))

(setq deft-directory "~/Dropbox/org/journal"
        deft-default-extension "org"
        deft-recursive t)

(defun deft-daily-note ()
  "Create or open a unique daily note for today, using a template file if the note is new. Also, ensure LSP is activated."
  (interactive)
  (let* ((template-file "~/Dropbox/org/doctemplates/daily-template.org") ; Adjust the path as necessary
         (daily-file (expand-file-name (format-time-string "%Y-%m-%d.org") deft-directory)))
    (if (file-exists-p daily-file)
        (find-file daily-file) ; Open the existing file
      (progn
        (copy-file template-file daily-file) ; Copy template to new file
        (find-file daily-file) ; Open the new file
        (message "New daily note created from template.")))
    )) ; Start LSP, replace `lsp-deferred` with `lsp` if you want immediate activation


                )






(defvar my/nano-agenda-frame nil
  "Frame containing the nano agenda")

(defun my/nano-agenda-toggle ()
  "Show an agenda in a dedicated frame"

  (interactive)
  (if (not (and my/nano-agenda-frame (frame-live-p my/nano-agenda-frame)))
      (progn
        (setq my/nano-agenda-frame (make-frame '((width . 80)
                                                 (height . 20))))
        (select-frame-set-input-focus my/nano-agenda-frame)
        (modify-frame-parameters my/nano-agenda-frame
                                 '((user-position . t)
                                   (top . 50)
                                   (left . (- 10))))
        (select-frame-set-input-focus my/nano-agenda-frame)
        (nano-agenda))
    (if (frame-visible-p my/nano-agenda-frame)
        (let ((frames (frame-list)))
          (make-frame-invisible my/nano-agenda-frame)
          (catch 'visible-frame
            (dolist (frame frames)
              (when (frame-visible-p frame)
                (select-frame-set-input-focus frame)
                (throw 'visible-frame nil)))))
      (make-frame-visible my/nano-agenda-frame))
    (nano-agenda-update)))

(use-package! org
  :config
  (setq org-agenda-files (directory-files-recursively "~/Dropbox/org/agenda/" "\\.org$"))
  (setq org-capture-templates
        '(("t" "Todo with Deadline" entry (file+headline "~/Dropbox/org/agenda/new-todo.org" "Tasks")
           "* TODO %?\n  DEADLINE: %^t\n  %i\n  %a"))))