<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <!-- 2020-05-26 mar. 08:39 --> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>Doom Emacs Configuration</title> <meta name="generator" content="Org mode" /> <meta name="author" content="Dehaeze Thomas" /> <link rel="stylesheet" type="text/css" href="./css/htmlize.css"/> <link rel="stylesheet" type="text/css" href="./css/readtheorg.css"/> <script type="text/javascript" src="./js/jquery.min.js"></script> <script type="text/javascript" src="./js/bootstrap.min.js"></script> <script type="text/javascript" src="./js/jquery.stickytableheaders.min.js"></script> <script type="text/javascript" src="./js/readtheorg.js"></script> </head> <body> <div id="org-div-home-and-up"> <a accesskey="h" href="./index.html"> UP </a> | <a accesskey="H" href="./index.html"> HOME </a> </div><div id="content"> <h1 class="title">Doom Emacs Configuration</h1> <div id="table-of-contents"> <h2>Table of Contents</h2> <div id="text-table-of-contents"> <ul> <li><a href="#org1e5264a">Useful Bindings</a> <ul> <li><a href="#orgbca83fb">General Bindings</a></li> <li><a href="#orgbb83b0a">Org-Babel Bindings</a></li> <li><a href="#org7ac1104">Evil bindings</a></li> </ul> </li> <li><a href="#orge548d2c">Basic Configuration</a> <ul> <li><a href="#orgd49c2db">Personal Information</a></li> <li><a href="#orgcf3b44c">Doom Config</a></li> <li><a href="#orga2ab779">Evil</a></li> <li><a href="#org10e9de4">Which Key</a></li> <li><a href="#org0272904">Visual</a></li> <li><a href="#orgfa0f4d4">Change default alert backend</a></li> <li><a href="#orgab0c401">Lockfiles</a></li> <li><a href="#org343ab5d">Disable highlight of current line</a></li> <li><a href="#org8fb9aef">Remap <code>jump-forward</code> key binding</a></li> <li><a href="#orgc047155">Magit</a></li> <li><a href="#org5891449">Dired</a></li> <li><a href="#orgd5fd766">PDF-Tools</a></li> <li><a href="#org3ef34ce">Yassnippets</a></li> <li><a href="#orgdf363e3">Ox-Hugo</a></li> </ul> </li> <li><a href="#orgda82ce0">Org Mode</a> <ul> <li><a href="#orge682476">Org General Config</a></li> <li><a href="#org4479f13">Org Inline Images</a></li> <li><a href="#org8afc2de">Org Links</a></li> <li><a href="#orgcd26239">Org Tagging</a></li> <li><a href="#org65d0f06">Org Refile</a></li> <li><a href="#org25ed4f3">Org TODO</a></li> <li><a href="#orga7b5140">Org Archive</a></li> <li><a href="#orga36def8">Org Agenda</a></li> <li><a href="#org0b832f0">Org Fancy Priority</a></li> <li><a href="#orgb9fc96d">Org Notification based on calendar event</a> <ul> <li><a href="#org1199365">appt-notification script</a></li> </ul> </li> <li><a href="#org3c5e1f3">Org Structure Template</a></li> <li><a href="#org9713b96">Org Capture</a></li> <li><a href="#org839d7a9">Org Export</a></li> <li><a href="#org253b1f3">HTML Export</a> <ul> <li><a href="#orge413ce2">HTML Defaults</a></li> <li><a href="#orgfe81dca">MathJax</a></li> <li><a href="#orgbaa8390">Ensuring useful HTML Anchors</a></li> <li><a href="#orged04965">Folded Drawers</a></li> </ul> </li> <li><a href="#org1a43ae2">Org LaTeX</a> <ul> <li><a href="#org3a04c02">LaTeX Fragments</a></li> <li><a href="#orgaa26736">LaTeX Classes</a></li> <li><a href="#org3480957">Ox Latex Subfigure package</a></li> <li><a href="#org44cf309">Clear page before heading</a></li> <li><a href="#org3b03fac">Default added packages</a></li> <li><a href="#org3b79603">Some configurations</a></li> <li><a href="#orgce10c33">Beamer</a></li> <li><a href="#org7d55947">Custom Export - Add Page and Label for LaTeX export</a></li> <li><a href="#org9d2764e">Number Equations</a></li> </ul> </li> <li><a href="#org5236d09">LaTeX macro both for LaTeX and HTML export</a></li> <li><a href="#org51ce4d3">Org Projects</a></li> <li><a href="#orgf5cfaee">Org big org-project</a></li> <li><a href="#org0a79d9f">Automatically run <code>startblock</code> when opening org-mode files</a></li> <li><a href="#orga1fc443">Insert ScreenShot or Picture from Phone</a></li> <li><a href="#org7902aff">Render Tables</a></li> <li><a href="#org66f0a8a">Org Gcal</a></li> <li><a href="#orgafe7963">Custom Keybindings - <code>,</code> leader key and <code>C-c</code></a> <ul> <li><a href="#orgdc0a145">Insert Elements <code>,i</code></a></li> <li><a href="#orgc62ba13">LaTeX <code>,l</code></a></li> <li><a href="#org0b5774e">Org LaTeX Automatic fragment</a></li> <li><a href="#orgee735c5">Bibtex <code>,r</code></a></li> <li><a href="#org87d89c4">Open ranger in current directory <code>,o</code></a></li> <li><a href="#orgb7c8cca">View in External programs <code>,v</code></a></li> </ul> </li> </ul> </li> <li><a href="#org38a8163">Org Babel</a> <ul> <li><a href="#org97bf4fc">Main configuration</a></li> <li><a href="#org741956d">Appearance of source blocks</a></li> <li><a href="#org737e623">Indentation</a></li> <li><a href="#orgee4e789">Library of Babel</a></li> <li><a href="#org232fea8">Org-Babel Matlab</a></li> <li><a href="#org80ca3ef">Some functions for using Matlab with Org Babel <code>,m</code></a></li> <li><a href="#org71fa917">Remap <code>ctrl-ret</code> used to execute the src block and go to the next one</a></li> <li><a href="#org4b37ab8">Remap <code>ctrl-shift-ret</code> used to execute the (matlab) src block in the background and go to the next one</a> <ul> <li><a href="#orgb05f319"><code>tdh-org-babel-execute-matlab-background</code></a></li> <li><a href="#orgf77f938"><code>tdh-matlab-execute-selected</code></a></li> <li><a href="#orgc5f1a86">Remap <code>ctrl-shift-ref</code></a></li> </ul> </li> <li><a href="#org354b3a0">Align Source Blocks</a></li> <li><a href="#org5783483">Helping Functions - Tangling <code>,b</code></a></li> </ul> </li> <li><a href="#orgbf4c78e">Bibliography Management</a> <ul> <li><a href="#orgd6dd52d">Org Ref (link)</a></li> <li><a href="#orgd5277ba">Org Noter (link)</a></li> <li><a href="#org11a3a48">Org Roam (link)</a></li> <li><a href="#org18473f5">Helm-Bibtex (link)</a></li> <li><a href="#orgd601e31">Deft</a></li> <li><a href="#org910a943">Org-Roam-Bibtex (link)</a></li> <li><a href="#org61eb6bc">Org-Ref-Ox-Hugo (link)</a></li> </ul> </li> <li><a href="#org5bc2aea">LaTeX</a> <ul> <li><a href="#org0822b20">Master file</a></li> <li><a href="#org944a888">Clean Output Files</a></li> <li><a href="#orga4ad7f6">PDF Viewer</a></li> <li><a href="#org120de8b">Bibtex</a></li> </ul> </li> <li><a href="#orgd94d627">Matlab</a> <ul> <li><a href="#orgb915baf">Setup Matlab Mode</a></li> <li><a href="#orga36d033">Setup Flycheck to work with <code>mlint</code></a></li> <li><a href="#org04bf41d">Completion in the Matlab Shell</a></li> <li><a href="#orgace4163">Beautify code</a></li> <li><a href="#orgb85ca7e">Key Bindings</a></li> </ul> </li> <li><a href="#org7d36b5d">Mu4e</a> <ul> <li><a href="#org0022939">Resources</a></li> <li><a href="#orgdf9660c">Cheatsheet</a></li> <li><a href="#org998a101">Helping function</a></li> <li><a href="#orge7dad22">Basic Config</a></li> <li><a href="#org5886531">Additional config</a></li> <li><a href="#orgbc87a17">Provide Information</a></li> <li><a href="#org4f572af">Receiving emails using mbsync</a></li> <li><a href="#orgd7ab730">Contexts</a></li> <li><a href="#org0f5f14d">Sending mails</a></li> <li><a href="#orgeb454c4">Bookmarks</a></li> </ul> </li> <li><a href="#org0b90463">Doom <code>init.el</code></a></li> <li><a href="#org973006b">Doom <code>packages.el</code></a></li> </ul> </div> </div> <p> <a href="https://medium.com/urbint-engineering/emacs-doom-for-newbies-1f8038604e3b">https://medium.com/urbint-engineering/emacs-doom-for-newbies-1f8038604e3b</a> <a href="https://noelwelsh.com/posts/2019-01-10-doom-emacs.html">https://noelwelsh.com/posts/2019-01-10-doom-emacs.html</a> <a href="https://dotdoom.netlify.com/config.html">https://dotdoom.netlify.com/config.html</a> <a href="https://emacs.christianbaeuerlein.com/">https://emacs.christianbaeuerlein.com/</a> <a href="https://github.com/nmartin84/.doom.d/blob/master/config.org">https://github.com/nmartin84/.doom.d/blob/master/config.org</a> </p> <p> Documentation: </p> <ul class="org-ul"> <li><a href="https://github.com/hlissner/doom-emacs/blob/develop/docs/index.org">https://github.com/hlissner/doom-emacs/blob/develop/docs/index.org</a></li> </ul> <p> When changing <code>init.el</code> or <code>package.el</code>, tangle the files and then run <code>doom sync</code>. After that, restart Emacs with <code>spc q r</code>. </p> <div id="outline-container-org1e5264a" class="outline-2"> <h2 id="org1e5264a">Useful Bindings</h2> <div class="outline-text-2" id="text-org1e5264a"> <ul class="org-ul"> <li><code>align-regexp</code>: equivalent of <a href="https://github.com/junegunn/vim-easy-align">vim-easy-align</a>. Very useful to align tables and stuff</li> </ul> </div> <div id="outline-container-orgbca83fb" class="outline-3"> <h3 id="orgbca83fb">General Bindings</h3> <div class="outline-text-3" id="text-orgbca83fb"> <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left" /> <col class="org-left" /> </colgroup> <tbody> <tr> <td class="org-left"><code>spc :</code></td> <td class="org-left">Execute command</td> </tr> <tr> <td class="org-left"><code>spc <</code></td> <td class="org-left">Switch to buffer</td> </tr> <tr> <td class="org-left"><code>spc X</code></td> <td class="org-left">org-capture</td> </tr> <tr> <td class="org-left"><code>spc s s</code></td> <td class="org-left">Search in buffer with swiper</td> </tr> <tr> <td class="org-left"><code>spc s p</code></td> <td class="org-left">Search in project</td> </tr> <tr> <td class="org-left"><code>spc p p</code></td> <td class="org-left">Switch project</td> </tr> <tr> <td class="org-left"><code>spc p t</code></td> <td class="org-left">TODOs in project</td> </tr> <tr> <td class="org-left"><code>spc o f</code></td> <td class="org-left">Create frame</td> </tr> <tr> <td class="org-left"><code>spc o e</code></td> <td class="org-left">Toggle Eshell</td> </tr> <tr> <td class="org-left"><code>spc n l</code></td> <td class="org-left">Store link</td> </tr> <tr> <td class="org-left"><code>spc g g</code></td> <td class="org-left">Magit status</td> </tr> <tr> <td class="org-left"><code>spc f r</code></td> <td class="org-left">Open recent file</td> </tr> <tr> <td class="org-left"><code>spc b B</code></td> <td class="org-left">Switch to buffer</td> </tr> <tr> <td class="org-left"><code>spc b d</code></td> <td class="org-left">Kill current buffer</td> </tr> <tr> <td class="org-left"><code>spc b i</code></td> <td class="org-left">ibuffer</td> </tr> <tr> <td class="org-left"><code>spc tab .</code></td> <td class="org-left">Switch to workspace</td> </tr> <tr> <td class="org-left"><code>spc tab n</code></td> <td class="org-left">New workspace</td> </tr> <tr> <td class="org-left"><code>spc tab r</code></td> <td class="org-left">Rename workspace</td> </tr> <tr> <td class="org-left"><code>spc m A</code></td> <td class="org-left">org-archive-subtree</td> </tr> <tr> <td class="org-left"><code>spc m I</code></td> <td class="org-left">org-toggle-inline-images</td> </tr> <tr> <td class="org-left"><code>spc m d</code></td> <td class="org-left">org-deadline</td> </tr> <tr> <td class="org-left"><code>spc m e</code></td> <td class="org-left">org-export-dispatch</td> </tr> <tr> <td class="org-left"><code>spc m o</code></td> <td class="org-left">org-set-property</td> </tr> <tr> <td class="org-left"><code>spc m s</code></td> <td class="org-left">org-schedule</td> </tr> <tr> <td class="org-left"><code>spc m t</code></td> <td class="org-left">org-todo</td> </tr> </tbody> </table> </div> </div> <div id="outline-container-orgbb83b0a" class="outline-3"> <h3 id="orgbb83b0a">Org-Babel Bindings</h3> <div class="outline-text-3" id="text-orgbb83b0a"> <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left" /> <col class="org-left" /> </colgroup> <tbody> <tr> <td class="org-left"><code>C-c C-v p</code></td> <td class="org-left">org-babel-previous-src-block</td> </tr> <tr> <td class="org-left"><code>C-c C-v n</code></td> <td class="org-left">org-babel-next-src-block</td> </tr> <tr> <td class="org-left"><code>C-c C-v e</code></td> <td class="org-left">org-babel-execute-maybe</td> </tr> <tr> <td class="org-left"><code>C-c C-v o</code></td> <td class="org-left">org-babel-open-src-block-result</td> </tr> <tr> <td class="org-left"><code>C-c C-v v</code></td> <td class="org-left">org-babel-expand-src-block</td> </tr> <tr> <td class="org-left"><code>C-c C-v u</code></td> <td class="org-left">org-babel-goto-src-block-head</td> </tr> <tr> <td class="org-left"><code>C-c C-v g</code></td> <td class="org-left">org-babel-goto-named-src-block</td> </tr> <tr> <td class="org-left"><code>C-c C-v r</code></td> <td class="org-left">org-babel-goto-named-result</td> </tr> <tr> <td class="org-left"><code>C-c C-v b</code></td> <td class="org-left">org-babel-execute-buffer</td> </tr> <tr> <td class="org-left"><code>C-c C-v s</code></td> <td class="org-left">org-babel-execute-subtree</td> </tr> <tr> <td class="org-left"><code>C-c C-v d</code></td> <td class="org-left">org-babel-demarcate-block</td> </tr> <tr> <td class="org-left"><code>C-c C-v t</code></td> <td class="org-left">org-babel-tangle</td> </tr> <tr> <td class="org-left"><code>C-c C-v f</code></td> <td class="org-left">org-babel-tangle-file</td> </tr> <tr> <td class="org-left"><code>C-c C-v c</code></td> <td class="org-left">org-babel-check-src-block</td> </tr> <tr> <td class="org-left"><code>C-c C-v j</code></td> <td class="org-left">org-babel-insert-header-arg</td> </tr> <tr> <td class="org-left"><code>C-c C-v l</code></td> <td class="org-left">org-babel-load-in-session</td> </tr> <tr> <td class="org-left"><code>C-c C-v i</code></td> <td class="org-left">org-babel-lob-ingest</td> </tr> <tr> <td class="org-left"><code>C-c C-v I</code></td> <td class="org-left">org-babel-view-src-block-info</td> </tr> <tr> <td class="org-left"><code>C-c C-v z</code></td> <td class="org-left">org-babel-switch-to-session-with-code</td> </tr> <tr> <td class="org-left"><code>C-c C-v a</code></td> <td class="org-left">org-babel-sha1-hash</td> </tr> <tr> <td class="org-left"><code>C-c C-v h</code></td> <td class="org-left">org-babel-describe-bindings</td> </tr> <tr> <td class="org-left"><code>C-c C-v x</code></td> <td class="org-left">org-babel-do-key-sequence-in-edit-buffer</td> </tr> </tbody> </table> </div> </div> <div id="outline-container-org7ac1104" class="outline-3"> <h3 id="org7ac1104">Evil bindings</h3> <div class="outline-text-3" id="text-org7ac1104"> <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left" /> <col class="org-left" /> </colgroup> <tbody> <tr> <td class="org-left"><code>gv</code></td> <td class="org-left">Selects the previous visual</td> </tr> <tr> <td class="org-left"><code>o</code> in visual mode</td> <td class="org-left">go to the `Other` end of the selection</td> </tr> <tr> <td class="org-left"><code>g=</code> and <code>g-</code></td> <td class="org-left">Increase/decrement number</td> </tr> <tr> <td class="org-left"><code>t</code> followed by any char</td> <td class="org-left">goes “till” next character (not included)</td> </tr> <tr> <td class="org-left"><code>f</code> followed by any char</td> <td class="org-left">“find” next character (included)</td> </tr> <tr> <td class="org-left"><code>yt.</code></td> <td class="org-left">yank until next <code>.</code></td> </tr> </tbody> </table> </div> </div> </div> <div id="outline-container-orge548d2c" class="outline-2"> <h2 id="orge548d2c">Basic Configuration</h2> <div class="outline-text-2" id="text-orge548d2c"> </div> <div id="outline-container-orgd49c2db" class="outline-3"> <h3 id="orgd49c2db">Personal Information</h3> <div class="outline-text-3" id="text-orgd49c2db"> <div class="org-src-container"> <pre class="src src-emacs-lisp">;; These are used for a number of things, particularly for GPG configuration, ;; some email clients, file templates and snippets. (setq user-full-name "Dehaeze Thomas" user-mail-address "dehaeze.thomas@gmail.com") </pre> </div> </div> </div> <div id="outline-container-orgcf3b44c" class="outline-3"> <h3 id="orgcf3b44c">Doom Config</h3> <div class="outline-text-3" id="text-orgcf3b44c"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq doom-font (font-spec :family "Hack Nerd Font Mono" :size 12 :weight 'semi-light) doom-variable-pitch-font (font-spec :family "Hack Nerd Font Mono") doom-unicode-font (font-spec :family "Hack Nerd Font Mono" :size 12) doom-big-font (font-spec :family "Hack Nerd Font Mono" :size 19)) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq doom-theme 'doom-gruvbox) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq display-line-numbers-type t) </pre> </div> </div> </div> <div id="outline-container-orga2ab779" class="outline-3"> <h3 id="orga2ab779">Evil</h3> <div class="outline-text-3" id="text-orga2ab779"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! evil (map! :m "-" #'dired-jump)) </pre> </div> <p> Make movement keys work like they should </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(define-key evil-normal-state-map (kbd "<remap> <evil-next-line>") 'evil-next-visual-line) (define-key evil-normal-state-map (kbd "<remap> <evil-previous-line>") 'evil-previous-visual-line) (define-key evil-motion-state-map (kbd "<remap> <evil-next-line>") 'evil-next-visual-line) (define-key evil-motion-state-map (kbd "<remap> <evil-previous-line>") 'evil-previous-visual-line) </pre> </div> <p> Make horizontal movement cross lines </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq-default evil-cross-lines t) </pre> </div> </div> </div> <div id="outline-container-org10e9de4" class="outline-3"> <h3 id="org10e9de4">Which Key</h3> <div class="outline-text-3" id="text-org10e9de4"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! which-key (setq which-key-idle-delay 0.5 which-key-idle-secondary-delay 0.01 which-key-sort-order 'which-key-key-order-alpha)) </pre> </div> </div> </div> <div id="outline-container-org0272904" class="outline-3"> <h3 id="org0272904">Visual</h3> <div class="outline-text-3" id="text-org0272904"> <p> Automatic line wrap. </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(global-visual-line-mode nil) </pre> </div> <p> Turn off auto-fill mode that add line breaks. </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(auto-fill-mode -1) (remove-hook 'text-mode-hook 'turn-on-auto-fill) ;; turn on auto-fill for text-mode (add-hook 'text-mode-hook 'turn-on-auto-fill) (after! org ;; turn off auto-fill for org-mode (add-hook 'org-mode-hook 'turn-off-auto-fill)) </pre> </div> </div> </div> <div id="outline-container-orgfa0f4d4" class="outline-3"> <h3 id="orgfa0f4d4">Change default alert backend</h3> <div class="outline-text-3" id="text-orgfa0f4d4"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq alert-default-style 'libnotify) </pre> </div> </div> </div> <div id="outline-container-orgab0c401" class="outline-3"> <h3 id="orgab0c401">Lockfiles</h3> <div class="outline-text-3" id="text-orgab0c401"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq create-lockfiles nil) </pre> </div> </div> </div> <div id="outline-container-org343ab5d" class="outline-3"> <h3 id="org343ab5d">Disable highlight of current line</h3> <div class="outline-text-3" id="text-org343ab5d"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(global-hl-line-mode -1) (after! org (add-hook 'org-mode-hook (lambda() (hl-line-mode -1) (global-hl-line-mode -1)) 't )) </pre> </div> </div> </div> <div id="outline-container-org8fb9aef" class="outline-3"> <h3 id="org8fb9aef">Remap <code>jump-forward</code> key binding</h3> <div class="outline-text-3" id="text-org8fb9aef"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(with-eval-after-load 'better-jumper (map! :desc "Jump Forward" "C-i" #'better-jumper-jump-forward)) </pre> </div> </div> </div> <div id="outline-container-orgc047155" class="outline-3"> <h3 id="orgc047155">Magit</h3> <div class="outline-text-3" id="text-orgc047155"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setenv "GIT_ASKPASS" "git-gui--askpass") (setq magit-diff-refine-hunk 'all) </pre> </div> </div> </div> <div id="outline-container-org5891449" class="outline-3"> <h3 id="org5891449">Dired</h3> <div class="outline-text-3" id="text-org5891449"> <ul class="org-ul"> <li><code>C-c C-e</code> Writable Dired mode, when changes are done <code>C-c C-c</code>. This works also with <code>C-x C-q</code></li> <li><code>C-c C-r</code> use <code>rsync</code> to copy file in the background</li> <li><code>+</code> Create a directory</li> <li><code>R</code> Rename / move</li> <li><code>C</code> Copy</li> <li><code>d</code> Delete</li> <li><code>m</code> Mark</li> <li><code>U</code> unmark all marked</li> <li><code>t</code> invert the selection</li> <li><code>u</code> unmark / undelete</li> <li><code>x</code> actually delete files/directories marked for deletion</li> <li><code>!</code> Execute shell command on this file, or currently marked files</li> <li><code>%m</code> mark by pattern</li> <li><code>o</code> sort by time/name</li> <li><code>(</code> Hide details</li> <li><code>)</code> Show git infos</li> </ul> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! dired-narrow :config (map! :map dired-mode-map :n "f" 'dired-narrow-fuzzy)) </pre> </div> </div> </div> <div id="outline-container-orgd5fd766" class="outline-3"> <h3 id="orgd5fd766">PDF-Tools</h3> <div class="outline-text-3" id="text-orgd5fd766"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! pdf-tools :config (add-hook 'pdf-view-mode-hook (lambda() (linum-mode -1))) ) </pre> </div> </div> </div> <div id="outline-container-org3ef34ce" class="outline-3"> <h3 id="org3ef34ce">Yassnippets</h3> <div class="outline-text-3" id="text-org3ef34ce"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(push "~/.config/doom/snippets" yas-snippet-dirs) (yas-global-mode 1) </pre> </div> </div> </div> <div id="outline-container-orgdf363e3" class="outline-3"> <h3 id="orgdf363e3">Ox-Hugo</h3> <div class="outline-text-3" id="text-orgdf363e3"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-export-everything-to-hugo () "Export all the .org files in the specified directory to markdown using Hugo" (interactive) (setq org-files (directory-files (read-directory-name "Directory:" "/home/thomas/Cloud/brain/") t "org$" t)) (while org-files (setq current-org-file (car org-files)) (message "Exporting %s" current-org-file) (find-file current-org-file) (org-hugo-export-to-md) (setq org-files (cdr org-files)))) </pre> </div> </div> </div> </div> <div id="outline-container-orgda82ce0" class="outline-2"> <h2 id="orgda82ce0">Org Mode</h2> <div class="outline-text-2" id="text-orgda82ce0"> <ul class="org-ul"> <li><a href="http://cachestocaches.com/2016/9/my-workflow-org-agenda/">http://cachestocaches.com/2016/9/my-workflow-org-agenda/</a></li> <li><a href="http://doc.norang.ca/org-mode.html#TodoKeywords">http://doc.norang.ca/org-mode.html#TodoKeywords</a></li> <li><a href="https://emacs.cafe/emacs/orgmode/gtd/2017/06/30/orgmode-gtd.html">https://emacs.cafe/emacs/orgmode/gtd/2017/06/30/orgmode-gtd.html</a></li> </ul> </div> <div id="outline-container-orge682476" class="outline-3"> <h3 id="orge682476">Org General Config</h3> <div class="outline-text-3" id="text-orge682476"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq org-directory "~/Cloud/org/") (after! org (setq org-directory "~/Cloud/org/") ;; Replace the content marker, “⋯”, with a nice unicode arrow. (setq org-ellipsis " ⤵") (setq org-default-notes-file "~/Cloud/org/refile.org") ;; Avoid accidentally editing folded regions, say by adding text after an Org “⋯”. (setq org-catch-invisible-edits 'show) ;; The following setting hides blank lines between headings which keeps folded view nice and compact. (setq org-cycle-separator-lines 0) ;; Indent according to the outline structure (setq org-startup-indented t) (setq org-startup-folded t) ;; Record the information of when the task was marked as DONE (setq org-log-done 'time) ;; begining of line on heading behavior (setq org-special-ctrl-a/e nil) ) </pre> </div> <p> TAB was changed to toggle only the visibility state of the current subtree, rather than cycle through it recursively. This can be reversed with: </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! evil-org (remove-hook 'org-tab-first-hook #'+org-cycle-only-current-subtree-h)) </pre> </div> </div> </div> <div id="outline-container-org4479f13" class="outline-3"> <h3 id="org4479f13">Org Inline Images</h3> <div class="outline-text-3" id="text-org4479f13"> <p> Display the real size of images and not the one set with <code>attr_latex: :width \linewidth</code> for instance. </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-image-actual-width t)) </pre> </div> </div> </div> <div id="outline-container-org8afc2de" class="outline-3"> <h3 id="org8afc2de">Org Links</h3> <div class="outline-text-3" id="text-org8afc2de"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-link-abbrev-alist '(("bib" . "~/Cloud/brain/biblio/references.bib::%s") ("notes" . "~/Cloud/brain/%s.org") ("papers" . "~/Cloud/pdfs/%s.pdf"))) ) </pre> </div> </div> </div> <div id="outline-container-orgcd26239" class="outline-3"> <h3 id="orgcd26239">Org Tagging</h3> <div class="outline-text-3" id="text-orgcd26239"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org ;; Align Tags and flush right (setq org-tags-column -78) ;; Tags with fast selection keys (setq org-tag-alist (quote (("@home" . ?h) ("@work" . ?w) ("@christophe" . ?c) ("@veijo" . ?v)))) ) </pre> </div> </div> </div> <div id="outline-container-org65d0f06" class="outline-3"> <h3 id="org65d0f06">Org Refile</h3> <div class="outline-text-3" id="text-org65d0f06"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-refile-targets '((org-agenda-files . (:maxlevel . 6)))) ) </pre> </div> </div> </div> <div id="outline-container-org25ed4f3" class="outline-3"> <h3 id="org25ed4f3">Org TODO</h3> <div class="outline-text-3" id="text-org25ed4f3"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org ;; Tags with fast selection keys (setq org-todo-keywords '( (sequence "TODO(t)" "NEXT(n)" "MAIL(m)" "|" "DONE(d)") (sequence "READ(r)" "BKMK(b)" "EXER(x)" "|" "DONE(d)") (sequence "WAIT(w@/!)" "SDAY(s)" "|" "CANC(c@/!)") (sequence "QUES(q)" "|" "ANSW(a)") (sequence "EXAM(e)" "IDEA(i)" "|") )) ;; Display of the keywords (setq org-todo-keyword-faces '(("TODO" . (:foreground "#cc241d" :weight bold)) ;; red ("EXER" . (:foreground "#cc241d" :weight bold)) ;; red ("NEXT" . (:foreground "#cc241d" :weight bold)) ;; red ("MAIL" . (:foreground "#cc241d" :weight bold)) ;; red ("READ" . (:foreground "#cc241d" :weight bold)) ;; red ("ANSW" . (:foreground "#689d6a" :weight bold)) ;; aqua ("DONE" . (:foreground "#689d6a" :weight bold)) ;; aqua ("WAIT" . (:foreground "#d65d0e" :weight bold)) ;; orange ("QUES" . (:foreground "#d79921" :weight bold)) ;; yellow ("CANC" . (:foreground "#a89984" :weight bold)) ;; grey ("SDAY" . (:foreground "#98971a" :weight bold)) ;; green ("BKMK" . (:foreground "#98971a" :weight bold)) ;; green ("IDEA" . (:foreground "#98971a" :weight bold)) ;; green ("EXAM" . (:foreground "#98971a" :weight bold)))) ;; green ) </pre> </div> </div> </div> <div id="outline-container-orga7b5140" class="outline-3"> <h3 id="orga7b5140">Org Archive</h3> <div class="outline-text-3" id="text-orga7b5140"> <p> <a href="https://gist.github.com/Fuco1/e86fb5e0a5bb71ceafccedb5ca22fcfb">https://gist.github.com/Fuco1/e86fb5e0a5bb71ceafccedb5ca22fcfb</a> Archive subtrees under the same hierarchy as original in the archive files </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (defadvice org-archive-subtree (around fix-hierarchy activate) (let* ((fix-archive-p (and (not current-prefix-arg) (not (use-region-p)))) (location (org-archive--compute-location org-archive-location)) (afile (car location)) (offset (if (= 0 (length (cdr location))) 1 (1+ (string-match "[^*]" (cdr location))))) (buffer (or (find-buffer-visiting afile) (find-file-noselect afile)))) ad-do-it (when fix-archive-p (with-current-buffer buffer (goto-char (point-max)) (while (> (org-current-level) offset) (org-up-heading-safe)) (let* ((olpath (org-entry-get (point) "ARCHIVE_OLPATH")) (path (and olpath (split-string olpath "/"))) (level offset) tree-text) (when olpath (org-mark-subtree) (setq tree-text (buffer-substring (region-beginning) (region-end))) (let (this-command) (org-cut-subtree)) (goto-char (point-min)) (save-restriction (widen) (-each path (lambda (heading) (if (re-search-forward (rx-to-string `(: bol (repeat ,level "*") (1+ " ") ,heading)) nil t) (org-narrow-to-subtree) (goto-char (point-max)) (unless (looking-at "^") (insert "\n")) (insert (make-string level ?*) " " heading "\n")) (cl-incf level))) (widen) (org-end-of-subtree t t) (org-paste-subtree level tree-text)))))))) ) </pre> </div> </div> </div> <div id="outline-container-orga36def8" class="outline-3"> <h3 id="orga36def8">Org Agenda</h3> <div class="outline-text-3" id="text-orga36def8"> <p> General configuration </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org ;; File to save todo items (setq org-agenda-files (list "~/Cloud/org/")) ;; Include archived files (setq org-agenda-archives-mode t) ;; Set priority range from A to C with default A (setq org-highest-priority ?A) (setq org-lowest-priority ?C) (setq org-default-priority ?C) ;; Set colours for priorities (setq org-priority-faces '((?A . (:foreground "#FB4934")) (?B . (:foreground "#FABD2F")) (?C . (:foreground "#98971A")))) ;; Open agenda in current window (setq org-agenda-window-setup 'current-window) (setq org-agenda-prefix-format '((agenda . " %-12:c %?-12t% s") (todo . "") ;; Don't show the filename for reading agenda (tags . " %-12:c") (search . " %-12:c")) ) ) </pre> </div> <p> Org Agenda Custom Views </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org-agenda (defun tdh-org-agenda-skip-scheduled () (org-agenda-skip-entry-if 'scheduled 'deadline 'regexp "\n]+>")) (setq org-agenda-custom-commands '(("w" "Work" ((org-ql-block '(and (tags "@work") (todo "TODO") (priority "A")) ((org-ql-block-header "Important TODOs"))) (org-ql-block '(and (tags "@work") (todo "TODO") (priority "B")) ((org-ql-block-header "TODOs"))) (org-ql-block '(and (tags "@work") (todo "TODO") (priority "C")) ((org-ql-block-header "Not important TODOs"))))) ("h" "Home" ((org-ql-block '(and (tags "@home") (todo "TODO") (priority "A")) ((org-ql-block-header "Things to do"))) (org-ql-block '(and (tags "@home") (todo "TODO") (priority "B")) ((org-ql-block-header "Things to do"))) (org-ql-block '(and (tags "@home") (todo "TODO") (priority "C")) ((org-ql-block-header "Things to do"))))) ("q" "Questions to ask" ((org-ql-block '(and (todo "QUES") (tags "@christophe")) ((org-ql-block-header "Questions to Christophe"))) (org-ql-block '(and (todo "QUES") (tags "@veijo")) ((org-ql-block-header "Questions to Veijo"))) (org-ql-block '(and (todo "QUES") (not (tags "@veijo" "@christophe"))) ((org-ql-block-header "Other Questions"))))) ("R" "Already read Articles and Books" ((org-ql-block '(and (todo "DONE") (level 1) (tags "article" "inproceedings" "techreport" "inbook")) ((org-ql-block-header "Articles"))) (org-ql-block '(and (todo "DONE") (level 1) (tags "book")) ((org-ql-block-header "Books"))) (org-ql-block '(and (todo "DONE") (level 1) (tags "phdthesis")) ((org-ql-block-header "Phd Thesis"))) (org-ql-block '(and (todo "DONE") (level 1) (not (tags "article" "inproceedings" "techreport" "inbook" "book" "phdthesis"))) ((org-ql-block-header "Other Things")))) ((org-agenda-files '("~/Cloud/brain/")))) ("r" "Articles and Books to read" ((org-ql-block '(and (todo "READ") (level 1) (tags "article" "inproceedings" "techreport" "inbook")) ((org-ql-block-header "Article to Read"))) (org-ql-block '(and (todo "READ") (level 1) (tags "book")) ((org-ql-block-header "Books to Read"))) (org-ql-block '(and (todo "READ") (level 1) (tags "phdthesis")) ((org-ql-block-header "Phd Thesis to Read"))) (org-ql-block '(and (todo "READ") (level 1) (not (tags "article" "inproceedings" "techreport" "inbook" "book" "phdthesis"))) ((org-ql-block-header "Other Things to Read")))) ((org-agenda-files '("~/Cloud/brain/"))))) ) ) </pre> </div> </div> </div> <div id="outline-container-org0b832f0" class="outline-3"> <h3 id="org0b832f0">Org Fancy Priority</h3> <div class="outline-text-3" id="text-org0b832f0"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! org-fancy-priorities ; priority icons :hook (org-mode . org-fancy-priorities-mode) :config (setq org-fancy-priorities-list '("■" "■" "■"))) </pre> </div> </div> </div> <div id="outline-container-orgb9fc96d" class="outline-3"> <h3 id="orgb9fc96d">Org Notification based on calendar event</h3> <div class="outline-text-3" id="text-orgb9fc96d"> <p> <a href="https://emacs.stackexchange.com/questions/3844/good-methods-for-setting-up-alarms-audio-visual-triggered-by-org-mode-events">https://emacs.stackexchange.com/questions/3844/good-methods-for-setting-up-alarms-audio-visual-triggered-by-org-mode-events</a> </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org-agenda (setq appt-message-warning-time 5) (defun tdh-org-agenda-to-appt () (interactive) (setq appt-time-msg-list nil) (org-agenda-to-appt)) (tdh-org-agenda-to-appt) ; Display appointments as a window manager notification (setq appt-disp-window-function 'tdh-appt-display) (setq appt-delete-window-function (lambda () t)) (setq tdh-appt-notification-app (concat (getenv "HOME") "/bin/appt-notification")) (defun tdh-appt-display (min-to-app new-time msg) (if (atom min-to-app) (start-process "tdh-appt-notification-app" nil tdh-appt-notification-app min-to-app msg) (dolist (i (number-sequence 0 (1- (length min-to-app)))) (start-process "tdh-appt-notification-app" nil tdh-appt-notification-app (nth i min-to-app) (nth i msg))))) ) </pre> </div> </div> <div id="outline-container-org1199365" class="outline-4"> <h4 id="org1199365">appt-notification script</h4> <div class="outline-text-4" id="text-org1199365"> <div class="org-src-container"> <pre class="src src-bash">TIME="$1"TODO MSG="$2" dunstify --replace=85401 "Event in $TIME minutes" "$MSG" </pre> </div> </div> </div> </div> <div id="outline-container-org3c5e1f3" class="outline-3"> <h3 id="org3c5e1f3">Org Structure Template</h3> <div class="outline-text-3" id="text-org3c5e1f3"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-structure-template-alist '(("c" . "center") ("C" . "comment") ("m" . "src matlab\n") ("l" . "src emacs-lisp\n") ("i" . "important") ("e" . "example") ("q" . "quote") ("s" . "src"))) ) </pre> </div> </div> </div> <div id="outline-container-org9713b96" class="outline-3"> <h3 id="org9713b96">Org Capture</h3> <div class="outline-text-3" id="text-org9713b96"> <p> Documentation: </p> <ul class="org-ul"> <li>Template elements: <a href="https://orgmode.org/manual/Template-elements.html#Template-elements">https://orgmode.org/manual/Template-elements.html#Template-elements</a></li> <li>Template expansion: <a href="https://orgmode.org/manual/Template-expansion.html#Template-expansion">https://orgmode.org/manual/Template-expansion.html#Template-expansion</a></li> <li>Capture protocol: <a href="https://orgmode.org/manual/capture-protocol.html">https://orgmode.org/manual/capture-protocol.html</a></li> </ul> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-capture-templates (quote (("t" ; key "todo" ; name entry ; type (file+headline "~/Cloud/org/work-notebook.org" "Inbox") ; target "** TODO %?\n%U\n" ; template ) ("M" ; key "Meeting" ; name entry ; type (file+headline "~/Cloud/org/work-notebook.org" "Meetings") ; target "** %?\n%(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n" ; template ) ("m" ; key "mail" ; name entry ; type (file+headline "~/Cloud/org/work-notebook.org" "Mails") ; target "** TODO [#A] %?\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n%a\n" ; template ) ("pm" "Org-Protocol Mail" entry (file+headline "~/Cloud/org/work-notebook.org" "Mails") "* MAIL %:description [[message:%:link][link]]\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n\n" :immediate-finish t ) ("pu" "Org-Protocol Url" entry (file+headline "~/Cloud/org/work-notebook.org" "Inbox") "* [[%:link][%:description]]\nCaptured On: %U\n\n" :immediate-finish t ) ("pt" "Org-Protocol text" entry (file+headline "~/Cloud/org/work-notebook.org" "Inbox") "* %:description\nSource: %:link\nCaptured On: %U\n\n#+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n" :immediate-finish t ) ))) ) </pre> </div> </div> </div> <div id="outline-container-org839d7a9" class="outline-3"> <h3 id="org839d7a9">Org Export</h3> <div class="outline-text-3" id="text-org839d7a9"> <p> Basic configuration: </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org ;; How many levels of headline to export (setq org-export-headline-levels 4) ;; Authorize BIND to set local variables (setq org-export-allow-bind-keywords t) ;; Use doc instead of odt (setq org-odt-preferred-output-format "doc") ) </pre> </div> <p> Some defaults: </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-export-with-author t) (setq org-export-with-creator nil) (setq org-export-with-date t) (setq org-export-with-toc t) (setq org-export-with-drawers nil) (setq org-export-with-sub-superscripts nil) (setq org-export-with-todo-keywords nil) ) </pre> </div> <p> Do not export headline with the <code>:ignore:</code> tag: </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">;; Used to not export headings with :ignore: tag (after! org (require 'ox-extra) (ox-extras-activate '(ignore-headlines))) </pre> </div> </div> </div> <div id="outline-container-org253b1f3" class="outline-3"> <h3 id="org253b1f3">HTML Export</h3> <div class="outline-text-3" id="text-org253b1f3"> </div> <div id="outline-container-orge413ce2" class="outline-4"> <h4 id="orge413ce2">HTML Defaults</h4> <div class="outline-text-4" id="text-orge413ce2"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org ;; (setq org-html-head-extra (concat ;; "<link rel='stylesheet' href='../css/htmlize.css'>\n" ;; "<link rel='stylesheet' href='../css/readtheorg.css'>\n" ;; "<link rel='stylesheet' href='../css/zenburn.css'>\n" ;; "<link rel='text/javascript' href='../js/bootstrap.min.js'>\n" ;; "<link rel='text/javascript' href='../js/jquery.min.js'>\n" ;; "<link rel='text/javascript' href='../js/jquery.stickytableheaders.min.js'>\n" ;; "<link rel='text/javascript' href='../js/readtheorg.js'>\n")) ;; cleans up anything that would have been in there. (setq org-html-head nil) (setq org-html-head-include-default-style nil) (setq org-html-head-include-scripts nil) (setq org-html-viewport nil) (setq org-html-html5-fancy t) (setq org-html-doctype "xhtml-strict") (setq org-html-wrap-src-lines nil) ;; Export with css class instead of inline css (setq org-html-htmlize-output-type 'nil) ) </pre> </div> </div> </div> <div id="outline-container-orgfe81dca" class="outline-4"> <h4 id="orgfe81dca">MathJax</h4> <div class="outline-text-4" id="text-orgfe81dca"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-html-mathjax-template "<script>MathJax = { tex: { tags: 'ams', macros: {bm: [\"\\\\boldsymbol{#1}\",1],} } }; </script> <script type=\"text/javascript\" src=\"%PATH\"></script>") (setq org-html-mathjax-options '((path "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js") (scale "100") (align "center") (font "TeX") (linebreaks "false") (autonumber "AMS") (indent "0em") (multlinewidth "85%") (tagindent ".8em") (tagside "right"))) ) </pre> </div> </div> </div> <div id="outline-container-orgbaa8390" class="outline-4"> <h4 id="orgbaa8390">Ensuring useful HTML Anchors</h4> <div class="outline-text-4" id="text-orgbaa8390"> <ul class="org-ul"> <li class="off"><code>[ ]</code> <a href="https://github.com/alhassy/emacs.d">https://github.com/alhassy/emacs.d</a></li> <li class="off"><code>[ ]</code> <a href="https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors">https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors</a></li> </ul> <p> This is not working </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(define-minor-mode unpackaged/org-export-html-with-useful-ids-mode "Attempt to export Org as HTML with useful link IDs. Instead of random IDs like \"#orga1b2c3\", use heading titles, made unique when necessary." :global t (if unpackaged/org-export-html-with-useful-ids-mode (advice-add #'org-export-get-reference :override #'unpackaged/org-export-get-reference) (advice-remove #'org-export-get-reference #'unpackaged/org-export-get-reference))) (defun unpackaged/org-export-get-reference (datum info) "Like `org-export-get-reference', except uses heading titles instead of random numbers." (let ((cache (plist-get info :internal-references))) (or (car (rassq datum cache)) (let* ((crossrefs (plist-get info :crossrefs)) (cells (org-export-search-cells datum)) ;; Preserve any pre-existing association between ;; a search cell and a reference, i.e., when some ;; previously published document referenced a location ;; within current file (see ;; `org-publish-resolve-external-link'). ;; ;; However, there is no guarantee that search cells are ;; unique, e.g., there might be duplicate custom ID or ;; two headings with the same title in the file. ;; ;; As a consequence, before re-using any reference to ;; an element or object, we check that it doesn't refer ;; to a previous element or object. (new (or (cl-some (lambda (cell) (let ((stored (cdr (assoc cell crossrefs)))) (when stored (let ((old (org-export-format-reference stored))) (and (not (assoc old cache)) stored))))) cells) (when (org-element-property :raw-value datum) ;; Heading with a title (unpackaged/org-export-new-title-reference datum cache)) ;; NOTE: This probably breaks some Org Export ;; feature, but if it does what I need, fine. (org-export-format-reference (org-export-new-reference cache)))) (reference-string new)) ;; Cache contains both data already associated to ;; a reference and in-use internal references, so as to make ;; unique references. (dolist (cell cells) (push (cons cell new) cache)) ;; Retain a direct association between reference string and ;; DATUM since (1) not every object or element can be given ;; a search cell (2) it permits quick lookup. (push (cons reference-string datum) cache) (plist-put info :internal-references cache) reference-string)))) (defun unpackaged/org-export-new-title-reference (datum cache) "Return new reference for DATUM that is unique in CACHE." (cl-macrolet ((inc-suffixf (place) `(progn (string-match (rx bos (minimal-match (group (1+ anything))) (optional "--" (group (1+ digit))) eos) ,place) ;; HACK: `s1' instead of a gensym. (-let* (((s1 suffix) (list (match-string 1 ,place) (match-string 2 ,place))) (suffix (if suffix (string-to-number suffix) 0))) (setf ,place (format "%s--%s" s1 (cl-incf suffix))))))) (let* ((title (org-element-property :raw-value datum)) (ref (url-hexify-string (substring-no-properties title))) (parent (org-element-property :parent datum))) (while (--any (equal ref (car it)) cache) ;; Title not unique: make it so. (if parent ;; Append ancestor title. (setf title (concat (org-element-property :raw-value parent) "--" title) ref (url-hexify-string (substring-no-properties title)) parent (org-element-property :parent parent)) ;; No more ancestors: add and increment a number. (inc-suffixf ref))) ref))) </pre> </div> </div> </div> <div id="outline-container-orged04965" class="outline-4"> <h4 id="orged04965">Folded Drawers</h4> <div class="outline-text-4" id="text-orged04965"> <p> Adapt this from <a href="https://github.com/alhassy/emacs.d">https://github.com/alhassy/emacs.d</a> to do something similar for source blocks. </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun my/org-drawer-format (name contents) "Export to HTML the drawers named with prefix ‘fold_’, ignoring case. The resulting drawer is a ‘code-details’ and so appears folded; the user clicks it to see the information therein. Henceforth, these are called ‘fold drawers’. Drawers without such a prefix may be nonetheless exported if their body contains ‘:export: t’ ---this switch does not appear in the output. Thus, we are biased to generally not exporting non-fold drawers. One may suspend export of fold drawers by having ‘:export: nil’ in their body definition. Fold drawers naturally come with a title. Either it is specfied in the drawer body by ‘:title: ⋯’, or otherwise the drawer's name is used with all underscores replaced by spaces. " (let* ((contents′ (replace-regexp-in-string ":export:.*\n?" "" contents)) (fold? (s-prefix? "fold_" name 'ignore-case)) (export? (string-match ":export:\s+t" contents)) (not-export? (string-match ":export:\s+nil" contents)) (title′ (and (string-match ":title:\\(.*\\)\n" contents) (match-string 1 contents)))) ;; Ensure we have a title. (unless title′ (setq title′ (s-join " " (cdr (s-split "_" name))))) ;; Output (cond ((and export? (not fold?)) contents′) (not-export? nil) (fold? (thread-last contents′ (replace-regexp-in-string ":title:.*\n" "") (format "<details class=\"code-details\"> <summary> <strong> <font face=\"Courier\" size=\"3\" color=\"green\"> %s </font> </strong> </summary> %s </details>" title′)))))) (setq org-html-format-drawer-function 'my/org-drawer-format) </pre> </div> </div> </div> </div> <div id="outline-container-org1a43ae2" class="outline-3"> <h3 id="org1a43ae2">Org LaTeX</h3> <div class="outline-text-3" id="text-org1a43ae2"> </div> <div id="outline-container-org3a04c02" class="outline-4"> <h4 id="org3a04c02">LaTeX Fragments</h4> <div class="outline-text-4" id="text-org3a04c02"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org ;; Highligh latex parts in org mode (setq org-highlight-latex-and-related '(latex script entities)) ;; Use F9 to globally generate all the latex fragments (map! :map org-mode-map :n "<f9>" (lambda () (interactive) (org-preview-latex-fragment 16))) ;; Put all the preview images in some directory (setq org-preview-latex-image-directory "~/.ltximg/") ;; Define backends to preview LaTeX fragments (setq org-preview-latex-process-alist '((imagemagick :programs ("pdflatex" "convert") :description "pdf > png" :message "you need to install the programs: pdflatex and imagemagick." :image-input-type "pdf" :image-output-type "png" :image-size-adjust (1.0 . 1.0) :latex-compiler ("pdflatex -interaction nonstopmode -output-directory %o %f") :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O")) (dvipng :programs ("latex" "dvipng") :description "dvi > png" :message "you need to install the programs: latex and dvipng." :image-input-type "dvi" :image-output-type "png" :image-size-adjust (0.4 . 0.4) :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f") :image-converter ("dvipng -D %D -T tight -o %O %f")) (dvisvgm :programs ("pdflatex" "dvisvgm") :description "dvi > svg" :message "you need to install the programs: latex and dvisvgm." :image-input-type "dvi" :image-output-type "svg" :image-size-adjust (0.6 . 0.6) :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f") :image-converter ("dvisvgm %f -n -b min -c %S -o %O")) )) ;; Use imagemagick/dvisvgm to generate png from pdf (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 (face-background 'fringe))) ) </pre> </div> </div> </div> <div id="outline-container-orgaa26736" class="outline-4"> <h4 id="orgaa26736">LaTeX Classes</h4> <div class="outline-text-4" id="text-orgaa26736"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org ;; Custom classes to use when exporting to latex (add-to-list 'org-latex-classes '("beamer" ,(concat "\\documentclass[presentation]{beamer}\n" "[DEFAULT-PACKAGES]" "[PACKAGES]" "[EXTRA]\n") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))) (add-to-list 'org-latex-classes '("clean-cheatsheet" "\\documentclass{clean-cheatsheet}" ("\\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 '("clean-beamer" "\\documentclass{clean-beamer}" ("\\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 '("cleanreport" "\\documentclass{cleanreport}" ("\\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 '("scrreprt" "\\documentclass{scrreprt}" ("\\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 '("biblioreport" "\\documentclass{biblioreport}" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}")) ) ) </pre> </div> </div> </div> <div id="outline-container-org3480957" class="outline-4"> <h4 id="org3480957">Ox Latex Subfigure package</h4> <div class="outline-text-4" id="text-org3480957"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! ox-latex-subfigure :after org :config (require 'ox-latex-subfigure)) </pre> </div> </div> </div> <div id="outline-container-org44cf309" class="outline-4"> <h4 id="org44cf309">Clear page before heading</h4> <div class="outline-text-4" id="text-org44cf309"> <p> <a href="https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-heading/30892">https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-heading/30892</a> </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (defun tdh-get-headline-string-element (headline backend info) (let ((prop-point (next-property-change 0 headline))) (if prop-point (plist-get (text-properties-at prop-point headline) :parent)))) (defun tdh-ensure-latex-clearpage (headline backend info) (when (org-export-derived-backend-p backend 'latex) (let ((elmnt (tdh-get-headline-string-element headline backend info))) (when (and elmnt (org-element-property :CLEARPAGE elmnt)) (concat "\\clearpage\n" headline))))) (add-to-list 'org-export-filter-headline-functions 'tdh-ensure-latex-clearpage) ) </pre> </div> </div> </div> <div id="outline-container-org3b03fac" class="outline-4"> <h4 id="org3b03fac">Default added packages</h4> <div class="outline-text-4" id="text-org3b03fac"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (add-to-list 'org-latex-packages-alist '("" "siunitx" t)) (add-to-list 'org-latex-packages-alist '("" "array" t)) (add-to-list 'org-latex-packages-alist '("" "tabularx" t)) (add-to-list 'org-latex-packages-alist '("" "booktabs" t)) (add-to-list 'org-latex-packages-alist '("" "bm" t)) (add-to-list 'org-latex-packages-alist '("most" "tcolorbox" t)) ) </pre> </div> </div> </div> <div id="outline-container-org3b79603" class="outline-4"> <h4 id="org3b79603">Some configurations</h4> <div class="outline-text-4" id="text-org3b79603"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org ;; Setup default option for image size when exporting to LaTeX (setq org-latex-image-default-scale "") (setq org-latex-image-default-width "\\linewidth") (setq org-latex-image-default-height "") (setq org-latex-image-default-option "") ;; Use define labels instead of automatic generated ones (setq org-latex-prefer-user-labels t) ;; Captions above the table (setq org-latex-caption-above '(table)) ;; Settings to export code with `minted' instead of `verbatim'. (setq org-latex-listings 'minted) ;; Set the following as images (setq org-latex-inline-image-rules '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\|tikz\\|pgf\\|svg\\|gif\\)\\'"))) ;; Command used when exporting to pdf (setq org-latex-pdf-process '("latexmk -cd -pdflatex=\"pdflatex -synctex=1 -shell-escape -interaction nonstopmode -output-directory %o\" -pdf -bibtex -f %f")) ) </pre> </div> </div> </div> <div id="outline-container-orgce10c33" class="outline-4"> <h4 id="orgce10c33">Beamer</h4> <div class="outline-text-4" id="text-orgce10c33"> <p> Bold Text </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (defun tdh-my-beamer-bold (contents backend info) (when (eq backend 'beamer) (replace-regexp-in-string (concat "\\`\\\\" "[A-Za-z0-9]+") ;; If not, orgmode is crazy... "\\\\textbf" contents))) (add-to-list 'org-export-filter-bold-functions 'tdh-my-beamer-bold) ) </pre> </div> <p> Special Environments </p> <ul class="org-ul"> <li class="off"><code>[ ]</code> Make some comment those special environments</li> </ul> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (add-to-list 'org-beamer-environments-extra '("cbox" ;; Name of environment "m" ;; Selection key "\\onslide%a{\\begin{cbox}[%h]%O" "\\end{cbox}}\\vspace{0.5em}")) (add-to-list 'org-beamer-environments-extra '("csubbox" ;; Name of environment "M" ;; Selection key "\\onslide%a{\\tcbsubtitle{%h}" "}")) ) </pre> </div> </div> </div> <div id="outline-container-org7d55947" class="outline-4"> <h4 id="org7d55947">Custom Export - Add Page and Label for LaTeX export</h4> <div class="outline-text-4" id="text-org7d55947"> <p> <a href="https://emacs.stackexchange.com/questions/156/emacs-function-to-convert-an-arbitrary-org-property-into-an-arbitrary-string-na?rq=1">https://emacs.stackexchange.com/questions/156/emacs-function-to-convert-an-arbitrary-org-property-into-an-arbitrary-string-na?rq=1</a> </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defcustom tdh-org-property-mapping '((latex ("CUSTOM_PAGE" . tdh-insert-org-page-latex) ("CUSTOM_LABEL" . tdh-insert-org-label-latex))) "List of mappings from org property to arbitrary strings. Each element is a list: (BACKEND (PROPERTY1 . FUNCTION1) (PROPERTY2 . FUNCTION2) ...) FUNCTION are functions which get called with a single argument (the value of PROPERTY) and are responsible for doing whatever should be done." :type '(repeat (cons symbol (repeat (cons string string))))) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-replace-org-property (backend) "Convert org properties using `tdh-org-property-mapping'. Lookup BACKEND in `tdh-org-property-mapping' for a list of (PROPERTY REPLACEMENT). For each healine being exported, if it has a PROPERTY listed insert a string immediately after the healine given by (format REPLACEMENT PROPERTY-VALUE)" (let ((map (cdr (assoc backend tdh-org-property-mapping))) value replacement) (when map (org-map-entries (lambda () (dolist (it map) (save-excursion (when (setq value (org-entry-get (point) (car it))) (funcall (cdr it) value))))))))) (add-hook 'org-export-before-processing-hook #'tdh-replace-org-property) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-org-label-latex (label) "Insert \"\\\\label{LABEL}\\n\" after the :PROPERTY: drawer." (search-forward-regexp org-property-end-re) (forward-char 1) (insert (format "\\label{%s}\n" label))) (defun tdh-insert-org-page-latex (page) "Insert \"\\\\page{PAGE}\\n\" after the :PROPERTY: drawer." (search-forward-regexp org-property-end-re) (forward-char 1) (insert (format "\\page{%s}\n" page))) </pre> </div> </div> </div> <div id="outline-container-org9d2764e" class="outline-4"> <h4 id="org9d2764e">Number Equations</h4> <div class="outline-text-4" id="text-org9d2764e"> <p> <a href="https://kitchingroup.cheme.cmu.edu/blog/2016/11/07/Better-equation-numbering-in-LaTeX-fragments-in-org-mode/">https://kitchingroup.cheme.cmu.edu/blog/2016/11/07/Better-equation-numbering-in-LaTeX-fragments-in-org-mode/</a> </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (defun tdh-org-renumber-environment (orig-func &rest args) "A function to inject numbers in LaTeX fragment previews." (let ((results '()) (counter -1) (numberp)) (setq results (loop for (begin . env) in (org-element-map (org-element-parse-buffer) 'latex-environment (lambda (env) (cons (org-element-property :begin env) (org-element-property :value env)))) collect (cond ((and (string-match "\\\\begin{equation}" env) (not (string-match "\\\\tag{" env))) (incf counter) (cons begin counter)) ((string-match "\\\\begin{align}" env) (prog2 (incf counter) (cons begin counter) (with-temp-buffer (insert env) (goto-char (point-min)) ;; \\ is used for a new line. Each one leads to a number (incf counter (count-matches "\\\\$")) ;; unless there are nonumbers. (goto-char (point-min)) (decf counter (count-matches "\\nonumber"))))) (t (cons begin nil))))) (when (setq numberp (cdr (assoc (point) results))) (setf (car args) (concat (format "\\setcounter{equation}{%s}\n" numberp) (car args))))) (apply orig-func args)) (advice-add 'org-create-formula-image :around #'tdh-org-renumber-environment) ) </pre> </div> </div> </div> </div> <div id="outline-container-org5236d09" class="outline-3"> <h3 id="org5236d09">LaTeX macro both for LaTeX and HTML export</h3> <div class="outline-text-3" id="text-org5236d09"> <p> <a href="https://www.reddit.com/r/orgmode/comments/7u2n0h/tip_for_defining_latex_macros_for_use_in_both/">https://www.reddit.com/r/orgmode/comments/7u2n0h/tip_for_defining_latex_macros_for_use_in_both/</a> </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (add-to-list 'org-src-lang-modes '("latex-macros" . latex)) (defvar org-babel-default-header-args:latex-macros '((:results . "raw") (:exports . "results"))) (defun prefix-all-lines (pre body) (with-temp-buffer (insert body) (string-insert-rectangle (point-min) (point-max) pre) (buffer-string))) (defun org-babel-execute:latex-macros (body _params) (concat "\n#+begin_export html\n<div style=\"display: none\"> \\(\n" body "\n\\)</div>\n#+end_export\n")) ) </pre> </div> </div> </div> <div id="outline-container-org51ce4d3" class="outline-3"> <h3 id="org51ce4d3">Org Projects</h3> <div class="outline-text-3" id="text-org51ce4d3"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq org-publish-project-alist '(("config" :base-directory "~/.config/literate-dotfiles/dotfiles/" :publishing-directory "~/.config/literate-dotfiles/docs/" :recursive nil :publishing-function org-html-publish-to-html :auto-sitemap nil :section-numbers nil :table-of-contents nil) ("stewart-simscape" :base-directory "~/Cloud/thesis/matlab/stewart-simscape/org/" :base-extension "org" :publishing-directory "~/Cloud/thesis/matlab/stewart-simscape/docs/" :author "Dehaeze Thomas" :email "dehaeze.thomas@gmail.com/" :recursive nil :publishing-function org-html-publish-to-html :auto-preamble t :auto-sitemap nil :html-link-up "index.html" :html-link-home "index.html" :with-todo-keywords nil :html-wrap-src-lines nil :table-of-contents nil) ("nass-simscape" :base-directory "~/Cloud/thesis/matlab/nass-simscape/org/" :base-extension "org" :publishing-directory "~/Cloud/thesis/matlab/nass-simscape/docs/" :author "Dehaeze Thomas" :email "dehaeze.thomas@gmail.com/" :recursive nil :publishing-function org-html-publish-to-html :auto-preamble t :auto-sitemap nil :html-link-up "index.html" :html-link-home "index.html" :with-todo-keywords nil :html-wrap-src-lines nil :table-of-contents nil) ("tikz-maker" :base-directory "~/Cloud/tikz/org/" :base-extension "org" :publishing-directory "~/Cloud/tikz/docs/" :author "Dehaeze Thomas" :email "dehaeze.thomas@gmail.com/" :recursive nil :publishing-function org-html-publish-to-html :auto-preamble t :auto-sitemap nil :html-link-up "index.html" :html-link-home "index.html" :with-todo-keywords nil :html-wrap-src-lines nil :table-of-contents nil))) </pre> </div> </div> </div> <div id="outline-container-orgf5cfaee" class="outline-3"> <h3 id="orgf5cfaee">Org big org-project</h3> <div class="outline-text-3" id="text-orgf5cfaee"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq org-publish-project-alist '(("website" :components ("nass-simscape" "nass-simscape-images")) ("nass-simscape" :base-directory "~/Cloud/thesis/matlab/nass-simscape/org/" :base-extension "org" :publishing-directory "~/Cloud/website/nass-simscape/" :publishing-function org-html-publish-to-html :html-link-up "./index.html" :html-link-home "~/Cloud/website/index.html" :html-footnotes-section "<div id='footnotes'><!--%s-->%s</div>" :recursive nil :auto-sitemap nil :language en) ("nass-simscape-images" :base-directory "~/Cloud/thesis/matlab/nass-simscape/docs/figs/" :base-extension "png" :publishing-directory "~/Cloud/website/nass-simscape/figs/" :publishing-function org-publish-attachment) )) </pre> </div> </div> </div> <div id="outline-container-org0a79d9f" class="outline-3"> <h3 id="org0a79d9f">Automatically run <code>startblock</code> when opening org-mode files</h3> <div class="outline-text-3" id="text-org0a79d9f"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (defun tdh-eval-startblock () (if (member "startblock" (org-babel-src-block-names)) (save-excursion (org-babel-goto-named-src-block "startblock") (org-babel-execute-src-block)) nil ) ) (add-hook 'org-mode-hook 'tdh-eval-startblock) ) </pre> </div> </div> </div> <div id="outline-container-orga1fc443" class="outline-3"> <h3 id="orga1fc443">Insert ScreenShot or Picture from Phone</h3> <div class="outline-text-3" id="text-orga1fc443"> <p> <a href="http://pragmaticemacs.com/emacs/a-workflow-to-quickly-add-photos-to-org-mode-notes/">http://pragmaticemacs.com/emacs/a-workflow-to-quickly-add-photos-to-org-mode-notes/</a> </p> <ul class="org-ul"> <li class="off"><code>[ ]</code> One function to move file from <code>~/Picture/</code> folder (where the screenshots are taken) to current directory and then insert and org link to the picture. Maybe ask if it should be copied in a sub directory (figs folder for instance).</li> <li class="off"><code>[ ]</code> One function to copy file from <code>~/Cloud/Photos/</code> folder (where the pictures from phone are taken) to current directory (and ask for the new name of the picture) and insert org link.</li> </ul> <div class="org-src-container"> <pre class="src src-emacs-lisp">;; required libraries (require 'dash) ;; (require 'swiper) (require 's) ;; start directory (defvar tdh-image-dir (expand-file-name "/home/thomas/Pictures")) (defun tdh-insert-conference-image () "Insert image from conference directory, rename and add link in current file. The file is taken from a start directory set by `tdh-image-dir' and moved to the current directory, renamed and embedded at the point as an org-mode link. The user is presented with a list of files in the start directory, from which to select the file to move, sorted by most recent first." (interactive) (let (file-list target-dir file-list-sorted start-file start-file-full file-ext end-file end-file-base end-file-full file-number) ;; Clean directories from list but keep times (setq file-list (-remove (lambda (x) (nth 1 x)) (directory-files-and-attributes tdh-image-dir))) ;; Get target directory (setq target-dir (file-name-directory (buffer-file-name))) ;; Sort list by most recent (setq file-list-sorted (mapcar #'car (sort file-list #'(lambda (x y) (time-less-p (nth 6 y) (nth 6 x)))))) ;; Use ivy to select start-file (setq start-file (ivy-read (concat "Move selected file to " target-dir ":") file-list-sorted :re-builder #'ivy--regex :sort nil :initial-input nil)) ;; add full path to start file and end-file (setq start-file-full (expand-file-name start-file tdh-image-dir)) ;; final file name including path (setq end-file-full (expand-file-name start-file target-dir)) ;; rename file (rename-file start-file-full end-file-full) (message "moved %s to %s" start-file-full start-file) ;; insert link (insert (org-make-link-string (format "file:%s" start-file))) ;; display image (org-display-inline-images t t))) </pre> </div> </div> </div> <div id="outline-container-org7902aff" class="outline-3"> <h3 id="org7902aff">Render Tables</h3> <div class="outline-text-3" id="text-org7902aff"> <p> <a href="https://www.reddit.com/r/emacs/comments/d3a8or/pretty_org_tables_in_the_buffer_chapter_2_it/">https://www.reddit.com/r/emacs/comments/d3a8or/pretty_org_tables_in_the_buffer_chapter_2_it/</a> </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (defun tdh-render-org-table-at-point () (interactive) (save-excursion (beginning-of-line) ;; removes the overlay is already there (if (overlays-at (point)) (delete-overlay (car (overlays-at (point)))) (let* ((element-type (org-element-type (org-element-at-point)))) (if (and (not (eq element-type 'table)) (not (eq element-type 'table-row))) (error "not at an org table") (while (not (eq 'table (org-element-type (org-element-at-point)))) (forward-line -1)) (tdh-render-org-table (org-element-at-point)) ))))) (defun tdh-render-org-table (table) (interactive) (let* ((begin (org-element-property :begin table)) (end (let ((pos (org-element-property :end table))) (goto-char pos) (beginning-of-line) ;; skip possible space after table (while (not (looking-at " *[|#]")) (setq pos (point)) (forward-line -1)) pos)) (tabletxt (buffer-substring-no-properties begin end)) (img (with-temp-buffer (insert tabletxt) (mark-whole-buffer) (org-latex-convert-region-to-latex) (org-latex-preview) (goto-char (point-min)) (overlay-get (car (overlays-at (point))) 'display))) (overlay (make-overlay begin end))) (overlay-put overlay 'display img) (forward-line -1)) ) (defun tdh-render-org-tables-in-buffer () (save-excursion (org-element-map (org-element-parse-buffer) 'table 'tdh-render-org-table))) ;; Use F9 to globally generate tables (map! :map org-mode-map :n "<f8>" (lambda () (interactive) (tdh-render-org-table-at-point))) ) </pre> </div> </div> </div> <div id="outline-container-org66f0a8a" class="outline-3"> <h3 id="org66f0a8a">Org Gcal</h3> <div class="outline-text-3" id="text-org66f0a8a"> <ul class="org-ul"> <li><a href="https://cestlaz.github.io/posts/using-emacs-26-gcal/#.WIqBud9vGAk">https://cestlaz.github.io/posts/using-emacs-26-gcal/#.WIqBud9vGAk</a></li> </ul> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! org-gcal :after org :init :config (setq org-gcal-client-id "396102378658-dcmbcmrnthbe925519otsjbd921otq0v.apps.googleusercontent.com" org-gcal-client-secret "4M5PWrbhQjwYEMXGK85lDYX9" org-gcal-file-alist '(("dehaeze.thomas@gmail.com" . "~/Cloud/org/gcal.org") ("8kjmhe2ar0abnm054ill1fb0gc@group.calendar.google.com" . "~/Cloud/org/gcal_phd.org"))) ;; Automatic fetch of the new events ;; (add-hook 'org-agenda-mode-hook (lambda () (org-gcal-fetch) )) ) </pre> </div> </div> </div> <div id="outline-container-orgafe7963" class="outline-3"> <h3 id="orgafe7963">Custom Keybindings - <code>,</code> leader key and <code>C-c</code></h3> <div class="outline-text-3" id="text-orgafe7963"> <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left" /> <col class="org-left" /> </colgroup> <thead> <tr> <th scope="col" class="org-left"> </th> <th scope="col" class="org-left"> </th> </tr> </thead> <tbody> <tr> <td class="org-left"><code>C-c a</code></td> <td class="org-left">Org Agenda</td> </tr> <tr> <td class="org-left"><code>C-c n</code></td> <td class="org-left">Narrow to Subtree</td> </tr> <tr> <td class="org-left"><code>C-c l</code></td> <td class="org-left">Org Link</td> </tr> </tbody> </table> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (map! :map org-mode-map (:desc "Org Agenda" :ni "C-c a" 'org-agenda) (:desc "Archive" :n "C-c A" 'org-archive-subtree) (:desc "Org Capture" :ni "C-c c" 'org-capture) (:desc "Store Link" :ni "C-c l" 'org-store-link) (:desc "Narrow Subtree" :ni "C-c n" 'org-toggle-narrow-to-subtree) (:desc "Org Noter" :ni "C-c N" 'org-noter) (:desc "Align Block" :ni "C-c =" 'tdh-align-src-block) (:desc "Insert Reference" :ni "C-c r" 'org-ref-insert-ref-link) (:desc "Insert Image" :ni "C-c i" 'tdh-insert-image-org-link) (:desc "Insert Image SXIV" :ni "C-c I" 'tdh-insert-image-org-link-sxiv) (:desc "Link to next Figure" :ni "C-c f" 'tdh-insert-link-to-next-figure) (:desc "Link to previous Figure" :ni "C-c F" 'tdh-insert-link-to-previous-figure) (:desc "Insert Screenshot" :ni "C-c s" 'tdh-insert-screenshot-org-link) (:desc "Find Roam" :ni "C-c r" 'orb-find-non-ref-file) (:desc "Insert Roam" :ni "C-c R" 'orb-insert-non-ref) )) </pre> </div> </div> <div id="outline-container-orgdc0a145" class="outline-4"> <h4 id="orgdc0a145">Insert Elements <code>,i</code></h4> <div class="outline-text-4" id="text-orgdc0a145"> <p> Insert Link to paper </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-paper-org-link (paper) "Insert an org link to some paper, choosing the file with completion" (interactive (list (read-file-name "Paper: " "~/Cloud/pdfs/" nil t))) (insert (format "[[papers:%s]]" (file-name-base paper)))) </pre> </div> <p> Insert Link to notes </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-note-org-link (note) "Insert an org link to some note, choosing the file with completion" (interactive (list (read-file-name "Note: " "~/Cloud/pdfs/" nil t))) (insert (format "[[notes:%s]]" (file-name-base note)))) </pre> </div> <p> Insert Image that is in the figs folder </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-image-org-link (img) "Insert an org image link, choosing the file with completion and starting from `my-default-image-directory'." (interactive (list (file-relative-name (read-file-name "Image: " (concat default-directory "figs/")) default-directory))) (insert (format "[[file:%s]]" img))) </pre> </div> <p> Insert Image that is in the <code>figs</code> folder using SXIV </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-image-org-link-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'")) (unless (equal "" img) (insert (format "[[file:%s]]" img))) ) </pre> </div> <p> Copy picture from phone folder using SXIV and insert it </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-phone-picture () (interactive) (setq img (shell-command-to-string "~/.config/doom/bin/copy-phone-picture.sh")) (unless (equal "" img) (insert (format "[[file:%s]]" img))) ) </pre> </div> <p> Bash script for copying pictures taken by phone. </p> <div class="org-src-container"> <pre class="src src-bash">if [ -z "$1" ]; then oldpath=$(ls -t ~/Cloud/photos/phone/*.jpg | sxiv -i -t -o | tail -1); else oldpath=$(ls -t $1 | sxiv -i -t -o | tail -1); fi if [ -n "$oldpath" ]; then newfilename=$(basename $oldpath .jpg | rofi -i -dmenu -p "Filename") if [ -n "$newfilename" ]; then cp $oldpath "figs/$newfilename.jpg" printf "figs/$newfilename.jpg" fi fi </pre> </div> <p> Take Screenshot and insert a link: </p> <ul class="org-ul"> <li>Ask for a name <code>screenshot_name</code></li> <li>use <code>maim -s figs/screenshot_name.png</code> to take a screenshot with selection</li> <li>Then insert the following to the buffer</li> </ul> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-screenshot-org-link () "Capture screenshot and insert the resulting file. The screenshot tool is determined by `org-download-screenshot-method'." (interactive) (if (string-match "_" (file-name-base buffer-file-name)) (setq filename (read-string "Enter file name:" (car (split-string (file-name-base buffer-file-name) "_")))) (setq filename (read-string "Enter file name:"))) (setq filepath (concat "./figs/" filename ".png")) (shell-command (concat "maim -s " filepath)) (insert (format "#+name: fig:%s\n#+caption:\n[[file:%s]]" filename filepath)) (search-backward "caption") (end-of-line) ) </pre> </div> <p> Insert link to next figure: </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-link-to-next-figure () (interactive) (save-excursion (re-search-forward "^#\\+name:\s*\\(fig:.*\\)" nil t 1)) (insert (concat "[[" (match-string 1) "]]")) ) </pre> </div> <p> Insert link to previous figure: </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-link-to-previous-figure () (interactive) (save-excursion (re-search-backward "^#\\+name:\s*\\(fig:.*\\)" nil t 1)) (insert (concat "[[" (match-string 1) "]]")) ) </pre> </div> <p> Map Keys </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (map! :map org-mode-map (:prefix (",i" . "Insert") :n "p" 'tdh-insert-paper-org-link :n "n" 'tdh-insert-note-org-link :n "f" 'tdh-insert-image-org-link :n "F" 'tdh-insert-image-org-link-sxiv :n "i" 'tdh-insert-phone-picture :n "l" 'tdh-insert-link-to-next-figure :n "L" 'tdh-insert-link-to-previous-figure :n "s" 'tdh-insert-screenshot-org-link))) </pre> </div> </div> </div> <div id="outline-container-orgc62ba13" class="outline-4"> <h4 id="orgc62ba13">LaTeX <code>,l</code></h4> <div class="outline-text-4" id="text-orgc62ba13"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-latex-watch () "Watch LaTeX file using latexmk" (interactive) (start-process-shell-command "latexmk-watch" "*latexmk-watch-output*" "latexmk" (format "-pdflatex=\"xelatex -synctex=1 -shell-escape -interaction nonstopmode -output-directory='%s'\" -pdf -pvc -bibtex -f %s.tex" (file-name-directory buffer-file-name) (file-name-base buffer-file-name)))) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-latex-watch-kill () "Kill the currently running TeX job." (interactive) (delete-process "latexmk-watch") ) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (map! :map org-mode-map (:prefix (",l" . "LaTeX") :n "w" 'tdh-latex-watch :n "k" 'tdh-latex-watch-kill :n "l" 'org-latex-export-to-latex))) </pre> </div> </div> </div> <div id="outline-container-org0b5774e" class="outline-4"> <h4 id="org0b5774e">Org LaTeX Automatic fragment</h4> <div class="outline-text-4" id="text-org0b5774e"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-automatic-latex-fragment-activate () (interactive) (add-hook 'org-mode-hook 'org-fragtog-mode)) (defun tdh-automatic-latex-fragment-deactivate () (interactive) (remove-hook 'org-mode-hook 'org-fragtog-mode)) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (map! :map org-mode-map (:prefix (",l" . "LaTeX") :n "f" 'tdh-automatic-latex-fragment-activate :n "F" 'tdh-automatic-latex-fragment-deactivate))) </pre> </div> </div> </div> <div id="outline-container-orgee735c5" class="outline-4"> <h4 id="orgee735c5">Bibtex <code>,r</code></h4> <div class="outline-text-4" id="text-orgee735c5"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (map! :map org-mode-map (:prefix (",r" . "References") :n "b" 'helm-bibtex :n "B" 'helm-bibtex-with-local-bibliography :n "f" 'tdh-helm-bibtex-favorites :n "r" 'helm-resume))) </pre> </div> </div> </div> <div id="outline-container-org87d89c4" class="outline-4"> <h4 id="org87d89c4">Open ranger in current directory <code>,o</code></h4> <div class="outline-text-4" id="text-org87d89c4"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-open-ranger-in-workdir () (interactive) (call-process-shell-command (concat "termite --directory=" default-directory " --exec=ranger") nil 0)) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (map! :map org-mode-map :n ",o" 'tdh-open-ranger-in-workdir)) </pre> </div> </div> </div> <div id="outline-container-orgb7c8cca" class="outline-4"> <h4 id="orgb7c8cca">View in External programs <code>,v</code></h4> <div class="outline-text-4" id="text-orgb7c8cca"> <p> Open PDF output with <code>zathura</code> </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-open-org-pdf-externally () (interactive) (call-process "zathura" nil 0 nil (concat (file-name-sans-extension (buffer-file-name)) ".pdf")) ) </pre> </div> <p> Open HTML output externally </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-open-org-html-externally () (interactive) (call-process "xdg-open" nil 0 nil (concat (file-name-sans-extension (buffer-file-name)) ".html")) ) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (map! :map org-mode-map (:prefix (",v" . "View") :n "p" 'tdh-open-org-pdf-externally :n "h" 'tdh-open-org-html-externally))) </pre> </div> </div> </div> </div> </div> <div id="outline-container-org38a8163" class="outline-2"> <h2 id="org38a8163">Org Babel</h2> <div class="outline-text-2" id="text-org38a8163"> </div> <div id="outline-container-org97bf4fc" class="outline-3"> <h3 id="org97bf4fc">Main configuration</h3> <div class="outline-text-3" id="text-org97bf4fc"> <p> Don’t ask for confirmation when evaluating following blocs </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-org-confirm-babel-evaluate (lang body) (not (member lang '("emacs-lisp" "latex" "matlab" "sh" "latex-macros" "python")))) (after! org (setq org-confirm-babel-evaluate 'tdh-org-confirm-babel-evaluate)) </pre> </div> <p> Default header arguments. </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-babel-default-header-args '((:eval . "no-export")))) </pre> </div> <p> Use the current window for C-c ’ source editing </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-src-window-setup 'current-window)) </pre> </div> </div> </div> <div id="outline-container-org741956d" class="outline-3"> <h3 id="org741956d">Appearance of source blocks</h3> <div class="outline-text-3" id="text-org741956d"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-org-prettify-symbols () (mapc (apply-partially 'add-to-list 'prettify-symbols-alist) (cl-reduce 'append (mapcar (lambda (x) (list x (cons (upcase (car x)) (cdr x)))) `(("#+begin_src" . ?✎) ("#+end_src" . ?□) ("#+begin_quote" . ?«) ("#+end_quote" . ?»))))) (turn-on-prettify-symbols-mode)) (add-hook 'org-mode-hook #'tdh-org-prettify-symbols) </pre> </div> </div> </div> <div id="outline-container-org737e623" class="outline-3"> <h3 id="org737e623">Indentation</h3> <div class="outline-text-3" id="text-org737e623"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-edit-src-content-indentation 2 org-src-tab-acts-natively nil org-src-preserve-indentation nil) ) </pre> </div> </div> </div> <div id="outline-container-orgee4e789" class="outline-3"> <h3 id="orgee4e789">Library of Babel</h3> <div class="outline-text-3" id="text-orgee4e789"> <p> Add all named source blocks to <code>org-babel-library-of-babel</code> (<a href="emacs-library-babel.html">link</a>). </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (org-babel-lob-ingest "~/.config/literate-dotfiles/dotfiles/emacs-library-babel.org")) </pre> </div> </div> </div> <div id="outline-container-org232fea8" class="outline-3"> <h3 id="org232fea8">Org-Babel Matlab</h3> <div class="outline-text-3" id="text-org232fea8"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-babel-matlab-shell-command "/home/thomas/.local/bin/matlab -softwareopengl -nodesktop -nosplash") (setq org-babel-matlab-emacs-link-wrapper-method "%s if ischar(ans); echo('test'); fid = fopen('%s', 'w'); fprintf(fid, '%s', ans); fclose(fid); else; save -ascii %s ans; end delete('%s'); ") ) </pre> </div> <p> Default options for Matlab code </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (setq org-babel-default-header-args:matlab '((:results . "none") (:session . "*MATLAB*") (:comments . "org") (:exports . "both") (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "yes") (:mkdir . "yes") (:eval . "no-export"))) ) </pre> </div> </div> </div> <div id="outline-container-org80ca3ef" class="outline-3"> <h3 id="org80ca3ef">Some functions for using Matlab with Org Babel <code>,m</code></h3> <div class="outline-text-3" id="text-org80ca3ef"> <p> <code>whos</code> matlab function </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-matlab-whos (&optional start end) "Get what is in the Matlab workspace" (interactive) (if (use-region-p) (let ((regionp (buffer-substring (region-beginning) (region-end)))) (process-send-string "*MATLAB*" (concat "whosEmacs " regionp "\n"))) (process-send-string "*MATLAB*" (concat "whosEmacs" "\n")))) </pre> </div> <p> <code>help</code> matlab function </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-matlab-help (&optional start end) "Get help on the selected function" (interactive) (if (use-region-p) (let ((regionp (buffer-substring (region-beginning) (region-end)))) (process-send-string "*MATLAB*" (concat "help " regionp "\n"))) (process-send-string "*MATLAB*" (concat "help " (read-string "Matlab help:") "\n"))) ) </pre> </div> <p> Specify a Matlab command to run </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-matlab-run-command () "Prompt user to enter a matlab command" (interactive) (process-send-string "*MATLAB*" (concat (read-string "Matlab Command: ") "\n"))) </pre> </div> <p> Specify a Matlab command to run and show output in mini-buffer </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-matlab-run-command-show-output () "Prompt user to enter a matlab command" (interactive) (process-send-string "*MATLAB*" (concat "evalEmacs('" (read-string "Matlab Command: ") "')\n"))) </pre> </div> <p> Org-Babel Tangle File and Execute with Matlab </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-matlab-tangle-and-execute () "Jump to tangle file for the source block at point." (interactive) (let (file org-babel-pre-tangle-hook org-babel-post-tangle-hook) (cl-letf (((symbol-function 'write-region) (lambda (start end filename &rest _ignore) (setq file filename))) ((symbol-function 'delete-file) #'ignore)) (org-babel-tangle '(4))) (when file (setq file (expand-file-name file)) (if (file-readable-p file) (process-send-string "*MATLAB*" (concat "run " file "\n")) (error "Cannot open tangle file %S" file))))) </pre> </div> <p> Map Functions </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (map! :map org-mode-map (:prefix (",m" . "Matlab") :n "e" 'tdh-matlab-run-command :n "E" 'tdh-matlab-run-command-show-output :n "T" 'tdh-matlab-tangle-and-execute :nv "h" 'tdh-matlab-help :nv "w" 'tdh-matlab-whos))) </pre> </div> </div> </div> <div id="outline-container-org71fa917" class="outline-3"> <h3 id="org71fa917">Remap <code>ctrl-ret</code> used to execute the src block and go to the next one</h3> <div class="outline-text-3" id="text-org71fa917"> <p> <a href="https://emacs.stackexchange.com/questions/13869/how-to-toggle-org-mode-source-code-block-eval-no-status">https://emacs.stackexchange.com/questions/13869/how-to-toggle-org-mode-source-code-block-eval-no-status</a> </p> <p> Remap <code>ctrl-ret</code> to execute the source block and go to the next source block when inside a source block. Otherwise, keep the normal behavior for <code>ctrl-ret</code>. </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-ctrl-ret () (interactive) (defun tdh-in-src-block-p () "Returns t when the point is inside a source code block" (string= "src" (org-in-block-p '("src")))) (if (tdh-in-src-block-p) (progn (org-babel-execute-src-block) (org-babel-next-src-block)) (+org--insert-item 'below))) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(map! :after evil-org :map evil-org-mode-map :n "<C-return>" #'tdh-ctrl-ret) </pre> </div> </div> </div> <div id="outline-container-org4b37ab8" class="outline-3"> <h3 id="org4b37ab8">Remap <code>ctrl-shift-ret</code> used to execute the (matlab) src block in the background and go to the next one</h3> <div class="outline-text-3" id="text-org4b37ab8"> </div> <div id="outline-container-orgb05f319" class="outline-4"> <h4 id="orgb05f319"><code>tdh-org-babel-execute-matlab-background</code></h4> <div class="outline-text-4" id="text-orgb05f319"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-org-babel-execute-matlab-background (&optional arg info params) (interactive) (let* ((org-babel-current-src-block-location (or org-babel-current-src-block-location (nth 5 info) (org-babel-where-is-src-block-head))) (info (if info (copy-tree info) (org-babel-get-src-block-info)))) ;; Merge PARAMS with INFO before considering source block ;; evaluation since both could disagree. (cl-callf org-babel-merge-params (nth 2 info) params) (when (org-babel-check-evaluate info) (cl-callf org-babel-process-params (nth 2 info)) (let* ((params (nth 2 info)) (cache (let ((c (cdr (assq :cache params)))) (and (not arg) c (string= "yes" c)))) (new-hash (and cache (org-babel-sha1-hash info :eval))) (old-hash (and cache (org-babel-current-result-hash))) (current-cache (and new-hash (equal new-hash old-hash)))) (cond (current-cache (save-excursion ;Return cached result. (goto-char (org-babel-where-is-src-block-result nil info)) (forward-line) (skip-chars-forward " \t") (let ((result (org-babel-read-result))) (message (replace-regexp-in-string "%" "%%" (format "%S" result))) result))) ((org-babel-confirm-evaluate info) (let* ((lang (nth 0 info)) (result-params (cdr (assq :result-params params))) ;; Expand noweb references in BODY and remove any ;; coderef. (body (let ((coderef (nth 6 info)) (expand (if (org-babel-noweb-p params :eval) (org-babel-expand-noweb-references info) (nth 1 info)))) (if (not coderef) expand (replace-regexp-in-string (org-src-coderef-regexp coderef) "" expand nil nil 1)))) (dir (cdr (assq :dir params))) (mkdirp (cdr (assq :mkdirp params))) (default-directory (cond ((not dir) default-directory) ((member mkdirp '("no" "nil" nil)) (file-name-as-directory (expand-file-name dir))) (t (let ((d (file-name-as-directory (expand-file-name dir)))) (make-directory d 'parents) d)))) (cmd (intern (concat "org-babel-execute:" lang))) result) (process-send-string "*MATLAB*" (concat body "\n")) result)) ))) ) ) </pre> </div> </div> </div> <div id="outline-container-orgf77f938" class="outline-4"> <h4 id="orgf77f938"><code>tdh-matlab-execute-selected</code></h4> <div class="outline-text-4" id="text-orgf77f938"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-matlab-execute-selected (start end) "Execute selected text in the *MATLAB* buffer" (interactive "r") (let ((regionp (buffer-substring start end))) (process-send-string "*MATLAB*" (concat regionp "\n")))) </pre> </div> </div> </div> <div id="outline-container-orgc5f1a86" class="outline-4"> <h4 id="orgc5f1a86">Remap <code>ctrl-shift-ref</code></h4> <div class="outline-text-4" id="text-orgc5f1a86"> <p> This function: </p> <ul class="org-ul"> <li>first check if inside a source block, if not does nothing</li> <li>when check if the language is <code>matlab</code> <ul class="org-ul"> <li>if it is not, it just runs the code and go to the next source block</li> <li>if it is in a <code>matlab</code> block, it first check if a region if selected, if so it just runs the selected region. if no region is selected, it runs all the code blocks and goes to the next block</li> </ul></li> </ul> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-ctrl-shift-ret () (interactive) (defun tdh-in-src-block-p () "Returns t when the point is inside a source code block" (string= "src" (org-in-block-p '("src")))) (if (tdh-in-src-block-p) (let ((lang (nth 0 (org-babel-get-src-block-info)))) (if (string= lang "matlab") (if (region-active-p) (tdh-matlab-execute-selected (region-beginning) (region-end)) (progn (tdh-org-babel-execute-matlab-background) (org-babel-next-src-block))) (tdh-ctrl-ret)) ) ) ) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(map! :after evil-org :map evil-org-mode-map :n "<C-S-return>" #'tdh-ctrl-shift-ret) </pre> </div> </div> </div> </div> <div id="outline-container-org354b3a0" class="outline-3"> <h3 id="org354b3a0">Align Source Blocks</h3> <div class="outline-text-3" id="text-org354b3a0"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-align-src-block () (interactive) (defun tdh-in-src-block-p () "Returns t when the point is inside a source code block" (string= "src" (org-in-block-p '("src")))) (if (tdh-in-src-block-p) (progn (org-edit-special) (evil-indent (point-min) (point-max)) (org-edit-src-exit)) (org-table-eval-formula))) </pre> </div> </div> </div> <div id="outline-container-org5783483" class="outline-3"> <h3 id="org5783483">Helping Functions - Tangling <code>,b</code></h3> <div class="outline-text-3" id="text-org5783483"> <p> Org-Babel Tangle Sub-tree </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-org-babel-tangle-subtree () "Tangle the current subtree" (interactive) (progn (org-narrow-to-subtree) (org-babel-tangle) (widen)) ) </pre> </div> <p> Org-Tangle and Org-Babel Jump to Tangle File </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-org-babel-jump-to-tangle-file () "Jump to tangle file for the source block at point." (interactive) (let (file org-babel-pre-tangle-hook org-babel-post-tangle-hook) (cl-letf (((symbol-function 'write-region) (lambda (start end filename &rest _ignore) (setq file filename))) ((symbol-function 'delete-file) #'ignore)) (org-babel-tangle '(4))) (when file (setq file (expand-file-name file)) (if (file-readable-p file) (find-file file) (error "Cannot open tangle file %S" file))))) </pre> </div> <p> Map Functions </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(after! org (map! :map org-mode-map (:prefix (",b" . "Tangle") :n "F" 'tdh-org-babel-jump-to-tangle-file :n "T" 'tdh-org-babel-tangle-subtree))) </pre> </div> </div> </div> </div> <div id="outline-container-orgbf4c78e" class="outline-2"> <h2 id="orgbf4c78e">Bibliography Management</h2> <div class="outline-text-2" id="text-orgbf4c78e"> <p> My bibliography management is mainly based on the following packages: </p> <ul class="org-ul"> <li><code>org-ref</code> for nice citations</li> <li><code>org-noter</code> to annotate documents</li> <li><code>org-roam</code> to manage and links all my notes</li> <li><code>helm-bibtex</code> as an interface to easily find references</li> <li><code>org-roam-bibtex</code> that connects all the above packages</li> </ul> </div> <div id="outline-container-orgd6dd52d" class="outline-3"> <h3 id="orgd6dd52d">Org Ref (<a href="https://github.com/jkitchin/org-ref">link</a>)</h3> <div class="outline-text-3" id="text-orgd6dd52d"> <p> Nice Functions: </p> <ul class="org-ul"> <li><code>org-ref-insert-ref-link</code></li> <li><code>org-ref-helm-insert-cite-link</code></li> <li><code>org-ref-list-of-figures</code></li> <li><code>org-ref-find-bad-citations</code></li> <li><code>org-ref-clean-bibtex-entry</code></li> </ul> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! org-ref :after org :init :config ;; Folder where the notes files are located (or file if just one Note file) (setq org-ref-notes-directory "~/Cloud/brain") (setq org-ref-bibliography-notes "~/Cloud/brain") ;; Bibliography File (setq reftex-default-bibliography '("~/Cloud/brain/biblio/references.bib")) (setq org-ref-default-bibliography '("~/Cloud/brain/biblio/references.bib")) ;; Folder where all the pdf are located (setq org-ref-pdf-directory "~/Cloud/pdfs") ;; Tell org-ref to let helm-bibtex find notes for it (setq org-ref-notes-function (lambda (thekey) (let ((bibtex-completion-bibliography (org-ref-find-bibliography))) (bibtex-completion-edit-notes (list (car (org-ref-get-bibtex-key-and-file thekey))))))) ;; Problem with speed: don't display broken links (setq org-ref-show-broken-links t) ;; Display information on the citation (setq org-ref-show-citation-on-enter t) (add-to-list 'org-ref-helm-user-candidates '("Open pdf in Zathura" . (lambda () (call-process "zathura" nil 0 nil (concat (file-name-as-directory org-ref-pdf-directory) (car (org-ref-get-bibtex-key-and-file)) ".pdf")))) t) (add-to-list 'org-ref-helm-user-candidates '("Drag and Drop" . (lambda () (call-process "/bin/bash" nil 0 nil "-c" (concat "dragon-drag-and-drop " (file-name-as-directory org-ref-pdf-directory) (car (org-ref-get-bibtex-key-and-file)) ".pdf")))) 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)))) ) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-org-ref-open-pdf-at-point () "Open the pdf in external program for bibtex key under point if it exists." (interactive) (let* ((results (org-ref-get-bibtex-key-and-file)) (key (car results)) (pdf-file (funcall org-ref-get-pdf-filename-function key))) (if (file-exists-p pdf-file) (call-process "zathura" nil 0 nil pdf-file) (message "no pdf found for %s" key)))) </pre> </div> </div> </div> <div id="outline-container-orgd5277ba" class="outline-3"> <h3 id="orgd5277ba">Org Noter (<a href="https://github.com/weirdNox/org-noter">link</a>)</h3> <div class="outline-text-3" id="text-orgd5277ba"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! org-noter :defer t :after (:any org pdf-view) :config (setq org-noter-always-create-frame nil) (setq org-noter-kill-frame-at-session-end nil) ;; Fraction of the frame that the document window will occupy when split (setq org-noter-doc-split-fraction '(0.6 . 0.6)) ;; Save the last visited location automatically; when starting a new session, go to that location (setq org-noter-auto-save-last-location nil) ;; Add an empty line between each note's heading and content (setq org-noter-separate-notes-from-heading t) ;; List of paths to check (non recursively) when searching for a notes file (setq org-noter-notes-search-path "~/Cloud/brain") (defun org-noter-init-pdf-view () (pdf-view-fit-page-to-window) (pdf-view-auto-slice-minor-mode) (run-at-time "0.5 sec" nil #'org-noter)) (add-hook 'pdf-view-mode-hook 'org-noter-init-pdf-view) (map! :map pdf-view-mode-map (:desc "Insert Note" :n "i" #'org-noter-insert-note)) ) </pre> </div> </div> </div> <div id="outline-container-org11a3a48" class="outline-3"> <h3 id="org11a3a48">Org Roam (<a href="https://github.com/jethrokuan/org-roam/">link</a>)</h3> <div class="outline-text-3" id="text-org11a3a48"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! org-roam :custom-face (org-roam-link ((t (:inherit org-link :foreground "#cc241d")))) :config (setq org-roam-directory "~/Cloud/brain/") (setq org-roam-completion-system 'helm) (setq org-roam-capture-templates `(("d" "default" plain (function org-roam--capture-get-point) "%?" :file-name "${slug}" :head ,(concat "#+TITLE: ${title}\n" "#+SETUPFILE: ./setup/org-setup-file.org\n" "#+HUGO_SECTION: zettels\n" "\n" "- Tags ::\n" "\n" "* Bibliography :ignore:\n" "bibliography:./biblio/references.bib" ) :unnarrowed t))) (setq org-roam-capture-ref-templates `(("r" "ref" plain (function org-roam--capture-get-point) "%?" :file-name "${slug}" :head ,(concat "#+TITLE: ${title}\n" "#+SETUPFILE: ./setup/org-setup-file.org\n" "#+HUGO_SECTION: websites\n" "#+ROAM_KEY: ${ref}\n" "\n" "- Tags ::\n" ) :unnarrowed t))) ) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-org-roam--backlinks-list (file) (if (org-roam--org-roam-file-p file) (--reduce-from (concat acc (format "- [[file:%s][%s]]\n" (file-relative-name (car it) org-roam-directory) (org-roam--get-title-or-slug (car it)))) "" (org-roam-db-query [:select [from] :from links :where (= to $s1)] file)) "")) (defun tdh-org-export-preprocessor (backend) (let ((links (tdh-org-roam--backlinks-list (buffer-file-name)))) (unless (string= links "") (save-excursion (goto-char (point-max)) (insert (concat "\n* Backlinks\n") links))))) (add-hook 'org-export-before-processing-hook 'tdh-org-export-preprocessor) </pre> </div> </div> </div> <div id="outline-container-org18473f5" class="outline-3"> <h3 id="org18473f5">Helm-Bibtex (<a href="https://github.com/tmalsburg/helm-bibtex">link</a>)</h3> <div class="outline-text-3" id="text-org18473f5"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! helm-bibtex :after-call helm-bibtex :init :config ;; Bibliography file (setq bibtex-completion-bibliography "~/Cloud/brain/biblio/references.bib") ;; Directory with all the pdfs (setq bibtex-completion-library-path "~/Cloud/pdfs") ;; Directory with notes files (setq bibtex-completion-notes-path "~/Cloud/brain/") (setq bibtex-completion-notes-extension ".org") (setq bibtex-completion-pdf-extension '(".pdf" ".djvu")) ;; Use "tags" field when looking for bib entries (setq helm-bibtex-additional-search-fields '(tags)) (setq helm-bibtex-full-frame nil) ;; Display of bibtex entries with helm (setq bibtex-completion-display-formats '((t . "${author:36} ${title:*} ${year:4} ${=type=:7} ${=has-note=:1}"))) ;; Special symbols for notes and pdf (setq bibtex-completion-pdf-symbol "⌘") (setq bibtex-completion-notes-symbol "✎") ;; Template used when creating new Note file (setq bibtex-completion-notes-template-multiple-files (concat "#+TITLE: ${title}\n" "#+SETUPFILE: ./setup/org-setup-file.org\n" "#+HUGO_SECTION: ${=type=}\n" "#+ROAM_KEY: ${=key=}\n" "\n" "- Tags ::\n" "- Reference :: cite:${=key=}\n" "- Author(s) :: ${author}\n" "- Year :: ${year}\n" "\n" "* ${author-abbrev} (${year}): ${title} :${=type=}:ignore:\n" ":PROPERTIES:\n" ":NOTER_DOCUMENT: ../pdfs/${=key=}.pdf\n" ":END:\n" "\n" "* Bibliography :ignore:\n" "bibliography:./biblio/references.bib" )) ;; Make "Edit notes" the default action (helm-delete-action-from-source "Edit notes" helm-source-bibtex) (helm-add-action-to-source "Edit notes" 'helm-bibtex-edit-notes helm-source-bibtex 0) (helm-delete-action-from-source "Open PDF Externally" helm-source-bibtex) (helm-add-action-to-source "Open PDF Externally" 'tdh-open-pdf-externally helm-source-bibtex 1) (helm-add-action-to-source "Insert Link to Note" 'tdh-insert-link-to-note helm-source-bibtex 2) ) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-insert-link-to-note (key) "Insert a link to a note associated with the bibtex entry." (if (and bibtex-completion-notes-path (f-directory? bibtex-completion-notes-path)) (let* ((path (f-join bibtex-completion-notes-path (s-concat key bibtex-completion-notes-extension)))) (if (file-exists-p path) (insert (concat "[[" (file-relative-name path) "][Notes]]")) (message "No note file associated")) ))) </pre> </div> <p> Open pdf externally </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-open-pdf-externally (key) (call-process "zathura" nil 0 nil (nth 0 (-cons-to-list (bibtex-completion-find-pdf key))))) </pre> </div> <p> Special Commands </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-helm-bibtex-favorites (&optional arg) "Search Favorite BibTeX entries" (interactive "P") (helm-bibtex arg nil "favorite ")) </pre> </div> <p> List all element of the bibliography without pdf associated </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-list-bib-without-pdf-associated () (interactive) (bibtex-completion-init) (setq candidates (bibtex-completion-candidates)) (defun canditate-is-pdf-present (candidate) (bibtex-completion-find-pdf-in-library (cdr (assoc "=key=" candidate))) ) (setq candidates-without-pdf (remove-if #'canditate-is-pdf-present candidates)) (setq candidate-without-pdf-names (mapcar (lambda (x) (cdr (assoc "title" x))) candidates-without-pdf)) (with-output-to-temp-buffer "*bib-without-pdf*" (princ (string-join candidate-without-pdf-names "\n"))) (switch-to-buffer-other-window "*bib-without-pdf*") ) </pre> </div> </div> </div> <div id="outline-container-orgd601e31" class="outline-3"> <h3 id="orgd601e31">Deft</h3> <div class="outline-text-3" id="text-orgd601e31"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! deft :custom (deft-directory "~/Cloud/brain/")) </pre> </div> </div> </div> <div id="outline-container-org910a943" class="outline-3"> <h3 id="org910a943">Org-Roam-Bibtex (<a href="https://github.com/Zaeph/org-roam-bibtex">link</a>)</h3> <div class="outline-text-3" id="text-org910a943"> <p> Provides nice functions such as: </p> <ul class="org-ul"> <li><code>orb-find-non-ref-file</code></li> <li><code>orb-insert-non-ref</code></li> <li><code>orb-note-action</code></li> </ul> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! org-roam-bibtex :hook (org-roam-mode . org-roam-bibtex-mode) :config (setq org-roam-bibtex-preformat-keywords `("=key=" "title" "author" "year" "author-abbrev" "=type=")) (setq org-roam-bibtex-templates `(("r" "ref" plain (function org-roam-capture--get-point) "" :file-name "${=key=}" :head ,(concat "#+TITLE: ${title}\n" "#+SETUPFILE: ./setup/org-setup-file.org\n" "#+HUGO_SECTION: ${=type=}\n" "#+ROAM_KEY: ${ref}\n" "\n" "- Tags ::\n" "- Reference :: ${ref}\n" "- Author(s) :: ${author}\n" "- Year :: ${year}\n" "\n" "* ${author-abbrev} (${year}): ${title} :${=type=}:ignore:\n" ":PROPERTIES:\n" ":NOTER_DOCUMENT: ../pdfs/${=key=}.pdf\n" ":END:\n" "\n" "* Bibliography :ignore:\n" "bibliography:./biblio/references.bib" ) :unnarrowed t))) (setq orb-note-actions-user '(("Open with Zathura" . tdh-open-bib-with-zathura))) ) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-open-bib-with-zathura (key) "Open the pdf corresponding to the reference KEY with Zathura" (if (listp key) (setq key (car key))) (call-process "zathura" nil 0 nil (org-ref-get-pdf-filename key))) </pre> </div> </div> </div> <div id="outline-container-org61eb6bc" class="outline-3"> <h3 id="org61eb6bc">Org-Ref-Ox-Hugo (<a href="https://github.com/jethrokuan/org-ref-ox-hugo">link</a>)</h3> <div class="outline-text-3" id="text-org61eb6bc"> <p> This package is used to correctly format the bibliography and links when exporting to hugo. </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! org-ref-ox-hugo :load-path "~/.config/doom/packages/org-ref-ox-hugo/" :config (add-to-list 'org-ref-formatted-citation-formats '("md" ("article" . "${author}, *${title}*, ${journal}, *${volume}(${number})*, ${pages} (${year}). ${doi}") ("inproceedings" . "${author}, *${title}*, In ${editor}, ${booktitle} (pp. ${pages}) (${year}). ${address}: ${publisher}.") ("book" . "${author}, *${title}* (${year}), ${address}: ${publisher}.") ("phdthesis" . "${author}, *${title}* (${year}). ${school}.") ("inbook" . "${author}, *${title}*, In ${editor} (Eds.), ${booktitle} (pp. ${pages}) (${year}). ${address}: ${publisher}.") ("incollection" . "${author}, *${title}*, In ${editor} (Eds.), ${booktitle} (pp. ${pages}) (${year}). ${address}: ${publisher}.") ("proceedings" . "${editor} (Eds.), _${booktitle}_ (${year}). ${address}: ${publisher}.") ("unpublished" . "${author}, *${title}* (${year}). Unpublished manuscript.") ("misc" . "${author} (${year}). *${title}*. Retrieved from [${howpublished}](${howpublished}). ${note}.") (nil . "${author}, *${title}* (${year})."))) (setq reference-link-class "reference-link") (setq bibtex-entry-class "bibtex-entry") ) </pre> </div> </div> </div> </div> <div id="outline-container-org5bc2aea" class="outline-2"> <h2 id="org5bc2aea">LaTeX</h2> <div class="outline-text-2" id="text-org5bc2aea"> <ul class="org-ul"> <li><a href="https://tex.stackexchange.com/questions/52179/what-is-your-favorite-emacs-and-or-auctex-command-trick">https://tex.stackexchange.com/questions/52179/what-is-your-favorite-emacs-and-or-auctex-command-trick</a></li> <li><a href="https://tex.stackexchange.com/questions/20843/useful-shortcuts-or-key-bindings-or-predefined-commands-for-emacsauctex">https://tex.stackexchange.com/questions/20843/useful-shortcuts-or-key-bindings-or-predefined-commands-for-emacsauctex</a></li> </ul> </div> <div id="outline-container-org0822b20" class="outline-3"> <h3 id="org0822b20">Master file</h3> <div class="outline-text-3" id="text-org0822b20"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq-default TeX-master nil) </pre> </div> </div> </div> <div id="outline-container-org944a888" class="outline-3"> <h3 id="org944a888">Clean Output Files</h3> <div class="outline-text-3" id="text-org944a888"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-latex-clean () "Clean LaTeX output using latexmk" (interactive) (async-shell-command ;; command and parameters "latexmk -c " (shell-quote-argument buffer-file-name) " &" )) (map! :map LaTeX-mode-map :n ",C" 'tdh-latex-clean) (add-hook 'TeX-mode-hook #'TeX-fold-mode) </pre> </div> </div> </div> <div id="outline-container-orga4ad7f6" class="outline-3"> <h3 id="orga4ad7f6">PDF Viewer</h3> <div class="outline-text-3" id="text-orga4ad7f6"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq TeX-view-program-selection '((output-pdf "Zathura"))) (setq TeX-source-correlate-mode t) (setq TeX-source-correlate-start-server t) (setq TeX-source-correlate-method 'synctex) (setq TeX-view-program-list '(("PDF Tools" TeX-pdf-tools-sync-view))) </pre> </div> </div> </div> <div id="outline-container-org120de8b" class="outline-3"> <h3 id="org120de8b">Bibtex</h3> <div class="outline-text-3" id="text-org120de8b"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! bibtex :config (bibtex-set-dialect 'BibTeX)) </pre> </div> </div> </div> </div> <div id="outline-container-orgd94d627" class="outline-2"> <h2 id="orgd94d627">Matlab</h2> <div class="outline-text-2" id="text-orgd94d627"> <ul class="org-ul"> <li><a href="https://sourceforge.net/projects/matlab-emacs/">https://sourceforge.net/projects/matlab-emacs/</a></li> </ul> </div> <div id="outline-container-orgb915baf" class="outline-3"> <h3 id="orgb915baf">Setup Matlab Mode</h3> <div class="outline-text-3" id="text-orgb915baf"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(setq matlab-shell-command "/home/thomas/.local/bin/matlab") (setq matlab-shell-command-switches (list "-nodesktop -nosplash")) (setq mlint-programs '("mlint" "/home/thomas/.local/bin/mlint")) </pre> </div> </div> </div> <div id="outline-container-orga36d033" class="outline-3"> <h3 id="orga36d033">Setup Flycheck to work with <code>mlint</code></h3> <div class="outline-text-3" id="text-orga36d033"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defvar mlint-executable "/home/thomas/.local/bin/mlint") (flycheck-define-command-checker 'matlab-mlint "A Matlab checker based on mlint." :command `(,mlint-executable source) :error-patterns '((warning line-start "L " line " (C " (1+ digit) "): " (message) line-end)) :modes '(matlab-mode)) (add-to-list 'flycheck-checkers 'matlab-mlint) ;; Automatic startup of flycheck for matlab (add-hook 'matlab-mode-hook 'flycheck-mode) </pre> </div> </div> </div> <div id="outline-container-org04bf41d" class="outline-3"> <h3 id="org04bf41d">Completion in the Matlab Shell</h3> <div class="outline-text-3" id="text-org04bf41d"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(map! :map matlab-shell-mode-map :i "<tab>" 'matlab-shell-tab) </pre> </div> </div> </div> <div id="outline-container-orgace4163" class="outline-3"> <h3 id="orgace4163">Beautify code</h3> <div class="outline-text-3" id="text-orgace4163"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-matlab-beautify-buffer () "Beautify Current Matlab Buffer" (interactive) ;; First verifies is the current file is a Matlab file (if (string= (file-name-extension (buffer-file-name)) "m") (progn (save-buffer) (matlab-shell-run-command (concat "MBeautify.formatFileNoEditor(\"" (buffer-file-name) "\", \"" (buffer-file-name) "\")")) (revert-buffer :ignore-auto :noconfirm)) (message "Current buffer is not a matlab file") ) ) </pre> </div> </div> </div> <div id="outline-container-orgb85ca7e" class="outline-3"> <h3 id="orgb85ca7e">Key Bindings</h3> <div class="outline-text-3" id="text-orgb85ca7e"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun tdh-matlab-add-breakpoint () (interactive) (matlab-shell-run-command (concat "dbstop in " (buffer-name) " at " (number-to-string (line-number-at-pos nil))))) (defun tdh-matlab-remove-breakpoint () (interactive) (matlab-shell-run-command (concat "dbclear in " (buffer-name) " at " (number-to-string (line-number-at-pos nil))))) (defun tdh-matlab-list-breakpoints () (interactive) (matlab-shell-run-command (concat "dbstatus " (buffer-name)))) (defun tdh-matlab-clear-breakpoints () (interactive) (matlab-shell-run-command (concat "dbclear in " (buffer-name)))) (defun tdh-matlab-go-to-file-directory () (interactive) (matlab-shell-run-command (concat "cd " (file-name-directory buffer-file-name)))) </pre> </div> <div class="org-src-container"> <pre class="src src-emacs-lisp">(map! :map matlab-mode-map :n ",g" 'tdh-matlab-go-to-file-directory :n ",da" 'tdh-matlab-add-breakpoint :n ",dr" 'tdh-matlab-remove-breakpoint :n ",dL" 'tdh-matlab-list-breakpoints :n ",dc" 'tdh-matlab-clear-breakpoints :n ",dl" 'gud-cont :n ",ds" 'gud-step :n ",dn" 'gud-next :n ",dq" 'gud-finish) </pre> </div> </div> </div> </div> <div id="outline-container-org7d36b5d" class="outline-2"> <h2 id="org7d36b5d">Mu4e</h2> <div class="outline-text-2" id="text-org7d36b5d"> </div> <div id="outline-container-org0022939" class="outline-3"> <h3 id="org0022939">Resources</h3> <div class="outline-text-3" id="text-org0022939"> <p> Documentation: </p> <ul class="org-ul"> <li class="off"><code>[ ]</code> Mu4e documentation: <a href="http://www.djcbsoftware.nl/code/mu/mu4e/index.html#Top">http://www.djcbsoftware.nl/code/mu/mu4e/index.html#Top</a></li> <li class="off"><code>[ ]</code> <a href="https://github.com/djcb/mu">https://github.com/djcb/mu</a></li> </ul> <p> Use contexts for multiple accounts: </p> <ul class="org-ul"> <li class="off"><code>[ ]</code> <a href="https://vxlabs.com/2017/02/07/mu4e-0-9-18-e-mailing-with-emacs-now-even-better/">https://vxlabs.com/2017/02/07/mu4e-0-9-18-e-mailing-with-emacs-now-even-better/</a></li> <li class="off"><code>[ ]</code> <a href="http://cachestocaches.com/2017/3/complete-guide-email-emacs-using-mu-and-/">http://cachestocaches.com/2017/3/complete-guide-email-emacs-using-mu-and-/</a></li> <li class="off"><code>[ ]</code> <a href="https://notanumber.io/2016-10-03/better-email-with-mu4e/">https://notanumber.io/2016-10-03/better-email-with-mu4e/</a></li> </ul> <p> Send math and source code: </p> <ul class="org-ul"> <li class="off"><code>[ ]</code> <a href="https://vxlabs.com/2015/01/28/sending-emails-with-math-and-source-code/">https://vxlabs.com/2015/01/28/sending-emails-with-math-and-source-code/</a></li> </ul> </div> </div> <div id="outline-container-orgdf9660c" class="outline-3"> <h3 id="orgdf9660c">Cheatsheet</h3> <div class="outline-text-3" id="text-orgdf9660c"> <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-left" /> <col class="org-left" /> </colgroup> <thead> <tr> <th scope="col" class="org-left">Command</th> <th scope="col" class="org-left">Usage</th> </tr> </thead> <tbody> <tr> <td class="org-left"><code>C-j</code></td> <td class="org-left">Next mail</td> </tr> <tr> <td class="org-left"><code>C-k</code></td> <td class="org-left">Previous mail</td> </tr> <tr> <td class="org-left"><code>R/C/F</code></td> <td class="org-left">Reply/Compose/Forward</td> </tr> <tr> <td class="org-left"><code>t</code></td> <td class="org-left">Move to Archive</td> </tr> <tr> <td class="org-left"><code>d</code></td> <td class="org-left">Move to Trash</td> </tr> </tbody> </table> </div> </div> <div id="outline-container-org998a101" class="outline-3"> <h3 id="org998a101">Helping function</h3> <div class="outline-text-3" id="text-org998a101"> <p> This is a helper to help determine which account context I am in based on the folder in my maildir the email (eg. ~/.mail/nine27) is located in. </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun mu4e-message-maildir-matches (msg rx) (when rx (if (listp rx) ;; If rx is a list, try each one for a match (or (mu4e-message-maildir-matches msg (car rx)) (mu4e-message-maildir-matches msg (cdr rx))) ;; Not a list, check rx (string-match rx (mu4e-message-field msg :maildir))))) </pre> </div> <p> Choose account label to feed msmtp -a option based on From header in Message buffer; This function must be added to message-send-mail-hook for on-the-fly change of From address before sending message since message-send-mail-hook is processed right before sending message. </p> <div class="org-src-container"> <pre class="src src-emacs-lisp">(defun choose-msmtp-account () (if (message-mail-p) (save-excursion (let* ((from (save-restriction (message-narrow-to-headers) (message-fetch-field "from"))) (account (cond ((string-match "dehaeze.thomas@gmail.com" from) "gmail") ((string-match "thomas.dehaeze@esrf.fr" from) "esrf")))) (setq message-sendmail-extra-arguments (list '"-a" account)))))) </pre> </div> </div> </div> <div id="outline-container-orge7dad22" class="outline-3"> <h3 id="orge7dad22">Basic Config</h3> <div class="outline-text-3" id="text-orge7dad22"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! mu4e :config (setq mail-user-agent 'mu4e-user-agent mu4e-mu-binary "/usr/bin/mu" mu4e-maildir "~/.mail" mu4e-compose-format-flowed t mu4e-compose-in-new-frame nil mu4e-view-show-images t mu4e-html2text-command "w3m -dump -T text/html" mu4e-use-fancy-chars t mu4e-headers-include-related t mu4e-attachment-dir "~/Downloads" message-kill-buffer-on-exit t mu4e-compose-signature-auto-include t mu4e-view-show-images t mu4e-view-show-addresses t) ) </pre> </div> </div> </div> <div id="outline-container-org5886531" class="outline-3"> <h3 id="org5886531">Additional config</h3> <div class="outline-text-3" id="text-org5886531"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! mu4e :config ;; Use imagemagick, if available. (when (fboundp 'imagemagick-register-types) (imagemagick-register-types)) ;; Sometimes html email is just not readable in a text based client, this lets me open the ;; email in my browser. (add-to-list 'mu4e-view-actions '("View in browser" . mu4e-action-view-in-browser) t) ;; Spell checking ftw. (add-hook 'mu4e-compose-mode-hook 'flyspell-mode) ;; Use Helm to select mailboxes (setq mu4e-completing-read-function 'completing-read) ;; Don't ask for a 'context' upon opening mu4e (setq mu4e-context-policy 'pick-first) ;; Don't ask to quit... why is this the default? (setq mu4e-confirm-quit nil) ) </pre> </div> </div> </div> <div id="outline-container-orgbc87a17" class="outline-3"> <h3 id="orgbc87a17">Provide Information</h3> <div class="outline-text-3" id="text-orgbc87a17"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! mu4e :config (setq mu4e-user-mail-address-list '("dehaeze.thomas@gmail.com" "thomas.dehaeze@esrf.fr") mu4e-compose-signature "Thomas Dehaeze\n" user-mail-address "dehaeze.thomas@gmail.com") ;; Default Folders (setq mu4e-sent-folder "/gmail/Sent" mu4e-drafts-folder "/gmail/Drafts" mu4e-trash-folder "/gmail/Trash" mu4e-refile-folder "/gmail/Archive") ) </pre> </div> </div> </div> <div id="outline-container-org4f572af" class="outline-3"> <h3 id="org4f572af">Receiving emails using mbsync</h3> <div class="outline-text-3" id="text-org4f572af"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! mu4e :config (setq mu4e-get-mail-command "checkmail" mu4e-update-interval nil mu4e-change-filenames-when-moving t) ;; Fix for mbsync ) </pre> </div> </div> </div> <div id="outline-container-orgd7ab730" class="outline-3"> <h3 id="orgd7ab730">Contexts</h3> <div class="outline-text-3" id="text-orgd7ab730"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! mu4e :config (setq mu4e-contexts `( ,(make-mu4e-context :name "gmail" :enter-func (lambda () (mu4e-message "Switch to the gmail context")) :match-func (lambda (msg) (when msg (string-prefix-p "/gmail" (mu4e-message-field msg :maildir)))) :leave-func (lambda () (mu4e-clear-caches)) :vars '( (user-mail-address . "dehaeze.thomas@gmail.com") (user-full-name . "Thomas Dehaeze") (mu4e-sent-folder . "/gmail/Sent") (mu4e-trash-folder . "/gmail/Trash") (mu4e-drafts-folder . "/gmail/Drafts") (mu4e-refile-folder . "/gmail/Archive") (mu4e-compose-signature . "Thomas Dehaeze\n") )) ,(make-mu4e-context :name "esrf" :enter-func (lambda () (mu4e-message "Switch to the esrf context")) :match-func (lambda (msg) (when msg (string-prefix-p "/esrf" (mu4e-message-field msg :maildir)))) :leave-func (lambda () (mu4e-clear-caches)) :vars '( (user-mail-address . "thomas.dehaeze@esrf.fr") (user-full-name . "Thomas Dehaeze") (mu4e-sent-folder . "/esrf/Sent") (mu4e-trash-folder . "/esrf/Trash") (mu4e-drafts-folder . "/esrf/Drafts") (mu4e-refile-folder . "/esrf/Archive") (mu4e-compose-signature . "Thomas Dehaeze\n") )) )) ) </pre> </div> </div> </div> <div id="outline-container-org0f5f14d" class="outline-3"> <h3 id="org0f5f14d">Sending mails</h3> <div class="outline-text-3" id="text-org0f5f14d"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! mu4e :config (setq message-send-mail-function 'message-send-mail-with-sendmail sendmail-program "/usr/bin/msmtp" user-full-name "Thomas Dehaeze") ;; This prevents saving the email to the Sent folder since gmail will do this for us on their end. (setq mu4e-sent-messages-behavior 'delete) ;; Use the correct account context when sending mail based on the from header. (setq message-sendmail-envelope-from 'header) (add-hook 'message-send-mail-hook 'choose-msmtp-account) ) </pre> </div> </div> </div> <div id="outline-container-orgeb454c4" class="outline-3"> <h3 id="orgeb454c4">Bookmarks</h3> <div class="outline-text-3" id="text-orgeb454c4"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(use-package! mu4e :config (setq mu4e-bookmarks `(,(make-mu4e-bookmark :name "All Inboxes" :query "maildir:/gmail/Inbox OR maildir:/esrf/Inbox" :key ?i) ("flag:unread" "Unread messages" ?u) ("date:today..now" "Today's messages" ?t) ("date:7d..now" "Last 7 days" ?w))) ) </pre> </div> </div> </div> </div> <div id="outline-container-org0b90463" class="outline-2"> <h2 id="org0b90463">Doom <code>init.el</code></h2> <div class="outline-text-2" id="text-org0b90463"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(when noninteractive (after! undo-tree (global-undo-tree-mode -1))) (doom! :completion company ; the ultimate code completion backend helm ; the *other* search engine for love and life ivy ; a search engine for love and life :ui doom ; what makes DOOM look the way it does deft hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW hydra (modeline +light) ; 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 unicode ; extended unicode support for various languages vc-gutter ; vcs diff in the fringe vi-tilde-fringe ; fringe tildes to mark beyond EOB workspaces ; tab emulation, persistence & separate workspaces :editor (evil +everywhere); come to the dark side, we have cookies fold ; (nigh) universal code folding 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] electric ; smarter, keyword-based electric-indent (ibuffer +icons) ; interactive buffer management vc ; version-control and Emacs, sitting in a tree :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 ;;pass ; password manager for nerds pdf ; pdf enhancements eval biblio :checkers syntax ; tasing you for every semicolon you forget spell ; tasing you for misspelling mispelling :lang data ; config/data formats emacs-lisp ; drown in parentheses go (javascript +lsp) latex ; writing papers in Emacs has never been so fun ;; 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 +roam ; +present) ; using org-mode for presentations python ; beautiful is better than ugly (sh ; she sells {ba,z,fi}sh shells on the C xor +lsp) (web +lsp) :email (mu4e +gmail) :app calendar ;;(rss +org) ; emacs as an RSS reader ;;write ; emacs for writers (fiction, notes, papers, etc.) :config literate (default +bindings) ) </pre> </div> </div> </div> <div id="outline-container-org973006b" class="outline-2"> <h2 id="org973006b">Doom <code>packages.el</code></h2> <div class="outline-text-2" id="text-org973006b"> <div class="org-src-container"> <pre class="src src-emacs-lisp">(package! poet-theme) (package! org-alert) (package! org-gcal) (package! ox-latex-subfigure :recipe (:host github :repo "linktohack/ox-latex-subfigure")) (package! matlab-mode :recipe (:host github :repo "matlab-mode/mirror")) (package! org-ref) (package! org-roam-bibtex) (package! org-ql) (package! org-fancy-priorities) (package! evil-escape :disable t) (package! dired-narrow) </pre> </div> </div> </div> </div> <div id="postamble" class="status"> <p class="author">Author: Dehaeze Thomas</p> <p class="date">Created: 2020-05-26 mar. 08:39</p> </div> </body> </html>