From ce13adc1d33d4b61d3a765916da5bfb3378d35b2 Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Mon, 9 Mar 2026 09:27:31 +0100 Subject: [PATCH] Update Doom Emacs config, snippets and babel library --- doom.org | 766 +++++++++++++++++++++++++++------------- emacs-library-babel.org | 10 + emacs-snippets.org | 14 +- 3 files changed, 533 insertions(+), 257 deletions(-) diff --git a/doom.org b/doom.org index 5add66a..d9b67d0 100644 --- a/doom.org +++ b/doom.org @@ -1,4 +1,4 @@ -#+title: Doom Emacs Configuration +#+TITLE: Doom Emacs Configuration :DRAWER: #+startup: overview @@ -28,8 +28,6 @@ Documentation: When changing =init.el= or =package.el=, tangle the files and then run =doom sync=. After that, restart Emacs with =spc q r=. -* Dependencies / Installation - * Useful Bindings - =align-regexp=: equivalent of [[https://github.com/junegunn/vim-easy-align][vim-easy-align]]. Very useful to align tables and stuff @@ -120,7 +118,8 @@ Fonts Theme #+begin_src emacs-lisp -(setq doom-theme 'leuven) +;; (setq doom-theme 'leuven) +(setq doom-theme 'doom-gruvbox-light) #+end_src Line numbers @@ -157,7 +156,9 @@ Mode Line #+begin_src emacs-lisp (after! evil (map! :m "-" #'dired-jump) - (setq evil-respect-visual-line-mode nil)) + (setq evil-respect-visual-line-mode nil) + (modify-syntax-entry ?_ "w") ;; https://emacs.stackexchange.com/questions/9583/how-to-treat-underscore-as-part-of-the-word + ) #+end_src Make horizontal movement cross lines @@ -201,7 +202,7 @@ Turn off auto-fill mode that add line breaks. (setq ispell-program-name "aspell") #+end_src -Correct last work using =C-l=. +Correct last work using =C-.=. #+begin_src emacs-lisp (defun tdh-correct-last-word () (interactive) @@ -211,7 +212,23 @@ Correct last work using =C-l=. ) ) -(define-key evil-insert-state-map (kbd "C-l") 'tdh-correct-last-word) +(map! :map org-mode-map + :i "C-." #'tdh-correct-last-word) +#+end_src + +Go to previous/next spell mistake using =g[= and =g]=: +#+begin_src emacs-lisp +(map! :map evil-normal-state-map + "g]" #'spell-fu-goto-next-error) +(map! :map evil-normal-state-map + "g[" #'spell-fu-goto-previous-error) +#+end_src + +** C-cedilla issue +This tells GTK builds of Emacs to use native input method handling +#+begin_src emacs-lisp +(setq x-gtk-use-system-tooltips nil) +(setq x-gtk-use-native-input t) #+end_src ** Lockfiles @@ -244,18 +261,18 @@ This helps to speed-up emacs. #+begin_src emacs-lisp (setenv "GIT_ASKPASS" "git-gui--askpass") -(after! magit - (setq magit-diff-refine-hunk 'all) - (setq magit-repolist-columns '(("Name" 25 magit-repolist-column-ident nil) - ("Status" 7 magit-repolist-column-flag) - ("BU" 3 magit-repolist-column-unpushed-to-upstream - ((:right-align t) - (:help-echo "Local changes not in upstream"))) - ("Path" 99 magit-repolist-column-path nil))) - ) +;; (after! magit +;; (setq magit-diff-refine-hunk 'all) +;; (setq magit-repolist-columns '(("Name" 25 magit-repolist-column-ident nil) +;; ("Status" 7 magit-repolist-column-flag) +;; ("BU" 3 magit-repolist-column-unpushed-to-upstream +;; ((:right-align t) +;; (:help-echo "Local changes not in upstream"))) +;; ("Path" 99 magit-repolist-column-path nil))) +;; ) #+end_src ** Dired @@ -290,13 +307,6 @@ This works also with =C-x C-q= #+end_src ** PDF-Tools -#+begin_src emacs-lisp -(use-package! pdf-tools - :config - (add-hook 'pdf-view-mode-hook (lambda() (linum-mode -1))) - ) -#+end_src - Function that opens current pdf page as an SVG file with Inkscape. #+begin_src emacs-lisp (defun tdh-screenshot-page () @@ -336,6 +346,13 @@ Disable flycheck for now with orgmode buffers: ) #+end_src +** Helm AG +Increase the number of "columns" when search for text: +#+begin_src emacs-lisp +(setq counsel-rg-base-command + "rg --max-columns 1000 --with-filename --no-heading --line-number --color never %s") +#+end_src + ** Others #+begin_src emacs-lisp (setq auto-save-default t) @@ -387,8 +404,8 @@ TAB was changed to toggle only the visibility state of the current subtree, rath https://github.com/doomemacs/doomemacs/issues/6478#issuecomment-1406167570 #+begin_src emacs-lisp (after! evil - (setq org-fold-core-style 'text-properties) - (evil-select-search-module 'evil-search-module 'isearch) + (setq org-fold-core-style 'overlays) + (evil-select-search-module 'evil-search-module 'evil-search) ) #+end_src @@ -558,28 +575,59 @@ Org Agenda Custom Views (defun tdh-org-agenda-skip-scheduled () (org-agenda-skip-entry-if 'scheduled 'deadline 'regexp "\n]+>")) + (defun tdh-org-agenda-phd-files () + (seq-mapcat + (lambda (subdir) + (directory-files subdir t "\\.org$" t)) + (seq-filter #'file-directory-p + (directory-files "~/Cloud/work-projects/ID31-NASS/phd-thesis-chapters" t "^[^.]" t)))) + (setq org-agenda-custom-commands '(("T" "test" ((org-ql-block '(planning) ((org-ql-block-header "To refill"))) )) - ("w" "Work" - ((org-ql-block '(and (tags "inbox")) - ((org-ql-block-header "To refill"))) - (org-ql-block '(and (scheduled) - (not (done))) - ((org-ql-block-header "Scheduled Tasks"))) + ("p" "PhD Thesis" + ((agenda "" ((org-agenda-span 3) + (org-deadline-warning-days 0) + (org-agenda-block-separator nil) + (org-agenda-format-date "%A %-e %B %Y") + (org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done)) + (org-agenda-overriding-header "Next:"))) (org-ql-block '(and (not (tags "@home")) (not (tags "@biblio")) (todo "TODO") (priority "A")) - ((org-ql-block-header "Important Tasks"))) + ((org-ql-block-header "Important:"))) (org-ql-block '(and (not (tags "@home")) (todo "DELE")) - ((org-ql-block-header "Delegated Tasks"))) + ((org-ql-block-header "Delegated:"))) (org-ql-block '(and (not (tags "@home")) (todo "WAIT")) - ((org-ql-block-header "Tasks on hold"))) + ((org-ql-block-header "On hold:"))) + ) + ((org-agenda-files (tdh-org-agenda-phd-files)))) + + ("w" "Work" + ((agenda "" ((org-agenda-span 3) + (org-deadline-warning-days 0) + (org-agenda-block-separator nil) + (org-agenda-format-date "%A %-e %B %Y") + (org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done)) + (org-agenda-overriding-header "Next:"))) + (org-ql-block '(and (not (tags "@home")) + (not (tags "@biblio")) + (todo "TODO") + (priority "A")) + ((org-ql-block-header "Important:"))) + (org-ql-block '(and (not (tags "@home")) + (todo "DELE")) + ((org-ql-block-header "Delegated:"))) + (org-ql-block '(and (not (tags "@home")) + (todo "WAIT")) + ((org-ql-block-header "On hold:"))) + (org-ql-block '(and (tags "inbox")) + ((org-ql-block-header "To refill:"))) )) ("h" "Home" ((org-ql-block '(and (tags "@home") @@ -644,13 +692,6 @@ Org Agenda Custom Views ) #+end_src -** Org Fancy Priority -#+begin_src emacs-lisp -(use-package! org-fancy-priorities ; priority icons - :hook (org-mode . org-fancy-priorities-mode) - :config (setq org-fancy-priorities-list '("■" "■" "■"))) -#+end_src - ** Org Structure Template #+begin_src emacs-lisp (after! org @@ -843,22 +884,21 @@ Do not export headline with the =:ignore:= tag: (after! org (setq org-html-mathjax-template " - ") + MathJax = { + svg: { + scale: 1, + fontCache: \"global\" + }, + tex: { + tags: \"ams\", + multlineWidth: \"85%\", + tagSide: \"right\", + tagIndent: \".8em\", + macros: {bm: [\"\\\\boldsymbol{#1}\",1]} + } + }; + + ") (setq org-html-mathjax-options '((path "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js" ) @@ -948,26 +988,28 @@ Do not export headline with the =:ignore:= tag: :latex-compiler ("pdflatex -output-format dvi -interaction nonstopmode -output-directory %o %f") :image-converter ("dvipng -D %D -T tight -o %O %f")) (dvisvgm - :programs ("xetex" "dvisvgm") - :description "xdv > svg" + :programs ("latex" "dvisvgm") + :description "xdi > svg" :message "you need to install the programs: xetex and dvisvgm." - :image-input-type "xdv" + :image-input-type "dvi" :image-output-type "svg" :image-size-adjust (0.6 . 0.6) - :latex-compiler ("xelatex -no-pdf -output-directory %o %f") - :image-converter ("dvisvgm %f -n -b min -c %S -o %O")) + :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f") + :image-converter ("dvisvgm %f --no-fonts --exact-bbox --scale=%S --output=%O")) )) ;; Use imagemagick/dvisvgm to generate png from pdf - (setq org-preview-latex-default-process 'pdf2svg) + (setq org-preview-latex-default-process 'dvisvgm) ;; Don't change the font size for subscripts and superscripts in latex fragments. ;; This cause the orgmode tables not to be well aligned. (setq font-latex-fontify-script nil) ;; Colors of latex fragments - (setq org-format-latex-options (plist-put org-format-latex-options :foreground 'default)) - (setq org-format-latex-options (plist-put org-format-latex-options :background 'default)) + (plist-put org-format-latex-options :foreground nil) + (plist-put org-format-latex-options :background nil) + ;; (setq org-format-latex-options (plist-put org-format-latex-options :foreground 'default)) + ;; (setq org-format-latex-options (plist-put org-format-latex-options :background 'default)) ) #+end_src @@ -1167,10 +1209,23 @@ https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-he (setq org-latex-pdf-process '("latexmk -cd -pdflatex=\"pdflatex -synctex=1 -shell-escape -interaction nonstopmode -output-directory %o\" -pdf -f %f")) - ;; Better display of timestamps - (setq org-latex-diary-timestamp-format "\\footnotesize{\\textit{%s}}" - org-latex-inactive-timestamp-format "\\footnotesize{\\textit{%s}}" - org-latex-active-timestamp-format "\\footnotesize{\\textit{%s}}") + ;; ;; Better display of timestamps + ;; (setq org-latex-diary-timestamp-format "\\footnotesize{\\textit{%s}}" + ;; org-latex-inactive-timestamp-format "\\footnotesize{\\textit{%s}}" + ;; org-latex-active-timestamp-format "\\footnotesize{\\textit{%s}}") + + (defun org-export-filter-timestamp-remove-brackets (timestamp backend info) + "removes relevant brackets from a timestamp" + (cond + ((org-export-derived-backend-p backend 'latex) + (replace-regexp-in-string "[<>]\\|[][]" "" timestamp)) + ((org-export-derived-backend-p backend 'html) + (replace-regexp-in-string "&[lg]t;\\|[][]" "" timestamp)))) + + (eval-after-load 'ox '(add-to-list + 'org-export-filter-timestamp-functions + 'org-export-filter-timestamp-remove-brackets)) + ) #+end_src @@ -1193,7 +1248,7 @@ Bold Text Special Environments - [ ] Make some comment those special environments #+begin_src emacs-lisp -(after! org +(after! org-beamer (add-to-list 'org-beamer-environments-extra '("cbox" ;; Name of environment "m" ;; Selection key @@ -1298,6 +1353,15 @@ https://www.reddit.com/r/orgmode/comments/7u2n0h/tip_for_defining_latex_macros_f ) #+end_src +** Org mode and Yasnippet +=TAB= used not to work well with Yasnippet ([[https://github.com/doomemacs/doomemacs/issues/7733#issuecomment-2586904927][github issue]]), with the following, it works well: +#+begin_src emacs-lisp +(map! :map org-mode-map :after yasnippet ;; Retain org-mode's native TAB functionality but allow yas-expand when a snippet is available + :nvi [tab] yas-maybe-expand ;; Optionally, bind other keys for snippet navigation + :nvi "C-c n" #'yas-next-field + :nvi "C-c p" #'yas-prev-field) +#+end_src + ** Some function #+begin_src emacs-lisp (defun org-syntax-convert-case-to-lower () @@ -1371,6 +1435,71 @@ https://www.reddit.com/r/emacs/comments/d3a8or/pretty_org_tables_in_the_buffer_c ) #+end_src +** Disable LaTeX fragments in table +#+begin_src emacs-lisp +(after! org + ;; Toggle + (defvar td/org-disable-latex-in-tables t + "If non-nil, disable LaTeX preview inside Org tables.") + + (defun td/toggle-latex-in-tables () + (interactive) + (setq td/org-disable-latex-in-tables + (not td/org-disable-latex-in-tables)) + (message "Disable LaTeX preview in tables: %s" + td/org-disable-latex-in-tables)) + + (defun td/point-in-table-p (pos) + "Check if position POS is inside an Org table." + (save-excursion + (goto-char pos) + (org-at-table-p))) + + (defadvice! td/org-format-latex-ignore-tables (orig-fn &rest args) + "Disable LaTeX preview inside Org tables." + :around #'org-format-latex + (let ((beg (nth 0 args)) + (end (nth 1 args))) + ;; If toggle is OFF → run normally + (if (not td/org-disable-latex-in-tables) + (apply orig-fn args) + ;; If this is NOT a user-initiated call (no buffer positions) + ;; we need to check if we're currently inside a table + (if (not (and (number-or-marker-p beg) + (number-or-marker-p end))) + ;; Internal call: check if point is in a table + (if (td/point-in-table-p (point)) + nil ; Skip if in table + (apply orig-fn args)) ; Process if not in table + ;; User-initiated preview with buffer region + ;; Temporarily narrow to exclude table lines, then process + (save-restriction + (narrow-to-region beg end) + (goto-char (point-min)) + ;; Process each non-table section separately + (let ((start (point-min))) + (while (not (eobp)) + (if (org-at-table-p) + ;; Skip the entire table + (progn + ;; Process region before table + (when (< start (point)) + (apply orig-fn (list start (point)) (cddr args))) + ;; Move past table + (org-table-end) + (setq start (point))) + ;; Move to next line + (forward-line 1))) + ;; Process any remaining region after last table + (when (< start (point-max)) + (apply orig-fn (list start (point-max)) (cddr args)))))))))) + +;; Optional keybinding +(map! :leader + :desc "Toggle LaTeX preview inside Org tables" + "t t" #'td/toggle-latex-in-tables) +#+end_src + ** Org CalDAV #+begin_src emacs-lisp (use-package! org-caldav @@ -1426,34 +1555,88 @@ https://www.reddit.com/r/emacs/comments/d3a8or/pretty_org_tables_in_the_buffer_c *** =message:= link to mutt #+begin_src emacs-lisp -;; (require 'org-protocol) +;; Customizable variables +(defcustom tdh/org-mutt-terminal "kitty" + "The terminal emulator to use for opening Mutt/Neomutt." + :group 'org-link + :type 'string) -(defun stefanv/mutt-open-message (message-id) - "In neomutt, open the email with the the given Message-ID" - (let* - ((message-id (replace-regexp-in-string "^/*" "" message-id)) - (mail-file - (replace-regexp-in-string - "\n$" "" (shell-command-to-string - (format "mu find -f l i:%s | head -n 1" message-id)))) - (mail-dir (replace-regexp-in-string "/\\(cur\\|new\\|tmp\\)/$" "" - (file-name-directory mail-file))) - (process-id (concat "neomutt-" message-id)) - (message-id-escaped (regexp-quote message-id)) - (mutt-keystrokes - (format "L~i %s\n\nLall\n\nl" (shell-quote-argument message-id-escaped))) - (mutt-command (list "neomutt" "-R" "-f" mail-dir - "-e" (format "push '%s'" mutt-keystrokes)))) +(defcustom tdh/org-mutt-executable "neomutt" + "The Mutt/Neomutt executable name." + :group 'org-link + :type 'string) - (message "Launching neomutt for message %s" message-id) - (call-process "setsid" nil nil - "-f" "alacritty" "-e" - "neomutt" "-R" "-f" mail-dir - "-e" (format "push '%s'" mutt-keystrokes)))) +(defcustom tdh/org-mutt-mu-utility "mu" + "The 'mu' mail indexer executable name." + :group 'org-link + :type 'string) -; Whenever org-mode sees a link starting with `message://`, it -; calls our `mutt-open-message` function -(org-add-link-type "message" 'stefanv/mutt-open-message) +(defun tdh/org-open-mutt-message (message-id) + "Open the email with the given Message-ID in Mutt/Neomutt using 'mu'. + +This function is intended to be called by Org mode for 'message://' links. +It uses `mu find` to locate the email file, determines the Maildir folder, +and launches Mutt/Neomutt in a terminal specified by `tdh/org-mutt-terminal`, +instructing it to limit view to the specific message. + +The Message-ID should be passed without the 'message://' prefix and +without surrounding '<>' characters." + (interactive "sMessage-ID: ") ; For testing interactively + (let* ( + ;; 1. Sanitize Message-ID (remove potential whitespace or <>) + (msg-id (replace-regexp-in-string "[<>[:space:]\n]" "" message-id)) + ;; 2. Construct the 'mu find' command safely + (mu-find-command (format "%s find --nocolor -f l i:%s | head -n 1" + (shell-quote-argument tdh/org-mutt-mu-utility) + (shell-quote-argument msg-id))) ; Quote msg-id for shell + ;; 3. Execute 'mu find' and get the mail file path + (mail-file-raw (shell-command-to-string mu-find-command)) + ;; Trim leading/trailing whitespace and newlines from the result + (mail-file (replace-regexp-in-string "\\`[[:space:]]*\\|[[:space:]]*\\'" "" mail-file-raw))) + + ;; 4. Check if 'mu find' returned a valid path + (if (or (string-empty-p mail-file) (not (file-exists-p mail-file))) + (error "Could not find mail file for Message-ID '%s'. Command: %s. Result: '%s'" + msg-id mu-find-command mail-file-raw) + + ;; 5. Derive the Maildir *folder* from the file path + (let* ( + ;; This regex assumes standard Maildir structure like /path/to/Maildir/cur/filename + ;; It removes the "/cur/filename", "/new/filename", or "/tmp/filename" part. + ;; Adjust if your Maildir structure or mu's output format differs. + (mail-dir (replace-regexp-in-string "/\\(cur\\|new\\|tmp\\)/[^/]*$" "/" mail-file)) + ;; Alternative (simpler, maybe less robust): just get parent dir of the file + ;; (mail-dir (directory-file-name (file-name-directory mail-file))) + + ;; 6. Define the keystrokes to send to Mutt/Neomutt + ;; L: Limit command + ;; ~i : Search Message-ID header + ;; \n: Execute limit + ;; \n: Press Enter again (should open the first/only message in the limited view) + (mutt-keystrokes (format "L~i %s\n\n" msg-id)) ; Limit, Enter, Enter to open + + ;; 7. Prepare arguments for the terminal and Mutt/Neomutt + (mutt-base-args (list "-R" ; Start read-only (safer, remove if you want write access) + "-f" mail-dir + "-e" (format "push '%s'" mutt-keystrokes))) + ;; Command list for the terminal emulator + (process-args (append (list "-e" tdh/org-mutt-executable) mutt-base-args)) + (process-name (concat tdh/org-mutt-executable "-" msg-id))) ; Unique process name for Emacs + + + (message "Launching %s for message %s (Maildir: %s)" tdh/org-mutt-executable msg-id mail-dir) + + ;; 8. Launch the process asynchronously using start-process (doesn't block Emacs) + (apply 'start-process process-name nil tdh/org-mutt-terminal process-args) + + ;; --- Alternative: Using call-process + setsid (might block Emacs briefly) --- + ;; This combines the arguments differently because setsid takes the command first + ;; (let ((full-command (append (list tdh/org-mutt-executable) mutt-base-args))) + ;; (apply 'call-process "setsid" nil nil "-f" tdh/org-mutt-terminal "-e" full-command)) + )))) + +;; Register the link type handler with Org mode +(org-add-link-type "message" 'tdh/org-open-mutt-message t) ; Added 't' to force update if already defined #+end_src ** Org Wild Notifier @@ -1552,7 +1735,7 @@ Insert Image that is in the =figs= folder using SXIV "Insert an org image link, choosing the file with completion and starting from `my-default-image-directory'." (interactive) - (setq img (shell-command-to-string "ls figs/*.{jpg,jpeg,bmp,png,gif} 2> /dev/null | sxiv -i -t -o | tail -1 | tr -d '\n'")) + (setq img (shell-command-to-string "ls figs/*.{jpg,jpeg,bmp,png,gif} 2> /dev/null | nsxiv -i -t -o | tail -1 | tr -d '\n'")) (unless (equal "" img) (insert (format "[[file:%s]]" img))) ) @@ -1571,9 +1754,9 @@ Copy picture from phone folder using SXIV and insert it Bash script for copying pictures taken by phone. #+begin_src bash :comments both :mkdirp yes :shebang "#!/usr/bin/env bash" :tangle ~/.config/doom/bin/copy-phone-picture.sh if [ -z "$1" ]; then - oldpath=$(ls -t ~/Cloud/photos/phone/*.jpg | sxiv -i -t -o | tail -1); + oldpath=$(ls -t ~/Cloud/photos/phone/*.jpg | nsxiv -i -t -o | tail -1); else - oldpath=$(ls -t $1 | sxiv -i -t -o | tail -1); + oldpath=$(ls -t $1 | nsxiv -i -t -o | tail -1); fi if [ -n "$oldpath" ]; then @@ -1667,7 +1850,7 @@ Map Keys "Watch LaTeX file using latexmk" (interactive) (start-process-shell-command "latexmk-watch" "*latexmk-watch-output*" - "latexmk" "-pvc")) + "latexmk -bibtex -pvc")) #+end_src #+begin_src emacs-lisp @@ -1736,18 +1919,18 @@ Map Keys :n "r" 'helm-resume))) #+end_src -*** Open ranger in current directory =,o= +*** Open yazi in current directory =,o= #+begin_src emacs-lisp -(defun tdh-open-ranger-in-workdir () +(defun tdh-open-yazi-in-workdir () (interactive) (call-process-shell-command - (concat "alacritty -e ranger " default-directory) nil 0)) + (concat "kitty -e yazi " default-directory) nil 0)) #+end_src #+begin_src emacs-lisp (after! org (map! :map org-mode-map - :n ",o" 'tdh-open-ranger-in-workdir)) + :n ",o" 'tdh-open-yazi-in-workdir)) #+end_src *** View in External programs =,v= @@ -1855,6 +2038,12 @@ Default options for Matlab code Better format the output results for Matlab ([[https://www.reddit.com/r/emacs/comments/fy98bs/orgbabels_matlab_session_output_is_malformed/?utm_source=share&utm_medium=web2x][link]]). #+begin_src emacs-lisp (after! org + (setq org-babel-octave-wrapper-method + "%s + if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid); + else, save -ascii %s ans + end + ") (defun org-babel-octave-evaluate-session (session body result-type &optional matlabp) "Evaluate BODY in SESSION." @@ -1939,35 +2128,6 @@ Better format the output results for Matlab ([[https://www.reddit.com/r/emacs/co ) #+end_src -** Mermaid -#+begin_src bash :tangle no -paru -S mermaid-cli -#+end_src - -#+begin_src emacs-lisp -(use-package! ob-mermaid - :after org - :config - (setq ob-mermaid-cli-path "mmdc") - ) -#+end_src - -#+begin_src mermaid :file figs/mermaid.png :theme default :background-color transparent :tangle no :exports both -gantt -dateFormat YYYY-MM-DD -title Adding GANTT diagram to mermaid -excludes weekdays 2014-01-10 - -section A section -Completed task :done, des1, 2014-01-06,2014-01-08 -Active task :active, des2, 2014-01-09, 3d -Future task : des3, after des2, 5d -Future task2 : des4, after des3, 5d -#+end_src - -#+RESULTS: -[[file:figs/mermaid.png]] - ** Some functions for using Matlab with Org Babel =,m= =whos= matlab function #+begin_src emacs-lisp @@ -2256,18 +2416,10 @@ Nice Functions: #+begin_src emacs-lisp (use-package! org-ref :after org - :init - (with-eval-after-load 'ox - (defun my/org-ref-process-buffer--html (backend) - "Preprocess `org-ref' citations to HTML format. - Do this only if the export backend is `html' or a derivative of - that." - ;; `ox-hugo' is derived indirectly from `ox-html'. - ;; ox-hugo <- ox-blackfriday <- ox-md <- ox-html - (when (org-export-derived-backend-p backend 'html) - (org-ref-process-buffer 'html))) - (add-to-list 'org-export-before-parsing-hook #'my/org-ref-process-buffer--html)) :config + ;; Ox-Hugo configuration: https://ox-hugo.scripter.co/doc/org-ref-citations/ + (setq org-hugo-link-desc-insert-type t) + ;; Folder where the notes files are located (or file if just one Note file) (setq bibtex-completion-notes-path "~/Cloud/brain/") @@ -2316,11 +2468,22 @@ Nice Functions: ;; t) ;; Let Mathjax deals with equation reference - (defun org-ref-eqref-export (keyword desc format) - (cond - ((eq format 'latex) (format "\\eqref{%s}" keyword)) - ((eq format 'html) (format "\\eqref{%s}" keyword)) - ((eq format 'md) (format "\\eqref{%s}" keyword)))) + ;; TODO - Will use an advice instead + ;; (defun org-ref-eqref-export (keyword desc format) + ;; (cond + ;; ((eq format 'latex) (format "\\eqref{%s}" keyword)) + ;; ((eq format 'html) (format "\\eqref{%s}" keyword)) + ;; ((eq format 'md) (format "\\eqref{%s}" keyword)))) + + ;; Convert eqref:label to \eqref{label} + (defun my/replace-eqref-with-ref (backend) + "Replace eqref:label with \\ref{label} for HTML and Hugo export." + (when (memq backend '(html html5 hugo)) + (goto-char (point-min)) + (while (re-search-forward "eqref:\\([a-zA-Z0-9:-_]+\\)" nil t) + (replace-match "\\\\ref{\\1}")))) + + (add-hook 'org-export-before-processing-hook 'my/replace-eqref-with-ref) ;; Derived from org-ref-extract-bibtex-to-file to force the bibfile to have the same name than to org file, and take references from bibtex-completion-bibliography ;; this function can be added in the org-export-before-parsing-hook for instance @@ -2491,23 +2654,37 @@ bibliography:./biblio/references.bib #+end_src Automatic export of backlinks -#+begin_src emacs-lisp :tangle no -(after! (org org-roam) - (defun tdh-org-roam--backlinks-list (file) - (when (org-roam--org-roam-file-p file) - (mapcar #'car (org-roam-db-query [:select :distinct [from] - :from links - :where (= to $s1) - :and from :not :like $s2] file "%private%")))) - (defun tdh-org-export-preprocessor (_backend) - (when-let ((links (tdh-org-roam--backlinks-list (buffer-file-name)))) - (insert "\nBacklinks:\n") - (dolist (link links) - (insert (format "- [[file:%s][%s]]\n" - (file-relative-name link org-roam-directory) - (org-roam--get-title-or-slug link)))))) +#+begin_src emacs-lisp +(after! (org org-roam org-ref) + ;; (defun tdh-org-roam--backlinks-list (file) + ;; (when (org-roam--org-roam-file-p file) + ;; (mapcar #'car (org-roam-db-query [:select :distinct [from] + ;; :from links + ;; :where (= to $s1) + ;; :and from :not :like $s2] file "%private%")))) - (add-hook 'org-export-before-processing-hook #'tdh-org-export-preprocessor) + ;; (defun tdh-org-export-preprocessor (_backend) + ;; (when-let ((links (tdh-org-roam--backlinks-list (buffer-file-name)))) + ;; (insert "\nBacklinks:\n") + ;; (dolist (link links) + ;; (insert (format "- [[file:%s][%s]]\n" + ;; (file-relative-name link org-roam-directory) + ;; (org-roam--get-title-or-slug link)))))) + + ;; (add-hook 'org-export-before-processing-hook #'tdh-org-export-preprocessor) + ) +#+end_src + +Correctly export references for Hugo blog. +#+begin_src emacs-lisp +(after! (org org-roam org-ref) + ;; Citation processing for org-ref + (defun tdh-org-export-org-ref-preprocessor--html (backend) + "Preprocess `org-ref' citations to HTML format." + (when (org-export-derived-backend-p backend 'html) + (org-ref-process-buffer 'html))) + + (add-hook 'org-export-before-processing-hook #'tdh-org-export-org-ref-preprocessor--html) ) #+end_src @@ -2750,8 +2927,17 @@ Provides nice functions such as: ** Completion in the Matlab Shell #+begin_src emacs-lisp +;; (map! :map matlab-shell-mode-map +;; :i "" 'matlab-shell-c-tab) (map! :map matlab-shell-mode-map - :i "" 'matlab-shell-tab) + :i "" #'matlab-shell-tab) +#+end_src + +#+begin_src emacs-lisp +(defadvice! inhibit-real-only-a (oldfun &rest r) + "Temporary remove read-only lines in shell buffer" + :around#'matlab-shell-collect-command-output + (let ((inhibit-read-only t)) (apply oldfun r))) #+end_src ** Beautify code @@ -2835,106 +3021,164 @@ Provides nice functions such as: * Doom =init.el= #+begin_src emacs-lisp :tangle ~/.config/doom/init.el -(when noninteractive - (after! undo-tree - (global-undo-tree-mode -1))) - (doom! :completion company ; the ultimate code completion backend + (corfu +orderless) ; complete with cap(f), cape and a flying feather! helm ; the *other* search engine for love and life - ivy ; a search engine for love and life + ;;ido ; the other *other* search engine... + ;;ivy ; a search engine for love and life + vertico ; the search engine of the future :ui doom ; what makes DOOM look the way it does - deft + (emoji +unicode) ; 🙂 hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW - hydra - modeline + indent-guides ; highlighted indent columns + modeline ; snazzy, Atom-inspired modeline, plus API ophints ; highlight the region an operation acts on - (popup ; tame sudden yet inevitable temporary windows - +all ; catch all popups that start with an asterix - +defaults) ; default popup rules + (popup +defaults) ; tame sudden yet inevitable temporary windows + ;;smooth-scroll ; So smooth you won't believe it's not butter unicode ; extended unicode support for various languages - indent-guides - vc-gutter ; vcs diff in the fringe + (vc-gutter +pretty) ; vcs diff in the fringe vi-tilde-fringe ; fringe tildes to mark beyond EOB workspaces ; tab emulation, persistence & separate workspaces - (emoji +unicode) :editor (evil +everywhere); come to the dark side, we have cookies + file-templates ; auto-snippets for empty files fold ; (nigh) universal code folding - rotate-text ; cycle region at point between text candidates + ;;(format +onsave) ; automated prettiness + ;;god ; run Emacs commands without modifier keys + ;;lispy ; vim for lisp, for people who don't like vim + ;;multiple-cursors ; editing in many places at once + ;;objed ; text object editing for the innocent + ;;parinfer ; turn lisp into python, sort of + ;;rotate-text ; cycle region at point between text candidates snippets ; my elves. They type so I don't have to word-wrap ; soft wrapping with language-aware indent :emacs - (dired +icons) ; making dired pretty [functional] + dired ; making dired pretty [functional] electric ; smarter, keyword-based electric-indent - (ibuffer +icons) ; interactive buffer management + ibuffer ; interactive buffer management + undo ; persistent, smarter undo for your inevitable mistakes vc ; version-control and Emacs, sitting in a tree - undo :term - eshell ; a consistent, cross-platform shell (WIP) - vterm - - :tools - debugger ; Stepping through code, to help you add bugs - (eval +overlay) ; run code, run (also, repls) - (lookup ; helps you navigate your code and documentation - +docsets) ; ...or in Dash docsets locally - lsp - magit ; a git porcelain for Emacs - docker - ;;pass ; password manager for nerds - pdf ; pdf enhancements - eval - biblio - (lookup +dictionary) + eshell ; the elisp shell that works everywhere + ;;shell ; simple shell REPL for Emacs + ;;term ; basic terminal emulator for Emacs + vterm ; the best terminal emulation in Emacs :checkers - syntax ; tasing you for every semicolon you forget - (spell - +aspell - +everywhere) ; tasing you for misspelling mispelling + syntax ; tasing you for every semicolon you forget + (spell +aspell +everywhere) ; tasing you for misspelling mispelling + + :tools + ;;ansible + biblio ; Writes a PhD for you (citation needed) + ;;collab ; buffers with friends + debugger ; FIXME stepping through code, to help you add bugs + ;;direnv + ;;docker + ;;editorconfig ; let someone else argue about tabs vs spaces + ;;ein ; tame Jupyter notebooks with emacs + (eval +overlay) ; run code, run (also, repls) + (lookup +dictionary) ; navigate your code and its documentation + ;;lsp ; M-x vscode + magit ; a git porcelain for Emacs + ;;make ; run make tasks from Emacs + ;;pass ; password manager for nerds + pdf ; pdf enhancements + ;;terraform ; infrastructure as code + ;;tmux ; an API for interacting with tmux + ;;tree-sitter ; syntax and parsing, sitting in a tree... + ;;upload ; map local to remote projects via ssh/ftp + + :os + ;;(:if (featurep :system 'macos) macos) ; improve compatibility with macOS + ;;tty ; improve the terminal Emacs experience :lang + ;;agda ; types of types of types of types... + ;;beancount ; mind the GAAP + ;;(cc +lsp) ; C > C++ == 1 + ;;clojure ; java with a lisp + ;;common-lisp ; if you've seen one lisp, you've seen them all + ;;coq ; proofs-as-programs + ;;crystal ; ruby at the speed of c + ;;csharp ; unity, .NET, and mono shenanigans data ; config/data formats + ;;(dart +flutter) ; paint ui and not much else + ;;dhall + ;;elixir ; erlang done right + ;;elm ; care for a cup of TEA? emacs-lisp ; drown in parentheses - go - (javascript - +lsp) - (latex - +latexmk) - ;; markdown ; writing docs for people to ignore - (org ; organize your plain life in plain text - +dragndrop ; drag & drop files/images into org buffers - +hugo ; use Emacs for hugo blogging - +roam2 ; - +gnuplot - +jupyter - +pretty - +present) ; using org-mode for presentations + ;;erlang ; an elegant language for a more civilized age + ;;ess ; emacs speaks statistics + ;;factor + ;;faust ; dsp, but you get to keep your soul + ;;fortran ; in FORTRAN, GOD is REAL (unless declared INTEGER) + ;;fsharp ; ML stands for Microsoft's Language + ;;fstar ; (dependent) types and (monadic) effects and Z3 + ;;gdscript ; the language you waited for + ;;(go +lsp) ; the hipster dialect + ;;(graphql +lsp) ; Give queries a REST + ;;(haskell +lsp) ; a language that's lazier than I am + ;;hy ; readability of scheme w/ speed of python + ;;idris ; a language you can depend on + ;;json ; At least it ain't XML + ;;(java +lsp) ; the poster child for carpal tunnel syndrome + ;;javascript ; all(hope(abandon(ye(who(enter(here)))))) + ;;julia ; a better, faster MATLAB + ;;kotlin ; a better, slicker Java(Script) + latex ; writing papers in Emacs has never been so fun + ;;lean ; for folks with too much to prove + ;;ledger ; be audit you can be + ;;lua ; one-based indices? one-based indices + markdown ; writing docs for people to ignore + ;;nim ; python + lisp at the speed of c + ;;nix ; I hereby declare "nix geht mehr!" + ;;ocaml ; an objective camel + (org +pretty +roam2 +hugo +noter) ; organize your plain life in plain text + ;;php ; perl's insecure younger brother + ;;plantuml ; diagrams for confusing people more + ;;graphviz ; diagrams for confusing yourself even more + ;;purescript ; javascript, but functional python ; beautiful is better than ugly - (sh ; she sells {ba,z,fi}sh shells on the C xor - +lsp) - (web - +lsp) - yaml + ;;qt ; the 'cutest' gui framework ever + ;;racket ; a DSL for DSLs + ;;raku ; the artist formerly known as perl6 + ;;rest ; Emacs as a REST client + ;;rst ; ReST in peace + ;;(ruby +rails) ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"} + ;;(rust +lsp) ; Fe2O3.unwrap().unwrap().unwrap().unwrap() + ;;scala ; java, but good + ;;(scheme +guile) ; a fully conniving family of lisps + sh ; she sells {ba,z,fi}sh shells on the C xor + ;;sml + ;;solidity ; do you need a blockchain? No. + ;;swift ; who asked for emoji variables? + ;;terra ; Earth and Moon in alignment for performance. + ;;web ; the tubes + ;;yaml ; JSON, but readable + ;;zig ; C, but simpler :email - (mu4e +gmail) + ;;(mu4e +org +gmail) + ;;notmuch + ;;(wanderlust +gmail) :app - ;; calendar + ;;calendar + ;;emms + ;;everywhere ; *leave* Emacs!? You must be joking + ;;irc ; how neckbeards socialize ;;(rss +org) ; emacs as an RSS reader - ;;write ; emacs for writers (fiction, notes, papers, etc.) :config literate - (default +bindings) - ) + (default +bindings +smartparens)) #+end_src * Doom =packages.el= @@ -2944,9 +3188,6 @@ Provides nice functions such as: ** Org Mode Related https://github.com/doomemacs/doomemacs/issues/6478 -#+begin_src emacs-lisp -(package! org-mode :pin "971eb6885ec996c923e955730df3bafbdc244e54") -#+end_src #+begin_src emacs-lisp ;; Automatic toggling of LaTeX fragments @@ -3000,28 +3241,17 @@ https://github.com/doomemacs/doomemacs/issues/6478 (package! poet-theme) #+end_src +#+begin_src emacs-lisp :tangle no +;; Major Mode for Matlab +(package! matlab-mode + :recipe (:host github :repo "matlab-mode/mirror") + :pin "f1a709e") +#+end_src + #+begin_src emacs-lisp ;; Major Mode for Matlab (package! matlab-mode - :recipe (:host github :repo "matlab-mode/mirror")) -#+end_src - -#+begin_src emacs-lisp -;; Don't use this default package in Doom -(package! evil-escape :disable t) -#+end_src - -#+begin_src emacs-lisp -;; Nice gantt charts -(package! ob-mermaid) -#+end_src - -#+begin_src emacs-lisp -;; Vimrc -(package! vimrc-mode) - -(package! transient :pin "c2bdf7e12c530eb85476d3aef317eb2941ab9440") -(package! with-editor :pin "391e76a256aeec6b9e4cbd733088f30c677d965b") + :recipe (:host github :repo "mathworks/Emacs-MATLAB-Mode")) #+end_src #+begin_src emacs-lisp @@ -3082,3 +3312,35 @@ https://github.com/doomemacs/doomemacs/issues/6478 :branch "main" :files ("*.el"))) #+end_src + +Why this was pinned? +#+begin_src emacs-lisp +;; (package! org-mode :pin "971eb6885ec996c923e955730df3bafbdc244e54") +#+end_src + +#+begin_src emacs-lisp +;; Nice theme +(package! languagetool) +#+end_src + +#+begin_src emacs-lisp +;; Don't use this default package in Doom +(package! evil-escape :disable t) +#+end_src + +#+begin_src emacs-lisp +;; Nice gantt charts +(package! ob-mermaid) +#+end_src + +#+begin_src emacs-lisp +;; Vimrc +(package! vimrc-mode) + +(package! transient :pin "c2bdf7e12c530eb85476d3aef317eb2941ab9440") +(package! with-editor :pin "391e76a256aeec6b9e4cbd733088f30c677d965b") +#+end_src + +#+begin_src emacs-lisp +(package! org-ai) +#+end_src diff --git a/emacs-library-babel.org b/emacs-library-babel.org index 0bd3c4f..8af3ee0 100644 --- a/emacs-library-babel.org +++ b/emacs-library-babel.org @@ -30,6 +30,16 @@ echo "[[file:$_figdir/$filename.$ext]]" (cons (car tbl) (cons 'hline (cdr tbl))) #+end_src +* Python Related +** =python-dir= Go to current directory + +#+name: python-dir +#+begin_src python :tangle no :results none :exports none :var current_dir="" +# Go to current Directory +import os +os.chdir(current_dir) +#+end_src + * Matlab Related ** =matlab-dir= Go to current directory diff --git a/emacs-snippets.org b/emacs-snippets.org index 006ab17..df0c102 100644 --- a/emacs-snippets.org +++ b/emacs-snippets.org @@ -424,19 +424,23 @@ $0 #contributor : Thomas Dehaeze #name :Python-Figure # -- -,#+begin_src jupyter-python :file ${2:filename}.png :results none -# Figure - ${1:description} -plt.figure(figsize=(${3:1200}/150, ${4:800}/150), dpi=150) -plt.clf +,#+begin_src python :exports none :results none +# ${1:description} +fig = plt.figure() $0 -plt.savefig('figs/$2.pdf', transparent=True, bbox_inches='tight', pad_inches=0) +,#+end_src + +,#+begin_src python :tangle no :results output file replace :file +plt.savefig('figs/${2:filename}.pdf', bbox_inches='tight', pad_inches=0) ,#+end_src ,#+name: fig:$2 ,#+caption: $1 +,#+RESULTS: [[file:figs/$2.png]] #+end_src + ** Matlab Specific *** Mconfig #+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mconfig