Add org-roam-bibtex, improve key bindings

This commit is contained in:
Thomas Dehaeze 2020-05-26 08:39:24 +02:00
parent c0035725ce
commit afbdc290d9
2 changed files with 500 additions and 310 deletions

View File

@ -1,7 +1,5 @@
#+TITLE: Doom Emacs Configuration
:DRAWER:
#+STARTUP: overview
#+LANGUAGE: en
#+EMAIL: dehaeze.thomas@gmail.com
#+AUTHOR: Dehaeze Thomas
@ -29,9 +27,13 @@ https://github.com/nmartin84/.doom.d/blob/master/config.org
Documentation:
- https://github.com/hlissner/doom-emacs/blob/develop/docs/index.org
When changing =init.el= or =package.el=, tangle the files and then run =doom sync=.
After that, restart Emacs with =spc q r=.
* Useful Bindings
- =align-regexp=: equivalent of [[https://github.com/junegunn/vim-easy-align][vim-easy-align]]. Very useful to align tables and stuff
** General Bindings
| =spc := | Execute command |
| =spc <= | Switch to buffer |
| =spc X= | org-capture |
@ -58,29 +60,38 @@ Documentation:
| =spc m s= | org-schedule |
| =spc m t= | org-todo |
** Org-Babel Bindings
| =C-c C-v p= | org-babel-previous-src-block |
| =C-c C-v n= | org-babel-next-src-block |
| =C-c C-v e= | org-babel-execute-maybe |
| =C-c C-v o= | org-babel-open-src-block-result |
| =C-c C-v v= | org-babel-expand-src-block |
| =C-c C-v u= | org-babel-goto-src-block-head |
| =C-c C-v g= | org-babel-goto-named-src-block |
| =C-c C-v r= | org-babel-goto-named-result |
| =C-c C-v b= | org-babel-execute-buffer |
| =C-c C-v s= | org-babel-execute-subtree |
| =C-c C-v d= | org-babel-demarcate-block |
| =C-c C-v t= | org-babel-tangle |
| =C-c C-v f= | org-babel-tangle-file |
| =C-c C-v c= | org-babel-check-src-block |
| =C-c C-v j= | org-babel-insert-header-arg |
| =C-c C-v l= | org-babel-load-in-session |
| =C-c C-v i= | org-babel-lob-ingest |
| =C-c C-v I= | org-babel-view-src-block-info |
| =C-c C-v z= | org-babel-switch-to-session-with-code |
| =C-c C-v a= | org-babel-sha1-hash |
| =C-c C-v h= | org-babel-describe-bindings |
| =C-c C-v x= | org-babel-do-key-sequence-in-edit-buffer |
| C-c C-v p | org-babel-previous-src-block |
| C-c C-v n | org-babel-next-src-block |
| C-c C-v e | org-babel-execute-maybe |
| C-c C-v o | org-babel-open-src-block-result |
| C-c C-v v | org-babel-expand-src-block |
| C-c C-v u | org-babel-goto-src-block-head |
| C-c C-v g | org-babel-goto-named-src-block |
| C-c C-v r | org-babel-goto-named-result |
| C-c C-v b | org-babel-execute-buffer |
| C-c C-v s | org-babel-execute-subtree |
| C-c C-v d | org-babel-demarcate-block |
| C-c C-v t | org-babel-tangle |
| C-c C-v f | org-babel-tangle-file |
| C-c C-v c | org-babel-check-src-block |
| C-c C-v j | org-babel-insert-header-arg |
| C-c C-v l | org-babel-load-in-session |
| C-c C-v i | org-babel-lob-ingest |
| C-c C-v I | org-babel-view-src-block-info |
| C-c C-v z | org-babel-switch-to-session-with-code |
| C-c C-v a | org-babel-sha1-hash |
| C-c C-v h | org-babel-describe-bindings |
| C-c C-v x | org-babel-do-key-sequence-in-edit-buffer |
** Evil bindings
| ~gv~ | Selects the previous visual |
| ~o~ in visual mode | go to the `Other` end of the selection |
| ~g=~ and ~g-~ | Increase/decrement number |
| ~t~ followed by any char | goes "till" next character (not included) |
| ~f~ followed by any char | "find" next character (included) |
| ~yt.~ | yank until next ~.~ |
* Basic Configuration
** Personal Information
@ -188,6 +199,36 @@ Turn off auto-fill mode that add line breaks.
(setq magit-diff-refine-hunk 'all)
#+end_src
** Dired
- =C-c C-e= Writable Dired mode, when changes are done =C-c C-c=.
This works also with =C-x C-q=
- =C-c C-r= use =rsync= to copy file in the background
- =+= Create a directory
- =R= Rename / move
- =C= Copy
- =d= Delete
- =m= Mark
- =U= unmark all marked
- =t= invert the selection
- =u= unmark / undelete
- =x= actually delete files/directories marked for deletion
- =!= Execute shell command on this file, or currently marked files
- =%m= mark by pattern
- =o= sort by time/name
- =(= Hide details
- =)= Show git infos
#+begin_src emacs-lisp
(use-package! dired-narrow
:config
(map! :map dired-mode-map
:n "f"
'dired-narrow-fuzzy))
#+end_src
** PDF-Tools
#+begin_src emacs-lisp
(use-package! pdf-tools
@ -202,6 +243,21 @@ Turn off auto-fill mode that add line breaks.
(yas-global-mode 1)
#+end_src
** Ox-Hugo
#+begin_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))))
#+end_src
* Org Mode
- http://cachestocaches.com/2016/9/my-workflow-org-agenda/
- http://doc.norang.ca/org-mode.html#TodoKeywords
@ -209,6 +265,7 @@ Turn off auto-fill mode that add line breaks.
** Org General Config
#+begin_src emacs-lisp
(setq org-directory "~/Cloud/org/")
(after! org
(setq org-directory "~/Cloud/org/")
@ -225,6 +282,7 @@ Turn off auto-fill mode that add line breaks.
;; 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)
@ -250,10 +308,8 @@ Display the real size of images and not the one set with =attr_latex: :width \li
** Org Links
#+begin_src emacs-lisp
(after! org
(map! :map org-mode-map "C-c l" 'org-store-link)
(setq org-link-abbrev-alist
'(("bib" . "~/Cloud/brain/references.bib::%s")
'(("bib" . "~/Cloud/brain/biblio/references.bib::%s")
("notes" . "~/Cloud/brain/%s.org")
("papers" . "~/Cloud/pdfs/%s.pdf")))
)
@ -365,8 +421,6 @@ Archive subtrees under the same hierarchy as original in the archive files
General configuration
#+begin_src emacs-lisp
(after! org
(map! :map org-mode-map "C-c a" 'org-agenda)
;; File to save todo items
(setq org-agenda-files (list "~/Cloud/org/"))
@ -544,11 +598,6 @@ Documentation:
- Template expansion: https://orgmode.org/manual/Template-expansion.html#Template-expansion
- Capture protocol: https://orgmode.org/manual/capture-protocol.html
#+begin_src emacs-lisp
(after! org
(map! :map org-mode-map "C-c c" 'org-capture))
#+end_src
#+begin_src emacs-lisp
(after! org
(setq org-capture-templates
@ -657,7 +706,7 @@ Do not export headline with the =:ignore:= tag:
(setq org-html-wrap-src-lines nil)
;; Export with css class instead of inline css
(setq org-html-htmlize-output-type 'css)
(setq org-html-htmlize-output-type 'nil)
)
#+end_src
@ -959,18 +1008,18 @@ https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-he
#+begin_src emacs-lisp
(after! org
(defun org/get-headline-string-element (headline backend info)
(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 org/ensure-latex-clearpage (headline backend info)
(defun tdh-ensure-latex-clearpage (headline backend info)
(when (org-export-derived-backend-p backend 'latex)
(let ((elmnt (org/get-headline-string-element headline backend info)))
(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
'org/ensure-latex-clearpage)
'tdh-ensure-latex-clearpage)
)
#+end_src
@ -991,7 +1040,7 @@ https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-he
(after! org
;; Setup default option for image size when exporting to LaTeX
(setq org-latex-image-default-scale "")
(setq org-latex-image-default-width "")
(setq org-latex-image-default-width "\\linewidth")
(setq org-latex-image-default-height "")
(setq org-latex-image-default-option "")
@ -1004,6 +1053,9 @@ https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-he
;; 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"))
@ -1092,24 +1144,12 @@ https://emacs.stackexchange.com/questions/156/emacs-function-to-convert-an-arbit
(insert (format "\\page{%s}\n" page)))
#+end_src
#+begin_src emacs-lisp :tangle no
(defun org-latex-format-headline-default-function (todo _todo-type priority text tags _info)
"Default format function for a headline.
See `org-latex-format-headline-function' for details."
(concat
(and todo (format "{\\bfseries\\sffamily %s} " todo))
(and priority (format "\\framebox{\\#%c} " priority))
text
(and tags
(format "\\hfill{}\\textsc{%s}"
(mapconcat #'org-latex--protect-text tags ":")))
(and todo (format "{\n\\page{%s} " todo)))
#+end_src
*** Number Equations
https://kitchingroup.cheme.cmu.edu/blog/2016/11/07/Better-equation-numbering-in-LaTeX-fragments-in-org-mode/
#+begin_src emacs-lisp
(after! org
(defun org-renumber-environment (orig-func &rest args)
(defun tdh-org-renumber-environment (orig-func &rest args)
"A function to inject numbers in LaTeX fragment previews."
(let ((results '())
(counter -1)
@ -1150,7 +1190,7 @@ https://emacs.stackexchange.com/questions/156/emacs-function-to-convert-an-arbit
(apply orig-func args))
(advice-add 'org-create-formula-image :around #'org-renumber-environment)
(advice-add 'org-create-formula-image :around #'tdh-org-renumber-environment)
)
#+end_src
@ -1173,15 +1213,15 @@ https://www.reddit.com/r/orgmode/comments/7u2n0h/tip_for_defining_latex_macros_f
(defun org-babel-execute:latex-macros (body _params)
(concat
"\n#+HTML_HEAD_EXTRA: <div style=\"display: none\"> \\(\n"
(prefix-all-lines "#+HTML_HEAD_EXTRA: " body)
"\n#+HTML_HEAD_EXTRA: \\)</div>\n"))
"\n#+begin_export html\n<div style=\"display: none\"> \\(\n"
body
"\n\\)</div>\n#+end_export\n"))
)
#+end_src
** TODO Org Projects
#+begin_src emacs-lisp :tangle no
** Org Projects
#+begin_src emacs-lisp
(setq org-publish-project-alist
'(("config"
:base-directory "~/.config/literate-dotfiles/dotfiles/"
@ -1239,7 +1279,7 @@ https://www.reddit.com/r/orgmode/comments/7u2n0h/tip_for_defining_latex_macros_f
#+end_src
** TODO Org big org-project
#+begin_src emacs-lisp
#+begin_src emacs-lisp :tangle no
(setq org-publish-project-alist
'(("website"
:components ("nass-simscape" "nass-simscape-images"))
@ -1418,7 +1458,50 @@ https://www.reddit.com/r/emacs/comments/d3a8or/pretty_org_tables_in_the_buffer_c
)
#+end_src
** Custom Keybindings - =,= leader key
** TODO [#A] Custom Keybindings - =,= leader key and =C-c=
| | |
|---------+-------------------|
| =C-c a= | Org Agenda |
| =C-c n= | Narrow to Subtree |
| =C-c l= | Org Link |
#+begin_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)
))
#+end_src
*** Insert Elements =,i=
Insert Link to paper
#+begin_src emacs-lisp
@ -1494,12 +1577,17 @@ Take Screenshot and insert a link:
#+begin_src emacs-lisp
(defun tdh-insert-screenshot-org-link ()
"Capture screenshot and insert the resulting file.
"Capture screenshot and insert the resulting file.
The screenshot tool is determined by `org-download-screenshot-method'."
(interactive)
(setq filename (concat "./figs/" (read-string "Enter file name:") ".png"))
(shell-command (concat "maim -s " filename))
(insert (format "[[file:%s]]" filename))
(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)
)
#+end_src
@ -1513,6 +1601,16 @@ Insert link to next figure:
)
#+end_src
Insert link to previous figure:
#+begin_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) "]]"))
)
#+end_src
Map Keys
#+begin_src emacs-lisp
(after! org
@ -1524,6 +1622,7 @@ Map Keys
: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)))
#+end_src
@ -1581,7 +1680,7 @@ Map Keys
(:prefix (",r" . "References")
:n "b" 'helm-bibtex
:n "B" 'helm-bibtex-with-local-bibliography
:n "f" 'helm-bibtex-favorites
:n "f" 'tdh-helm-bibtex-favorites
:n "r" 'helm-resume)))
#+end_src
@ -1635,6 +1734,12 @@ Don't ask for confirmation when evaluating following blocs
(setq org-confirm-babel-evaluate 'tdh-org-confirm-babel-evaluate))
#+end_src
Default header arguments.
#+begin_src emacs-lisp
(after! org
(setq org-babel-default-header-args '((:eval . "no-export"))))
#+end_src
Use the current window for C-c ' source editing
#+begin_src emacs-lisp
(after! org
@ -1788,11 +1893,11 @@ when inside a source block. Otherwise, keep the normal behavior for =ctrl-ret=.
#+begin_src emacs-lisp
(defun tdh-ctrl-ret ()
(interactive)
(defun in-src-block-p ()
(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 (in-src-block-p)
(if (tdh-in-src-block-p)
(progn
(org-babel-execute-src-block)
(org-babel-next-src-block))
@ -1889,11 +1994,11 @@ This function:
#+begin_src emacs-lisp
(defun tdh-ctrl-shift-ret ()
(interactive)
(defun in-src-block-p ()
(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 (in-src-block-p)
(if (tdh-in-src-block-p)
(let ((lang (nth 0 (org-babel-get-src-block-info))))
(if (string= lang "matlab")
(if (region-active-p)
@ -1916,11 +2021,11 @@ This function:
#+begin_src emacs-lisp
(defun tdh-align-src-block ()
(interactive)
(defun in-src-block-p ()
(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 (in-src-block-p)
(if (tdh-in-src-block-p)
(progn
(org-edit-special)
(evil-indent (point-min) (point-max))
@ -1928,12 +2033,6 @@ This function:
(org-table-eval-formula)))
#+end_src
#+begin_src emacs-lisp
(map! :after evil-org
:map evil-org-mode-map
:n "C-c =" #'tdh-align-src-block)
#+end_src
** Helping Functions - Tangling =,b=
Org-Babel Tangle Sub-tree
#+begin_src emacs-lisp
@ -1999,8 +2098,8 @@ Nice Functions:
(setq org-ref-bibliography-notes "~/Cloud/brain")
;; Bibliography File
(setq reftex-default-bibliography '("~/Cloud/brain/references.bib"))
(setq org-ref-default-bibliography '("~/Cloud/brain/references.bib"))
(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")
@ -2032,10 +2131,12 @@ Nice Functions:
".pdf"))))
t)
(map!
:map org-mode-map
(:desc "Insert Link"
:ni "C-c i" #'org-ref-insert-ref-link))
;; 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))))
)
#+end_src
@ -2099,16 +2200,32 @@ Nice Functions:
"%?"
:file-name "${slug}"
:head ,(concat "#+TITLE: ${title}\n"
"#+SETUPFILE ./org-roam-setup-file.org\n"
"#+SETUPFILE: ./setup/org-setup-file.org\n"
"#+HUGO_SECTION: zettels\n"
"\n"
"- Tags ::\n"
"\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)))
)
#+end_src
#+begin_src emacs-lisp
(defun my/org-roam--backlinks-list (file)
(defun tdh-org-roam--backlinks-list (file)
(if (org-roam--org-roam-file-p file)
(--reduce-from
(concat acc (format "- [[file:%s][%s]]\n"
@ -2117,23 +2234,24 @@ Nice Functions:
"" (org-roam-db-query [:select [from] :from links :where (= to $s1)] file))
""))
(defun my/org-export-preprocessor (backend)
(let ((links (my/org-roam--backlinks-list (buffer-file-name))))
(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 'my/org-export-preprocessor)
(add-hook 'org-export-before-processing-hook 'tdh-org-export-preprocessor)
#+end_src
** Helm-Bibtex ([[https://github.com/tmalsburg/helm-bibtex][link]])
#+begin_src emacs-lisp
(use-package! helm-bibtex
:after-call helm-bibtex
:init
:config
;; Bibliography file
(setq bibtex-completion-bibliography "~/Cloud/brain/references.bib")
(setq bibtex-completion-bibliography "~/Cloud/brain/biblio/references.bib")
;; Directory with all the pdfs
(setq bibtex-completion-library-path "~/Cloud/pdfs")
@ -2160,32 +2278,57 @@ Nice Functions:
;; Template used when creating new Note file
(setq bibtex-completion-notes-template-multiple-files (concat "#+TITLE: ${title}\n"
"#+NOTER_DOCUMENT: ../pdfs/${=key=}.pdf\n"
"#+ROAM_KEY: cite:${=key=}\n"
"#+SETUPFILE: ./setup/org-setup-file.org\n"
"#+HUGO_SECTION: ${=type=}\n"
"#+ROAM_KEY: ${=key=}\n"
"\n"
"- Author :: ${author}\n"
"- Tags ::\n"
"- Reference :: cite:${=key=}\n"
"- Author(s) :: ${author}\n"
"- Year :: ${year}\n"
"- DOI :: ${DOI}\n"
"\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" 'tdehaeze/open-pdf-externally helm-source-bibtex 1)
(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)
)
#+end_src
#+begin_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"))
)))
#+end_src
Open pdf externally
#+begin_src emacs-lisp
(defun tdehaeze/open-pdf-externally (key)
(defun tdh-open-pdf-externally (key)
(call-process "zathura" nil 0 nil (nth 0 (-cons-to-list (bibtex-completion-find-pdf key)))))
#+end_src
Special Commands
#+begin_src emacs-lisp
(defun helm-bibtex-favorites (&optional arg)
(defun tdh-helm-bibtex-favorites (&optional arg)
"Search Favorite BibTeX entries"
(interactive "P")
(helm-bibtex arg nil "favorite "))
@ -2213,33 +2356,82 @@ List all element of the bibliography without pdf associated
)
#+end_src
** Org-Roam-Bibtex ([[https://github.com/Zaeph/org-roam-bibtex][link]])
** Deft
#+begin_src emacs-lisp
(use-package! org-roam-bibtex
:load-path "~/.config/doom/packages/org-roam-bibtex/"
(use-package! deft
:custom
(deft-directory "~/Cloud/brain/"))
#+end_src
** Org-Roam-Bibtex ([[https://github.com/Zaeph/org-roam-bibtex][link]])
Provides nice functions such as:
- =orb-find-non-ref-file=
- =orb-insert-non-ref=
- =orb-note-action=
#+begin_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)))
)
#+end_src
#+begin_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)))
#+end_src
** Org-Ref-Ox-Hugo ([[https://github.com/jethrokuan/org-ref-ox-hugo][link]])
This package is used to correctly format the bibliography and links when exporting to hugo.
#+begin_src emacs-lisp
(use-package! org-ref-ox-hugo
:load-path "~/.config/doom/packages/org-ref-ox-hugo/"
:config
(org-roam-bibtex-mode)
(setq org-roam-bibtex-preformat-keywords `("=key=" "title" "author" "year" "author-abbrev" "=type="))
(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 org-roam-bibtex-template
`(("r" "ref" plain (function org-roam-capture--get-point) ""
:file-name "${=key=}"
:head ,(concat "#+TITLE: ${title}\n"
"#+SETUPFILE ./org-notes-setup-file.org\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")
:unnarrowed t)))
(setq reference-link-class "reference-link")
(setq bibtex-entry-class "bibtex-entry")
)
#+end_src
@ -2254,7 +2446,7 @@ List all element of the bibliography without pdf associated
** Clean Output Files
#+begin_src emacs-lisp
(defun latex/clean ()
(defun tdh-latex-clean ()
"Clean LaTeX output using latexmk"
(interactive)
(async-shell-command
@ -2265,7 +2457,7 @@ List all element of the bibliography without pdf associated
))
(map! :map LaTeX-mode-map
:n ",C" 'latex/clean)
:n ",C" 'tdh-latex-clean)
(add-hook 'TeX-mode-hook #'TeX-fold-mode)
#+end_src
@ -2338,34 +2530,34 @@ List all element of the bibliography without pdf associated
** Key Bindings
#+begin_src emacs-lisp
(defun matlab-add-breakpoint ()
(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 matlab-remove-breakpoint ()
(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 matlab-list-breakpoints ()
(defun tdh-matlab-list-breakpoints ()
(interactive)
(matlab-shell-run-command (concat "dbstatus " (buffer-name))))
(defun matlab-clear-breakpoints ()
(defun tdh-matlab-clear-breakpoints ()
(interactive)
(matlab-shell-run-command (concat "dbclear in " (buffer-name))))
(defun matlab-go-to-file-directory ()
(defun tdh-matlab-go-to-file-directory ()
(interactive)
(matlab-shell-run-command (concat "cd " (file-name-directory buffer-file-name))))
#+end_src
#+begin_src emacs-lisp
(map! :map matlab-mode-map
:n ",g" 'matlab-go-to-file-directory
:n ",da" 'matlab-add-breakpoint
:n ",dr" 'matlab-remove-breakpoint
:n ",dL" 'matlab-list-breakpoints
:n ",dc" 'matlab-clear-breakpoints
: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
@ -2397,7 +2589,7 @@ Send math and source code:
| =d= | Move to Trash |
** Helping function
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.
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.
#+begin_src emacs-lisp
(defun mu4e-message-maildir-matches (msg rx)
(when rx
@ -2582,10 +2774,11 @@ Choose account label to feed msmtp -a option based on From header in Message buf
:ui
doom ; what makes DOOM look the way it does
deft
hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW
hydra
modeline ; snazzy, Atom-inspired modeline, plus API
nav-flash ; blink the current line after jumping
(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
@ -2593,7 +2786,6 @@ Choose account label to feed msmtp -a option based on From header in Message buf
unicode ; extended unicode support for various languages
vc-gutter ; vcs diff in the fringe
vi-tilde-fringe ; fringe tildes to mark beyond EOB
window-select ; visually switch windows
workspaces ; tab emulation, persistence & separate workspaces
:editor
@ -2606,7 +2798,7 @@ Choose account label to feed msmtp -a option based on From header in Message buf
:emacs
(dired +icons) ; making dired pretty [functional]
electric ; smarter, keyword-based electric-indent
ibuffer ; interactive buffer management
(ibuffer +icons) ; interactive buffer management
vc ; version-control and Emacs, sitting in a tree
:term
@ -2676,7 +2868,9 @@ Choose account label to feed msmtp -a option based on From header in Message buf
(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)
#+end_src

View File

@ -113,6 +113,14 @@ $0
\end{$1}
#+end_src
** Caption
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/caption
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Caption
# --
#+caption: $0
#+end_src
** Block
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/block
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
@ -147,18 +155,6 @@ $0
$0
#+end_src
** TODO Name Caption Figure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/name-caption-figure
#name: name-caption-figure
#key: ncf
# --
#+name: fig:${1:name}
#+caption: ${2:Caption}
[[${3:`(read-file-name "File: ")`}]]
$0
#+end_src
** Bibliography with completion
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/bib
#name: bibliography with completion
@ -177,7 +173,7 @@ cite:${1:$$(completing-read
(let ((bibtex-files (org-ref-find-bibliography)))(bibtex-global-key-alist)))}
#+end_src
** TODO Ref
** Ref
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/ref
#name: org-ref ref link with completion
#key: ref
@ -229,8 +225,7 @@ $0
# --
#+name: fig:${1:figure_name}
#+caption: ${2:Figure caption}
#+attr_latex: :${3:scale 1}
[[file:${4:figs/}$1.${5:pdf}]]
[[file:${3:figs/}$1.${4:pdf}]]
$0
#+end_src
@ -250,128 +245,6 @@ $0
\left$1 $0 \right$2
#+end_src
** Mconfig
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mconfig
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Configuration-Header
# --
#+PROPERTY: header-args:matlab :session *MATLAB*
#+PROPERTY: header-args:matlab+ :tangle ${1:filename}.m
#+PROPERTY: header-args:matlab+ :comments org
#+PROPERTY: header-args:matlab+ :exports both
#+PROPERTY: header-args:matlab+ :results none
#+PROPERTY: header-args:matlab+ :eval no-export
#+PROPERTY: header-args:matlab+ :noweb yes
#+PROPERTY: header-args:matlab+ :mkdirp yes
#+PROPERTY: header-args:matlab+ :output-dir ${2:figs}
$0
#+end_src
** Mdescription
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mdescription
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Measurement-Description
# --
,* Measurement description
,** Setup :ignore:
*Setup*:
,** Goal :ignore:
*Goal*:
,** Measurements :ignore:
*Measurements*:
Three measurements are done:
| Measurement File | Description |
|-------------------------+------------------------------|
| =mat/data_${1:001}.mat= | $2 |
Each of the measurement =mat= file contains one =data= array with 3 columns:
| Column number | Description |
|---------------+-------------------|
| 1 | $3 |
| 2 | $4 |
| 3 | Time |
$0
#+end_src
** Mfigure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mfigure
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Figure
# --
,#+begin_src matlab :tangle no :exports results :results file replace
exportFig('figs/${1:filename}.pdf', 'width', '${2:full}', 'height', '${3:full}')
,#+end_src
,#+name: fig:$1
,#+caption: $0
,#+RESULTS:
[[file:figs/$1.png]]
#+end_src
** Mfunction
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mfunction
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Function
# --
,* ${1:Function Name}
:PROPERTIES:
:header-args:matlab+: :tangle src/${2:matlab_file_name}.m
:header-args:matlab+: :comments none :mkdirp yes :eval no
:END:
<<sec:$2>>
This Matlab function is accessible [[file:src/$2.m][here]].
,#+begin_src matlab
function [${4:in_data}] = $2(${3:in_data})
% $2 - $0
%
% Syntax: [$4] = $2($3)
%
% Inputs:
% - $3 -
%
% Outputs:
% - $4 -
end
,#+end_src
#+end_src
** Mheader
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mheader
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Header
# --
,* ${1:Heading Name}
:PROPERTIES:
:header-args:matlab+: :tangle matlab/${2:matlab_file_name}.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
<<sec:$2>>
,** ZIP file containing the data and matlab files :ignore:
,#+begin_src bash :exports none :results none
if [ matlab/$2.m -nt data/$2.zip ]; then
cp matlab/$2.m $2.m;
zip data/$2 \
mat/data.mat \
$2.m
rm $2.m;
fi
,#+end_src
,#+begin_note
All the files (data and Matlab scripts) are accessible [[file:data/$2.zip][here]].
,#+end_note
$0
#+end_src
** Minipage
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/minipage
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
@ -397,34 +270,6 @@ $0
#+END_EXPORT
#+end_src
** Minit
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/minit
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Init
# --
,** Matlab Init :noexport:ignore:
,#+begin_src matlab :tangle no :exports none :results silent :noweb yes :var current_dir=(file-name-directory buffer-file-name)
<<matlab-dir>>
,#+end_src
,#+begin_src matlab :exports none :results silent :noweb yes
<<matlab-init>>
,#+end_src
$0
#+end_src
** Mtable
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mtable
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Table
# --
,#+begin_src matlab :exports results :results value table replace :tangle no :post addhdr(*this*)
data2orgtable(${1:data}, {${2:'rowlabel'}}, {${3:'collabel'}}, ' %.1f ');
,#+end_src
$0
#+end_src
** Multicolumn
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/multicolumn
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
@ -532,7 +377,7 @@ $1
,#+begin_src emacs-lisp :tangle user-init.el
$1
,#+end_src
#+end_src
#+end_Sec
** Wrap
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/wrap
@ -542,3 +387,154 @@ $1
#+attr_latex: :float wrap
$0
#+end_src
** Matlab Specific
*** Mconfig
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mconfig
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Configuration-Header
# --
#+PROPERTY: header-args:matlab :session *MATLAB*
#+PROPERTY: header-args:matlab+ :tangle ${1:filename}.m
#+PROPERTY: header-args:matlab+ :comments org
#+PROPERTY: header-args:matlab+ :exports both
#+PROPERTY: header-args:matlab+ :results none
#+PROPERTY: header-args:matlab+ :eval no-export
#+PROPERTY: header-args:matlab+ :noweb yes
#+PROPERTY: header-args:matlab+ :mkdirp yes
#+PROPERTY: header-args:matlab+ :output-dir ${2:figs}
$0
#+end_src
*** Mdescription
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mdescription
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Measurement-Description
# --
,* Measurement description
,** Setup :ignore:
*Setup*:
,** Goal :ignore:
*Goal*:
,** Measurements :ignore:
*Measurements*:
Three measurements are done:
| Measurement File | Description |
|-------------------------+------------------------------|
| =mat/data_${1:001}.mat= | $2 |
Each of the measurement =mat= file contains one =data= array with 3 columns:
| Column number | Description |
|---------------+-------------------|
| 1 | $3 |
| 2 | $4 |
| 3 | Time |
$0
#+end_src
*** Mfigure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mfigure
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Figure
# --
,#+begin_src matlab :tangle no :exports results :results file replace
exportFig('figs/${1:filename}.pdf', 'width', '${2:full}', 'height', '${3:full}');
,#+end_src
,#+name: fig:$1
,#+caption: $0
,#+RESULTS:
[[file:figs/$1.png]]
#+end_src
*** Mfunction
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mfunction
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Function
# --
,* ${1:Function Name}
:PROPERTIES:
:header-args:matlab+: :tangle src/${2:matlab_file_name}.m
:header-args:matlab+: :comments none :mkdirp yes :eval no
:END:
<<sec:$2>>
This Matlab function is accessible [[file:src/$2.m][here]].
,#+begin_src matlab
function [${4:in_data}] = $2(${3:in_data})
% $2 - $0
%
% Syntax: [$4] = $2($3)
%
% Inputs:
% - $3 -
%
% Outputs:
% - $4 -
end
,#+end_src
#+end_src
*** Mheader
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mheader
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Header
# --
,* ${1:Heading Name}
:PROPERTIES:
:header-args:matlab+: :tangle matlab/${2:matlab_file_name}.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
<<sec:$2>>
,** ZIP file containing the data and matlab files :ignore:
,#+begin_src bash :exports none :results none
if [ matlab/$2.m -nt data/$2.zip ]; then
cp matlab/$2.m $2.m;
zip data/$2 \
mat/data.mat \
$2.m
rm $2.m;
fi
,#+end_src
,#+begin_note
All the files (data and Matlab scripts) are accessible [[file:data/$2.zip][here]].
,#+end_note
$0
#+end_src
*** Minit
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/minit
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Init
# --
,** Matlab Init :noexport:ignore:
,#+begin_src matlab :tangle no :exports none :results silent :noweb yes :var current_dir=(file-name-directory buffer-file-name)
<<matlab-dir>>
,#+end_src
,#+begin_src matlab :exports none :results silent :noweb yes
<<matlab-init>>
,#+end_src
$0
#+end_src
*** Mtable
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/mtable
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Table
# --
,#+begin_src matlab :exports results :results value table replace :tangle no :post addhdr(*this*)
data2orgtable(${1:data}, {${2:'rowlabel'}}, {${3:'collabel'}}, ' %.1f ');
,#+end_src
$0
#+end_src