literate-dotfiles/dotfiles/doom.org

3437 lines
120 KiB
Org Mode
Raw Normal View History

2020-01-12 00:19:16 +01:00
#+TITLE: Doom Emacs Configuration
:DRAWER:
#+STARTUP: overview
#+LANGUAGE: en
#+EMAIL: dehaeze.thomas@gmail.com
#+AUTHOR: Dehaeze Thomas
#+HTML_LINK_HOME: ./index.html
#+HTML_LINK_UP: ./index.html
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="./css/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="./css/readtheorg.css"/>
#+HTML_HEAD: <script type="text/javascript" src="./js/jquery.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="./js/bootstrap.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="./js/jquery.stickytableheaders.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="./js/readtheorg.js"></script>
2020-01-28 21:31:08 +01:00
#+PROPERTY: header-args :tangle ~/.config/doom/config.el :results none :padline no
2020-01-12 00:19:16 +01:00
:END:
2020-03-19 10:09:30 +01:00
* Introduction and Resources :ignore:
2020-01-12 00:19:16 +01:00
https://medium.com/urbint-engineering/emacs-doom-for-newbies-1f8038604e3b
https://noelwelsh.com/posts/2019-01-10-doom-emacs.html
https://dotdoom.netlify.com/config.html
https://emacs.christianbaeuerlein.com/
https://github.com/nmartin84/.doom.d/blob/master/config.org
2020-01-12 00:19:16 +01:00
Documentation:
- https://github.com/hlissner/doom-emacs/blob/develop/docs/index.org
* Useful Bindings
2020-04-01 10:27:25 +02:00
- =align-regexp=: equivalent of [[https://github.com/junegunn/vim-easy-align][vim-easy-align]]. Very useful to align tables and stuff
2020-01-12 00:19:16 +01:00
| =spc := | Execute command |
| =spc <= | Switch to buffer |
| =spc X= | org-capture |
| =spc s s= | Search in buffer with swiper |
| =spc s p= | Search in project |
| =spc p p= | Switch project |
| =spc p t= | TODOs in project |
| =spc o f= | Create frame |
| =spc o e= | Toggle Eshell |
| =spc n l= | Store link |
| =spc g g= | Magit status |
| =spc f r= | Open recent file |
| =spc b B= | Switch to buffer |
| =spc b d= | Kill current buffer |
| =spc b i= | ibuffer |
| =spc tab .= | Switch to workspace |
| =spc tab n= | New workspace |
| =spc tab r= | Rename workspace |
| =spc m A= | org-archive-subtree |
| =spc m I= | org-toggle-inline-images |
| =spc m d= | org-deadline |
| =spc m e= | org-export-dispatch |
| =spc m o= | org-set-property |
| =spc m s= | org-schedule |
| =spc m t= | org-todo |
| 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 |
* Personal Information
#+begin_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")
#+end_src
* Doom Config
#+begin_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))
#+end_src
#+begin_src emacs-lisp
;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. These are the defaults.
(setq doom-theme 'doom-gruvbox)
#+end_src
#+begin_src emacs-lisp
(setq display-line-numbers-type t)
#+end_src
* Evil
#+begin_src emacs-lisp
(after! evil
(map! :m "-" #'dired-jump))
#+end_src
#+begin_src emacs-lisp
(map!
(:after evil
:en "C-h" #'evil-window-left
:en "C-j" #'evil-window-down
:en "C-k" #'evil-window-up
:en "C-l" #'evil-window-right))
#+end_src
2020-03-22 19:42:41 +01:00
Make movement keys work like they should
2020-03-01 22:09:27 +01:00
#+begin_src emacs-lisp
2020-03-22 19:42:41 +01:00
(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)
2020-03-01 22:09:27 +01:00
#+end_src
2020-03-22 19:42:41 +01:00
Make horizontal movement cross lines
2020-03-01 22:09:27 +01:00
#+begin_src emacs-lisp
(setq-default evil-cross-lines t)
#+end_src
* Which Key
2020-01-12 00:19:16 +01:00
#+begin_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))
#+end_src
* Basic
** Visual
Automatic line wrap.
#+begin_src emacs-lisp
2020-01-28 21:31:08 +01:00
(global-visual-line-mode nil)
2020-01-12 00:19:16 +01:00
#+end_src
Turn off auto-fill mode that add line breaks.
#+begin_src emacs-lisp
(auto-fill-mode -1)
2020-01-28 21:31:08 +01:00
(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))
2020-01-12 00:19:16 +01:00
#+end_src
** Change default alert backend
#+begin_src emacs-lisp
(setq alert-default-style 'libnotify)
#+end_src
** Lockfiles
#+begin_src emacs-lisp
(setq create-lockfiles nil)
#+end_src
2020-01-28 21:31:08 +01:00
** Disable highlight of current line
#+begin_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
))
2020-01-28 21:31:08 +01:00
#+end_src
** Remap =jump-forward= key binding
#+begin_src emacs-lisp
(with-eval-after-load 'better-jumper
(map!
:desc "Jump Forward"
"C-i" #'better-jumper-jump-forward))
#+end_src
2020-01-12 00:19:16 +01:00
* Magit
#+begin_src emacs-lisp
(setenv "GIT_ASKPASS" "git-gui--askpass")
(setq magit-diff-refine-hunk 'all)
#+end_src
* Org Mode
- http://cachestocaches.com/2016/9/my-workflow-org-agenda/
- http://doc.norang.ca/org-mode.html#TodoKeywords
- https://emacs.cafe/emacs/orgmode/gtd/2017/06/30/orgmode-gtd.html
** Org General Config
#+begin_src emacs-lisp
(after! org
(setq org-directory "~/Cloud/org/")
2020-01-12 00:19:16 +01:00
2020-03-01 22:09:27 +01:00
;; Replace the content marker, “⋯”, with a nice unicode arrow.
(setq org-ellipsis " ⤵")
(setq org-default-notes-file "~/Cloud/org/refile.org")
2020-01-12 00:19:16 +01:00
2020-03-01 22:09:27 +01:00
;; 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)
2020-01-12 00:19:16 +01:00
;; Indent according to the outline structure
(setq org-startup-indented t)
2020-01-12 00:19:16 +01:00
;; Record the information of when the task was marked as DONE
(setq org-log-done 'time)
2020-03-01 22:09:27 +01:00
;; begining of line on heading behavior
(setq org-special-ctrl-a/e nil)
)
2020-01-12 00:19:16 +01:00
#+end_src
TAB was changed to toggle only the visibility state of the current subtree, rather than cycle through it recursively. This can be reversed with:
#+begin_src emacs-lisp
(after! evil-org
(remove-hook 'org-tab-first-hook #'+org-cycle-only-current-subtree-h))
#+end_src
** Org Inline Images
Display the real size of images and not the one set with =attr_latex: :width \linewidth= for instance.
#+begin_src emacs-lisp
(after! org
(setq org-image-actual-width t))
#+end_src
2020-01-12 00:19:16 +01:00
** Org Links
#+begin_src emacs-lisp
(after! org
2020-03-01 22:09:27 +01:00
(map! :map org-mode-map "C-c l" 'org-store-link)
(setq org-link-abbrev-alist
'(("bib" . "~/Cloud/thesis/ressources/references.bib::%s")
("notes" . "~/Cloud/thesis/ressources/notes/notes.org::#%s")
("papers" . "~/Cloud/thesis/ressources/pdfs/%s.pdf")))
)
2020-01-12 00:19:16 +01:00
#+end_src
** Org Tagging
#+begin_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))))
)
2020-01-12 00:19:16 +01:00
#+end_src
** Org Refile
#+begin_src emacs-lisp
(after! org
(setq org-refile-targets '((org-agenda-files . (:maxlevel . 6))))
)
2020-01-12 00:19:16 +01:00
#+end_src
** Org TODO
#+begin_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
)
2020-01-12 00:19:16 +01:00
#+end_src
** Archive subtrees under the same hierarchy as original in the archive files
https://gist.github.com/Fuco1/e86fb5e0a5bb71ceafccedb5ca22fcfb
#+begin_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))))))))
)
2020-01-12 00:19:16 +01:00
#+end_src
** Org Agenda
*** General configuration
#+begin_src emacs-lisp
(after! org
(map! :map org-mode-map "C-c a" 'org-agenda)
2020-01-12 00:19:16 +01:00
;; File to save todo items
(setq org-agenda-files (list "~/Cloud/org/"))
2020-01-12 00:19:16 +01:00
;; Include archived files
(setq org-agenda-archives-mode t)
2020-01-12 00:19:16 +01:00
;; 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)
2020-01-12 00:19:16 +01:00
;; Set colours for priorities
2020-02-14 16:08:11 +01:00
(setq org-priority-faces '((?A . (:foreground "#FB4934"))
(?B . (:foreground "#FABD2F"))
(?C . (:foreground "#98971A"))))
2020-01-12 00:19:16 +01:00
;; Open agenda in current window
(setq org-agenda-window-setup 'current-window)
2020-01-12 00:19:16 +01:00
(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"))
)
2020-01-12 00:19:16 +01:00
)
#+end_src
*** Org Agenda Custom Views
https://blog.aaronbieber.com/2016/09/24/an-agenda-for-life-with-org-mode.html
#+begin_src emacs-lisp
(after! org-agenda
2020-03-01 22:09:27 +01:00
(defun tdh-org-agenda-skip-scheduled ()
2020-03-16 12:15:59 +01:00
(org-agenda-skip-entry-if 'scheduled 'deadline 'regexp "\n]+>"))
(setq org-agenda-custom-commands
2020-03-16 12:15:59 +01:00
'(("w" "Work"
((org-ql-block '(and (tags "@work")
(todo "TODO")
(priority "A"))
2020-03-19 10:08:02 +01:00
((org-ql-block-header "Important TODOs")))
2020-03-16 12:15:59 +01:00
(org-ql-block '(and (tags "@work")
(todo "TODO")
(priority "B"))
2020-03-19 10:08:02 +01:00
((org-ql-block-header "TODOs")))
2020-03-16 12:15:59 +01:00
(org-ql-block '(and (tags "@work")
(todo "TODO")
(priority "C"))
2020-03-19 10:08:02 +01:00
((org-ql-block-header "Not important TODOs")))))
2020-03-16 12:15:59 +01:00
("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"))
2020-03-19 10:08:02 +01:00
((org-ql-block-header "Questions to Christophe")))
2020-03-16 12:15:59 +01:00
(org-ql-block '(and (todo "QUES")
(tags "@veijo"))
2020-03-19 10:08:02 +01:00
((org-ql-block-header "Questions to Veijo")))
2020-03-16 12:15:59 +01:00
(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/thesis/ressources/notes/"))))
("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/thesis/ressources/notes/")))))
)
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-02-14 16:07:18 +01:00
** Org Fancy Priority
#+begin_src emacs-lisp
(use-package! org-fancy-priorities ; priority icons
:hook (org-mode . org-fancy-priorities-mode)
:config (setq org-fancy-priorities-list '("■" "■" "■")))
#+end_src
2020-01-12 00:19:16 +01:00
** Org Notification based on calendar event
https://emacs.stackexchange.com/questions/3844/good-methods-for-setting-up-alarms-audio-visual-triggered-by-org-mode-events
#+begin_src emacs-lisp
(after! org-agenda
(setq appt-message-warning-time 5)
2020-03-01 22:09:27 +01:00
(defun tdh-org-agenda-to-appt ()
(interactive)
(setq appt-time-msg-list nil)
(org-agenda-to-appt))
2020-03-01 22:09:27 +01:00
(tdh-org-agenda-to-appt)
; Display appointments as a window manager notification
2020-03-01 22:09:27 +01:00
(setq appt-disp-window-function 'tdh-appt-display)
(setq appt-delete-window-function (lambda () t))
2020-03-01 22:09:27 +01:00
(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)
2020-03-01 22:09:27 +01:00
(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))))
2020-03-01 22:09:27 +01:00
(start-process "tdh-appt-notification-app" nil tdh-appt-notification-app (nth i min-to-app) (nth i msg)))))
)
2020-01-12 00:19:16 +01:00
#+end_src
*** appt-notification script
:PROPERTIES:
:header-args: :tangle ~/.config/doom/bin/appt-notification
:header-args+: :comments none :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
#+begin_src bash
TIME="$1"TODO
MSG="$2"
dunstify --replace=85401 "Event in $TIME minutes" "$MSG"
#+end_src
** Org Structure Template
#+begin_src emacs-lisp
(after! org
(setq org-structure-template-alist
2020-03-01 22:09:27 +01:00
'(("c" . "center")
("C" . "comment")
("m" . "src matlab\n")
("l" . "src emacs-lisp\n")
("i" . "important")
("e" . "example")
("q" . "quote")
("s" . "src")))
2020-01-12 00:19:16 +01:00
)
#+end_src
** Org Capture
Documentation:
- Template elements: https://orgmode.org/manual/Template-elements.html#Template-elements
- 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
(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
)
)))
)
2020-01-12 00:19:16 +01:00
#+end_src
** Org Export
*** Basic
#+begin_src emacs-lisp
(after! org
;; How many levels of headline to export
(setq org-export-headline-levels 4)
2020-01-12 00:19:16 +01:00
;; Authorize BIND to set local variables
(setq org-export-allow-bind-keywords t)
2020-01-12 00:19:16 +01:00
(setq org-odt-preferred-output-format "doc")
)
#+end_src
2020-01-12 00:19:16 +01:00
*** Do not export headline with the =:ignore:= tag
#+begin_src emacs-lisp
2020-01-12 00:19:16 +01:00
;; Used to not export headings with :ignore: tag
(after! org
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines)))
2020-01-12 00:19:16 +01:00
#+end_src
*** Ox Latex Subfigure package
#+begin_src emacs-lisp
2020-03-19 10:38:23 +01:00
(use-package! ox-latex-subfigure
:after org
:config (require 'ox-latex-subfigure))
2020-01-12 00:19:16 +01:00
#+end_src
*** Clear page before heading
https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-heading/30892
#+begin_src emacs-lisp
(after! org
(defun org/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))))
2020-01-12 00:19:16 +01:00
(defun org/ensure-latex-clearpage (headline backend info)
(when (org-export-derived-backend-p backend 'latex)
(let ((elmnt (org/get-headline-string-element headline backend info)))
(when (and elmnt (org-element-property :CLEARPAGE elmnt))
(concat "\\clearpage\n" headline)))))
2020-01-12 00:19:16 +01:00
(add-to-list 'org-export-filter-headline-functions
'org/ensure-latex-clearpage)
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-03-22 20:12:48 +01:00
*** HTML Export
2020-01-12 00:19:16 +01:00
**** MathJax
#+begin_src emacs-lisp
(after! org
(setq org-html-mathjax-template
"<script>
MathJax = {
tex: { macros: {
bm: [\"\\\\boldsymbol{#1}\",1],
}
2020-01-29 15:28:53 +01:00
}
};
</script>
<script type=\"text/javascript\"
src=\"%PATH\"></script>")
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-01-29 15:28:53 +01:00
#+begin_src emacs-lisp
(after! org
(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")))
)
2020-01-29 15:28:53 +01:00
#+end_src
2020-01-12 00:19:16 +01:00
**** Export with css class instead of inline css
#+begin_src emacs-lisp
(after! org
(setq org-html-htmlize-output-type 'css))
2020-01-12 00:19:16 +01:00
#+end_src
**** TODO MP4 movies
#+begin_src emacs-lisp :tangle no
(after! org
(setq org-html-html5-fancy t)
(setq org-html-doctype "xhtml-strict")
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-03-01 22:09:27 +01:00
**** TODO Ensuring useful HTML Anchors
- [ ] https://github.com/alhassy/emacs.d
- [ ] https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors
This is not working
#+begin_src emacs-lisp :tangle no
(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)))
#+end_src
**** TODO Folded Drawers
Adapt this from https://github.com/alhassy/emacs.d to do something similar for source blocks.
#+begin_src emacs-lisp :tangle no
(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)
#+end_src
2020-01-12 00:19:16 +01:00
** Org LaTeX
2020-03-22 19:42:41 +01:00
*** LaTeX Fragments
#+begin_src emacs-lisp
(after! org
;; Highligh latex parts in org mode
(setq org-highlight-latex-and-related '(native))
;; Use F9 to globally generate all the latex fragments
2020-03-22 19:42:41 +01:00
(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"
2020-04-06 17:10:39 +02:00
: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)
2020-03-22 19:42:41 +01:00
;; 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)))
)
#+end_src
2020-01-12 00:19:16 +01:00
*** LaTeX Classes
#+begin_src emacs-lisp
(after! org
2020-01-12 00:19:16 +01:00
;; Custom classes to use when exporting to latex
(add-to-list 'org-latex-classes
2020-03-16 12:15:59 +01:00
'("beamer"
2020-01-12 00:19:16 +01:00
,(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}"))
)
)
2020-01-12 00:19:16 +01:00
#+end_src
*** Default added packages
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
(after! org
2020-01-12 00:19:16 +01:00
;; Add packages by default
(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))
)
#+end_src
2020-01-12 00:19:16 +01:00
*** Some configurations
#+begin_src emacs-lisp
(after! org
2020-01-12 00:19:16 +01:00
;; Setup default option for image size when exporting to LaTeX
2020-03-19 10:08:27 +01:00
(setq org-latex-image-default-scale "")
(setq org-latex-image-default-width "")
(setq org-latex-image-default-height "")
(setq org-latex-image-default-option "")
2020-01-12 00:19:16 +01:00
;; 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)
;; 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"))
)
2020-01-12 00:19:16 +01:00
#+end_src
*** Beamer
Bold Text
#+begin_src emacs-lisp
(after! org
2020-03-01 22:09:27 +01:00
(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)))
2020-01-12 00:19:16 +01:00
2020-03-01 22:09:27 +01:00
(add-to-list 'org-export-filter-bold-functions 'tdh-my-beamer-bold)
)
2020-01-12 00:19:16 +01:00
#+end_src
Special Environments
- [ ] Make some comment those special environments
#+begin_src emacs-lisp
(after! org
2020-01-12 00:19:16 +01:00
(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}"
"}"))
)
2020-01-12 00:19:16 +01:00
#+end_src
*** TODO Custom Export - Add Page and Label for LaTeX export
https://emacs.stackexchange.com/questions/156/emacs-function-to-convert-an-arbitrary-org-property-into-an-arbitrary-string-na?rq=1
#+begin_src emacs-lisp :tangle no
2020-03-01 22:09:27 +01:00
(defcustom tdh-org-property-mapping
'((latex ("CUSTOM_PAGE" . tdh-insert-org-page-latex)
("CUSTOM_LABEL" . tdh-insert-org-label-latex)))
2020-01-12 00:19:16 +01:00
"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)))))
#+end_src
#+begin_src emacs-lisp :tangle no
2020-03-01 22:09:27 +01:00
(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
2020-01-12 00:19:16 +01:00
(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)"
2020-03-01 22:09:27 +01:00
(let ((map (cdr (assoc backend tdh-org-property-mapping)))
2020-01-12 00:19:16 +01:00
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)))))))))
2020-03-01 22:09:27 +01:00
(add-hook 'org-export-before-processing-hook #'tdh-replace-org-property)
2020-01-12 00:19:16 +01:00
#+end_src
#+begin_src emacs-lisp :tangle no
2020-03-01 22:09:27 +01:00
(defun tdh-insert-org-label-latex (label)
2020-01-12 00:19:16 +01:00
"Insert \"\\\\label{LABEL}\\n\" after the :PROPERTY: drawer."
(search-forward-regexp org-property-end-re)
(forward-char 1)
(insert (format "\\label{%s}\n" label)))
2020-03-01 22:09:27 +01:00
(defun tdh-insert-org-page-latex (page)
2020-01-12 00:19:16 +01:00
"Insert \"\\\\page{PAGE}\\n\" after the :PROPERTY: drawer."
(search-forward-regexp org-property-end-re)
(forward-char 1)
(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
#+begin_src emacs-lisp
(after! org
(defun 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 #'org-renumber-environment)
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-03-16 12:15:59 +01:00
** LaTeX macro both for LaTeX and HTML export
https://www.reddit.com/r/orgmode/comments/7u2n0h/tip_for_defining_latex_macros_for_use_in_both/
#+begin_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#+HTML_HEAD_EXTRA: <div style=\"display: none\"> \\(\n"
(prefix-all-lines "#+HTML_HEAD_EXTRA: " body)
"\n#+HTML_HEAD_EXTRA: \\)</div>\n"))
)
#+end_src
2020-03-22 20:12:48 +01:00
** TODO View PDF in org mode
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp :tangle no
2020-03-01 22:09:27 +01:00
(defun tdh-org-include-img-from-pdf (&rest _)
2020-01-12 00:19:16 +01:00
"Convert pdf files to image files in org-mode bracket links.
# ()convertfrompdf:t # This is a special comment; tells that the upcoming
# link points to the to-be-converted-to file.
# If you have a foo.pdf that you need to convert to foo.png, use the
# foo.png file name in the link.
[[./foo.png]]
"
(interactive)
(if (executable-find "convert")
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^[ \t]*#\\s-+()convertfrompdf\\s-*:\\s-*t"
nil :noerror)
;; Keep on going to the next line till it finds a line with bracketed
;; file link.
(while (progn
(forward-line 1)
(not (looking-at org-bracket-link-regexp))))
;; Get the sub-group 1 match, the link, from `org-bracket-link-regexp'
(let ((link (match-string-no-properties 1)))
(when (stringp link)
(let* ((imgfile (expand-file-name (file-name-sans-extension link)))
(pdffile (expand-file-name
(concat imgfile
"." "pdf")))
(cmd (concat "pdftocairo -png -transp -singlefile "
pdffile " " imgfile)))
(message "%s" imgfile)
(when (and (file-readable-p pdffile)
(file-newer-than-file-p pdffile imgfile))
;; This block is executed only if pdffile is newer than
;; imgfile or if imgfile does not exist.
(shell-command cmd)
(message "%s" cmd)))))))
(user-error "`convert' executable (part of Imagemagick) is not found")))
2020-03-01 22:09:27 +01:00
(add-hook 'org-export-before-processing-hook #'tdh-org-include-img-from-pdf)
2020-01-12 00:19:16 +01:00
#+end_src
#+begin_src emacs-lisp :tangle no
(add-to-list 'image-type-file-name-regexps '("\\.pdf\\'" . imagemagick))
(add-to-list 'image-file-name-extensions "pdf")
(setq imagemagick-types-inhibit (remove 'PDF imagemagick-types-inhibit))
#+end_src
#+begin_src emacs-lisp :tangle no
2020-03-01 22:09:27 +01:00
(defun tdh-latex-filter-nobreaks (text backend info)
2020-01-12 00:19:16 +01:00
"Ensure \" \" are properly handled in LaTeX export."
(when (org-export-derived-backend-p backend 'latex)
(replace-regexp-in-string " " "~" text)))
(add-to-list 'org-export-filter-plain-text-functions
2020-03-01 22:09:27 +01:00
'tdh-latex-filter-nobreaks)
2020-01-12 00:19:16 +01:00
#+end_src
#+begin_src emacs-lisp :tangle no
(setq image-file-name-extensions
(quote
("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm" "xpm" "pbm" "pgm" "ppm" "pnm" "svg" "pdf" "bmp")))
(setq org-imagemagick-display-command "convert -density 600 \"%s\" -thumbnail \"%sx%s>\" \"%s\"")
(defun org-display-inline-images (&optional include-linked refresh beg end)
"Display inline images.
Normally only links without a description part are inlined, because this
is how it will work for export. When INCLUDE-LINKED is set, also links
with a description part will be inlined. This
can be nice for a quick
look at those images, but it does not reflect what exported files will look
like.
When REFRESH is set, refresh existing images between BEG and END.
This will create new image displays only if necessary.
BEG and END default to the buffer boundaries."
(interactive "P")
(unless refresh
(org-remove-inline-images)
(if (fboundp 'clear-image-cache) (clear-image-cache)))
(save-excursion
(save-restriction
(widen)
(setq beg (or beg (point-min)) end (or end (point-max)))
(goto-char beg)
(let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?"
(substring (org-image-file-name-regexp) 0 -2)
"\\)\\]" (if include-linked "" "\\]")))
old file ov img)
(while (re-search-forward re end t)
(setq old (get-char-property-and-overlay (match-beginning 1)
'org-image-overlay)
file (expand-file-name
(concat (or (match-string 3) "") (match-string 4))))
(when (file-exists-p file)
(let ((file-thumb (format "%s%s_thumb.png" (file-name-directory file) (file-name-base file))))
(if (file-exists-p file-thumb)
(let ((thumb-time (nth 5 (file-attributes file-thumb 'string)))
(file-time (nth 5 (file-attributes file 'string))))
(if (time-less-p thumb-time file-time)
(shell-command (format org-imagemagick-display-command
file org-image-actual-width org-image-actual-width file-thumb) nil nil)))
(shell-command (format org-imagemagick-display-command
file org-image-actual-width org-image-actual-width file-thumb) nil nil))
(if (and (car-safe old) refresh)
(image-refresh (overlay-get (cdr old) 'display))
(setq img (save-match-data (create-image file-thumb)))
(when img
(setq ov (make-overlay (match-beginning 0) (match-end 0)))
(overlay-put ov 'display img)
(overlay-put ov 'face 'default)
(overlay-put ov 'org-image-overlay t)
(overlay-put ov 'modification-hooks
(list 'org-display-inline-remove-overlay))
(push ov org-inline-image-overlays))))))))))
#+end_src
Two options:
- work with =.png= file extension and only replace with =.pdf= when exporting to LaTeX if the corresponding file exists
- work with =.pdf= file, add a special function to display =.pdf= files (using =convert= or =pdftocairo=). Change to =.png= when exporting to html
Let's try the first solution.
#+begin_src emacs-lisp :tangle no
2020-03-01 22:09:27 +01:00
(defun tdh-change-png-to-pdf (text backend info)
2020-01-12 00:19:16 +01:00
"Change png images to pdf images when existing"
(when (org-export-derived-backend-p backend 'latex)
(let ((text (replace-regexp-in-string "[^\\w]\\(:\\)[^\n\t\r]+\\(:\\)[^\\w]" "<mark>" text nil nil 1 nil)))
(replace-regexp-in-string "[^\\w]\\(<mark>\\)[^\n\t\r]+\\(:\\)[^\\w]" "</mark>" text nil nil 2 nil))))
2020-03-01 22:09:27 +01:00
(add-to-list 'org-export-filter-plain-text-fucntions 'tdh-html-mark-tag)
2020-01-12 00:19:16 +01:00
#+end_src
#+begin_src emacs-lisp :tangle no
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^[ \t]*#\\s-+()convertfrompdf\\s-*:\\s-*t"
nil :noerror)
;; Keep on going to the next line till it finds a line with bracketed
;; file link.
(while (progn
(forward-line 1)
(not (looking-at org-bracket-link-regexp))))
;; Get the sub-group 1 match, the link, from `org-bracket-link-regexp'
(let ((link (match-string-no-properties 1)))
(when (stringp link)
(let* ((imgfile (expand-file-name link))
(pdffile (expand-file-name
(concat (file-name-sans-extension imgfile)
"." "pdf")))
(cmd (concat "convert -density 96 -quality 85 "
pdffile " " imgfile)))
(when (and (file-readable-p pdffile)
(file-newer-than-file-p pdffile imgfile))
;; This block is executed only if pdffile is newer than
;; imgfile or if imgfile does not exist.
(shell-command cmd)
(message "%s" cmd)))))))
#+end_src
** Org Ref
Ressources:
- https://github.com/tmalsburg/helm-bibtex
- https://github.com/jkitchin/org-ref
- https://www.reddit.com/r/emacs/comments/4gudyw/help_me_with_my_orgmode_workflow_for_notetaking/
2020-03-19 10:09:30 +01:00
Nice Functions:
- =org-ref-insert-ref-link=
- =org-ref-helm-insert-cite-link=
- =org-ref-list-of-figures=
- =org-ref-find-bad-citations=
- =org-ref-clean-bibtex-entry=
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-02-14 16:08:11 +01:00
(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/thesis/ressources/notes")
(setq org-ref-bibliography-notes "~/Cloud/thesis/ressources/notes")
;; Bibliography File
(setq reftex-default-bibliography '("~/Cloud/thesis/ressources/references.bib"))
(setq org-ref-default-bibliography '("~/Cloud/thesis/ressources/references.bib"))
;; Folder where all the pdf are located
(setq org-ref-pdf-directory "~/Cloud/thesis/ressources/pdfs")
;; Tell org-ref to let helm-bibtex find notes for it
(setq org-ref-notes-function
2020-03-19 10:10:11 +01:00
(lambda (thekey)
(let ((bibtex-completion-bibliography (org-ref-find-bibliography)))
(bibtex-completion-edit-notes
(list (car (org-ref-get-bibtex-key-and-file thekey)))))))
2020-02-14 16:08:11 +01:00
;; 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)
2020-03-16 12:15:59 +01:00
(add-to-list 'org-ref-helm-user-candidates
2020-03-19 10:10:11 +01:00
'("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)
2020-03-16 12:15:59 +01:00
(add-to-list 'org-ref-helm-user-candidates
2020-03-19 10:10:11 +01:00
'("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)
2020-03-19 10:09:47 +01:00
(map!
:map org-mode-map
(:desc "Insert Link"
:ni "C-c i" #'org-ref-insert-ref-link))
2020-03-19 10:09:47 +01:00
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-03-16 12:15:59 +01:00
#+begin_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))))
#+end_src
2020-01-12 00:19:16 +01:00
** Org Noter
- https://github.com/weirdNox/org-noter
#+begin_src emacs-lisp
2020-02-14 16:08:11 +01:00
(use-package! org-noter
:defer t
:after (:any org pdf-view)
2020-02-14 16:08:11 +01:00
: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/thesis/ressources/notes")
(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))
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-01 10:27:25 +02:00
** Org Roam
#+begin_src emacs-lisp
(use-package! org-roam
:config
(setq org-roam-directory "~/Cloud/org-roam/")
(setq org-roam-completion-system 'helm)
)
#+end_src
2020-03-01 23:04:12 +01:00
** Org Projects
#+begin_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)
2020-03-16 12:15:59 +01:00
("bibliography"
:base-directory "~/Cloud/thesis/ressources/notes/"
:base-extension "org"
:publishing-directory "~/Cloud/thesis/ressources/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)
2020-03-01 23:04:12 +01:00
("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/thesis/latex/org/"
:base-extension "org"
:publishing-directory "~/Cloud/thesis/latex/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)))
#+end_src
2020-01-12 00:19:16 +01:00
** Automatically run =startblock= when opening org-mode files
#+begin_src emacs-lisp
(after! org
2020-03-01 22:09:27 +01:00
(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
)
)
2020-01-12 00:19:16 +01:00
2020-03-01 22:09:27 +01:00
(add-hook 'org-mode-hook 'tdh-eval-startblock)
)
2020-01-12 00:19:16 +01:00
#+end_src
** TODO Insert ScreenShot or Picture from Phone
http://pragmaticemacs.com/emacs/a-workflow-to-quickly-add-photos-to-org-mode-notes/
- [ ] One function to move file from =~/Picture/= 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).
- [ ] One function to copy file from =~/Cloud/Photos/= folder (where the pictures from phone are taken) to current directory (and ask for the new name of the picture) and insert org link.
#+begin_src emacs-lisp :tangle no
;; required libraries
(require 'dash)
;; (require 'swiper)
(require 's)
;; start directory
2020-03-01 22:09:27 +01:00
(defvar tdh-image-dir (expand-file-name "/home/thomas/Pictures"))
2020-01-12 00:19:16 +01:00
2020-03-01 22:09:27 +01:00
(defun tdh-insert-conference-image ()
2020-01-12 00:19:16 +01:00
"Insert image from conference directory, rename and add link in current file.
2020-03-01 22:09:27 +01:00
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."
2020-01-12 00:19:16 +01:00
(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))
2020-03-01 22:09:27 +01:00
(directory-files-and-attributes tdh-image-dir)))
2020-01-12 00:19:16 +01:00
;; 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
2020-03-01 22:09:27 +01:00
(expand-file-name start-file tdh-image-dir))
2020-01-12 00:19:16 +01:00
;; 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)))
#+end_src
2020-03-22 20:12:48 +01:00
** TODO Render Tables
2020-01-12 00:19:16 +01:00
https://www.reddit.com/r/emacs/comments/d3a8or/pretty_org_tables_in_the_buffer_chapter_2_it/
#+begin_src emacs-lisp
(after! org
2020-03-01 22:09:27 +01:00
(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))
2020-03-01 22:09:27 +01:00
(tdh-render-org-table (org-element-at-point))
)))))
2020-03-01 22:09:27 +01:00
(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))
)
2020-01-12 00:19:16 +01:00
2020-03-01 22:09:27 +01:00
(defun tdh-render-org-tables-in-buffer ()
(save-excursion
2020-03-01 22:09:27 +01:00
(org-element-map (org-element-parse-buffer) 'table 'tdh-render-org-table)))
2020-01-12 00:19:16 +01:00
;; Use F9 to globally generate tables
2020-03-01 22:09:27 +01:00
(map! :map org-mode-map :n "<f8>" (lambda () (interactive) (tdh-render-org-table-at-point)))
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-03-01 22:09:27 +01:00
** Org Download
#+begin_src emacs-lisp
#+end_src
2020-01-12 00:19:16 +01:00
** Org Gcal
- https://cestlaz.github.io/posts/using-emacs-26-gcal/#.WIqBud9vGAk
#+begin_src emacs-lisp
2020-02-13 17:16:08 +01:00
(use-package! org-gcal
:after org
:init
:config
(setq org-gcal-client-id "396102378658-dcmbcmrnthbe925519otsjbd921otq0v.apps.googleusercontent.com"
2020-02-13 17:16:08 +01:00
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
2020-03-01 22:09:27 +01:00
;; (add-hook 'org-agenda-mode-hook (lambda () (org-gcal-fetch) ))
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-03-22 19:42:41 +01:00
** Custom Keybindings - =,= leader key
*** Insert Elements =,i=
Insert Link to paper
#+begin_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/thesis/ressources/pdfs/" nil t)))
(insert (format "[[papers:%s]]" (file-name-base paper))))
#+end_src
Insert Link to notes
#+begin_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/thesis/ressources/pdfs/" nil t)))
(insert (format "[[notes:%s]]" (file-name-base note))))
#+end_src
Insert Image that is in the figs folder
#+begin_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)))
#+end_src
Insert Image that is in the =figs= folder using SXIV
#+begin_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)))
)
#+end_src
Copy picture from phone folder using SXIV and insert it
#+begin_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)))
)
#+end_src
Bash script for copying pictures taken by phone.
#+begin_src bash :comments both :mkdirp yes :shebang "#!/usr/bin/env bash" :tangle ~/.config/doom/bin/copy-phone-picture.sh
if [ -z "$1" ]; then
oldpath=$(ls -t ~/Cloud/photos/phone/*.jpg | sxiv -i -t -o | tail -1);
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
#+end_src
2020-03-22 19:42:41 +01:00
Take Screenshot and insert a link:
- Ask for a name =screenshot_name=
- use =maim -s figs/screenshot_name.png= to take a screenshot with selection
- Then insert the following to the buffer
#+begin_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)
(setq filename (concat "./figs/" (read-string "Enter file name:") ".png"))
(shell-command (concat "maim -s " filename))
(insert (format "[[file:%s]]" filename))
)
#+end_src
Map Keys
#+begin_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
2020-03-22 19:42:41 +01:00
:n "s" 'tdh-insert-screenshot-org-link)))
#+end_src
*** LaTeX =,l=
#+begin_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))))
#+end_src
#+begin_src emacs-lisp
(defun tdh-latex-watch-kill ()
"Kill the currently running TeX job."
(interactive)
(delete-process "latexmk-watch")
)
#+end_src
#+begin_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)))
#+end_src
*** Org LaTeX Automatic fragment
#+begin_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))
#+end_src
#+begin_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)))
#+end_src
*** Bibtex =,n=
#+begin_src emacs-lisp
(after! org
(map! :map org-mode-map
(:prefix (",b" . "BibTeX")
:n "b" 'helm-bibtex
:n "f" 'helm-bibtex-favorites
:n "r" 'helm-resume)))
#+end_src
*** Open ranger in current directory =,o=
#+begin_src emacs-lisp
(defun tdh-open-ranger-in-workdir ()
(interactive)
(call-process-shell-command
(concat "termite --directory=" default-directory " --exec=ranger") nil 0))
#+end_src
#+begin_src emacs-lisp
(after! org
(map! :map org-mode-map
:n ",o" 'tdh-open-ranger-in-workdir))
#+end_src
*** View in External programs =,v=
Open PDF output with =zathura=
#+begin_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"))
)
#+end_src
Open HTML output externally
#+begin_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"))
)
#+end_src
#+begin_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)))
#+end_src
2020-01-12 00:19:16 +01:00
* Org Babel
** Main configuration
Don't ask for confirmation when evaluating following blocs
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-03-01 22:09:27 +01:00
(defun tdh-org-confirm-babel-evaluate (lang body)
2020-03-30 00:07:44 +02:00
(not (member lang '("emacs-lisp" "latex" "matlab" "sh" "latex-macros" "python"))))
(after! org
2020-03-01 22:09:27 +01:00
(setq org-confirm-babel-evaluate 'tdh-org-confirm-babel-evaluate))
#+end_src
Use the current window for C-c ' source editing
#+begin_src emacs-lisp
(after! org
(setq org-src-window-setup 'current-window))
2020-01-12 00:19:16 +01:00
#+end_src
2020-03-01 22:09:27 +01:00
** Appearance of source blocks
#+begin_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" . ?□)
2020-03-16 12:15:59 +01:00
("#+begin_quote" . ?«)
("#+end_quote" . ?»)))))
2020-03-01 22:09:27 +01:00
(turn-on-prettify-symbols-mode))
(add-hook 'org-mode-hook #'tdh-org-prettify-symbols)
#+end_src
#+begin_src emacs-lisp
(after! org
(set-face-attribute 'org-block nil :background (face-background 'fringe))
(set-face-attribute 'org-block-begin-line nil :background (face-background 'fringe))
(set-face-attribute 'org-block-end-line nil :background (face-background 'fringe))
)
#+end_src
If required, it is possible to set custom colors for different source blocks
#+begin_src emacs-lisp
;; (after! org
;; (setq org-src-block-faces
;; '(("emacs-lisp" (:background (face-background 'org-block)))
;; ("matlab" (:background (face-background 'fringe)))))
;; )
#+end_src
2020-03-22 19:42:41 +01:00
** Indentation
#+begin_src emacs-lisp
(after! org
(setq org-edit-src-content-indentation 2
org-src-tab-acts-natively nil
org-src-preserve-indentation nil)
)
#+end_src
** Library of Babel
Add all named source blocks to =org-babel-library-of-babel=.
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
(after! org
(org-babel-lob-ingest "~/Cloud/thesis/org-mode/org-babel-tutorial/org-babel-library.org"))
2020-01-12 00:19:16 +01:00
#+end_src
2020-03-22 19:42:41 +01:00
** Org-Babel Matlab
#+begin_src emacs-lisp
(after! org
(setq org-babel-matlab-shell-command "/home/thomas/bin/matlab -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');
")
)
#+end_src
Default options for Matlab code
#+begin_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 . "no")
(:mkdir . "yes")
(:eval . "no-export")))
)
#+end_src
** Some functions for using Matlab with Org Babel =,m=
=whos= matlab function
#+begin_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"))))
#+end_src
=help= matlab function
#+begin_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")))
)
#+end_src
Specify a Matlab command to run
#+begin_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")))
#+end_src
Specify a Matlab command to run and show output in mini-buffer
#+begin_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")))
#+end_src
Org-Babel Tangle File and Execute with Matlab
#+begin_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)))))
#+end_src
Map Functions
#+begin_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)))
#+end_src
** Remap =ctrl-ret= used to execute the src block and go to the next one
2020-01-12 00:19:16 +01:00
https://emacs.stackexchange.com/questions/13869/how-to-toggle-org-mode-source-code-block-eval-no-status
Remap =ctrl-ret= to execute the source block and go to the next source block
when inside a source block. Otherwise, keep the normal behavior for =ctrl-ret=.
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-03-01 22:09:27 +01:00
(defun tdh-ctrl-ret ()
(interactive)
(defun in-src-block-p ()
"Returns t when the point is inside a source code block"
(string= "src" (org-in-block-p '("src"))))
2020-01-12 00:19:16 +01:00
(if (in-src-block-p)
2020-02-14 16:08:11 +01:00
(progn
(org-babel-execute-src-block)
(org-babel-next-src-block))
(+org--insert-item 'below)))
#+end_src
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-02-14 16:08:11 +01:00
(map! :after evil-org
:map evil-org-mode-map
2020-03-01 22:09:27 +01:00
:n "<C-return>" #'tdh-ctrl-ret)
2020-01-12 00:19:16 +01:00
#+end_src
** Remap =ctrl-shift-ret= used to execute the (matlab) src block in the background and go to the next one
2020-03-22 19:42:41 +01:00
*** =tdh-org-babel-execute-matlab-background=
#+begin_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))
)))
)
)
#+end_src
2020-03-22 19:42:41 +01:00
*** =tdh-matlab-execute-selected=
#+begin_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"))))
#+end_src
*** Remap =ctrl-shift-ref=
This function:
- first check if inside a source block, if not does nothing
- when check if the language is =matlab=
- if it is not, it just runs the code and go to the next source block
- if it is in a =matlab= 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
#+begin_src emacs-lisp
2020-03-22 19:42:41 +01:00
(defun tdh-ctrl-shift-ret ()
(interactive)
(defun 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)
(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))
)
)
)
#+end_src
#+begin_src emacs-lisp
2020-02-14 16:08:11 +01:00
(map! :after evil-org
:map evil-org-mode-map
2020-03-22 19:42:41 +01:00
:n "<C-S-return>" #'tdh-ctrl-shift-ret)
2020-01-12 00:19:16 +01:00
#+end_src
** Align Source Blocks
#+begin_src emacs-lisp
(defun tdh-align-src-block ()
(interactive)
(defun 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)
(progn
(org-edit-special)
(evil-indent (point-min) (point-max))
(org-edit-src-exit))
(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
2020-03-22 19:42:41 +01:00
** Helping Functions - Tangling =,b=
Org-Babel Tangle Sub-tree
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-03-01 22:09:27 +01:00
(defun tdh-org-babel-tangle-subtree ()
2020-01-12 00:19:16 +01:00
"Tangle the current subtree"
(interactive)
(progn
(org-narrow-to-subtree)
(org-babel-tangle)
(widen))
)
#+end_src
2020-03-22 19:42:41 +01:00
Org-Tangle and Org-Babel Jump to Tangle File
2020-01-12 00:19:16 +01:00
#+begin_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)))))
2020-01-12 00:19:16 +01:00
#+end_src
2020-03-22 19:42:41 +01:00
Map Functions
#+begin_src emacs-lisp
(after! org
2020-03-22 19:42:41 +01:00
(map! :map org-mode-map
(:prefix (",b" . "Tangle")
:n "F" 'tdh-org-babel-jump-to-tangle-file
:n "T" 'tdh-org-babel-tangle-subtree)))
#+end_src
2020-01-12 00:19:16 +01:00
* LaTeX
- https://tex.stackexchange.com/questions/52179/what-is-your-favorite-emacs-and-or-auctex-command-trick
- https://tex.stackexchange.com/questions/20843/useful-shortcuts-or-key-bindings-or-predefined-commands-for-emacsauctex
** Basic LaTeX configuration
#+begin_src emacs-lisp
(defun 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" 'latex/clean)
(add-hook 'TeX-mode-hook #'TeX-fold-mode)
#+end_src
** Face Attributes
#+begin_src emacs-lisp
(with-eval-after-load 'font-latex
(set-face-attribute 'font-latex-math-face nil :foreground (face-foreground 'org-meta-line))
)
#+end_src
2020-01-12 00:19:16 +01:00
** Master file
#+begin_src emacs-lisp
(setq-default TeX-master nil)
#+end_src
2020-02-14 16:08:11 +01:00
** PDF Viewer
2020-01-12 00:19:16 +01:00
#+begin_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)))
#+end_src
2020-02-14 16:08:11 +01:00
** Bibtex
#+begin_src emacs-lisp
2020-03-01 22:09:27 +01:00
(use-package! bibtex
:config
2020-02-14 16:08:11 +01:00
(bibtex-set-dialect 'BibTeX))
#+end_src
2020-01-12 00:19:16 +01:00
* Helm-Bibtex
** General Config
#+begin_src emacs-lisp
2020-02-14 16:08:11 +01:00
(use-package! helm-bibtex
:init
:config
;; Bibliography file
(setq bibtex-completion-bibliography "~/Cloud/thesis/ressources/references.bib")
;; Directory with all the pdfs
(setq bibtex-completion-library-path "~/Cloud/thesis/ressources/pdfs")
;; Directory with notes files
2020-03-01 22:09:27 +01:00
(setq bibtex-completion-notes-path "~/Cloud/thesis/ressources/notes/notes.org")
(setq bibtex-completion-notes-extension ".org")
(setq bibtex-completion-pdf-extension '(".pdf" ".djvu"))
2020-02-14 16:08:11 +01:00
;; 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"
2020-03-01 22:09:27 +01:00
":DRAWER:\n"
"#+LATEX_CLASS: biblioreport\n"
"\n"
"#+OPTIONS: toc:nil title:nil\n"
"#+OPTIONS: ':t -:t\n"
"\n"
"#+LATEX_HEADER: \\newcommand{\\refType}{${=type=}}\n"
"#+LATEX_HEADER: \\newcommand{\\refKey}{${=key=}}\n"
"#+LATEX_HEADER: \\newcommand{\\refTitle}{${title}}\n"
"#+LATEX_HEADER: \\newcommand{\\refAuthor}{${author-or-editor}}\n"
"#+LATEX_HEADER: \\newcommand{\\refJournal}{${journal}}\n"
"#+LATEX_HEADER: \\newcommand{\\refYear}{${year}}\n"
"#+LATEX_HEADER: \\newcommand{\\refDoi}{${DOI}}\n"
"#+LATEX_HEADER: \\newcommand{\\refUrl}{${url}}\n"
"#+LATEX_HEADER: \\newcommand{\\refKeywords}{${tags}}\n"
"#+LATEX_HEADER: \\input{config.tex}\n"
"#+LATEX_HEADER: \\graphicspath{{./figs/${=key=}/}}\n"
"# #+TOC: headlines 2\n"
":END:\n"
"\n"
"#+BEGIN_abstract\n"
"\n"
"#+END_abstract\n"
"\n"
"* ${title} :${=type=}:ignore:\n"
":PROPERTIES:\n"
":CUSTOM_ID: ${=key=}\n"
":AUTHOR: ${author}\n"
":TYPE: ${=type=}\n"
":JOURNAL: ${journal}\n"
":YEAR: ${year}\n"
":VOLUME: ${volume}\n"
":PAGES: ${pages}\n"
":DOI: ${DOI}\n"
":URL: ${url}\n"
":NOTER_DOCUMENT: ../pdfs/${=key=}.pdf\n"
":END:\n"
"\n"))
(setq bibtex-completion-notes-template-one-file (concat "\n"
"* ${author-abbrev} (${year}): ${title} :${=type=}:ignore:\n"
":PROPERTIES:\n"
":CUSTOM_ID: ${=key=}\n"
":EXPORT_FILE_NAME: ${=key=}\n"
":EXPORT_TITLE: ${title}\n"
":AUTHOR: ${author}\n"
":TYPE: ${=type=}\n"
":JOURNAL: ${journal}\n"
":YEAR: ${year}\n"
":VOLUME: ${volume}\n"
":PAGES: ${pages}\n"
":DOI: ${DOI}\n"
":URL: ${url}\n"
":NOTER_DOCUMENT: ../pdfs/${=key=}.pdf\n"
":END:\n"
"\n"))
2020-02-14 16:08:11 +01:00
;; Make "Edit notes" the default action
2020-01-12 00:19:16 +01:00
(helm-delete-action-from-source "Edit notes" helm-source-bibtex)
2020-02-14 16:08:11 +01:00
(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)
)
2020-01-12 00:19:16 +01:00
#+end_src
** Open pdf externally
#+begin_src emacs-lisp
2020-02-14 16:08:11 +01:00
;; Action to open the pdf with Zathura
2020-01-12 00:19:16 +01:00
(defun tdehaeze/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)
"Search Favorite BibTeX entries"
(interactive "P")
(helm-bibtex arg nil "favorite "))
#+end_src
** List all element of the bibliography without pdf associated
#+begin_src emacs-lisp
(defun 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*")
)
#+end_src
2020-03-22 20:12:48 +01:00
* TODO Matlab
2020-01-12 00:19:16 +01:00
- https://github.com/yuhonglin/matlab-mode
- https://github.com/pronobis/matlab-mode
** Setup Matlab Mode
#+begin_src emacs-lisp
(setq matlab-shell-command "/home/thomas/bin/matlab")
(setq matlab-shell-command-switches (list "-nodesktop -nosplash"))
(setq mlint-programs '("mlint" "/home/thomas/bin/mlint"))
#+end_src
** Setup Flycheck
#+begin_src emacs-lisp
(defvar mlint-executable "/home/thomas/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)
#+end_src
#+begin_src emacs-lisp :tangle no
(defadvice org-edit-src-code (around set-buffer-file-name activate compile)
(let ((file-name (buffer-file-name))) ;; (1)
ad-do-it ;; (2)
(setq buffer-file-name file-name))) ;; (3)
#+end_src
** TODO Setup Company - not working
#+begin_src emacs-lisp
;; (add-to-list 'company-backends 'company-matlab)
#+end_src
2020-03-01 22:09:27 +01:00
** Completion in the Matlab Shell
#+begin_src emacs-lisp
(map! :map matlab-shell-mode-map :i "<tab>" 'matlab-shell-tab)
#+end_src
2020-01-12 00:19:16 +01:00
** TODO Beautify code
#+begin_src emacs-lisp
(defun matlab-beautify-buffer ()
"Beautify Current Buffer"
(interactive)
(save-buffer)
(matlab-shell-run-command (concat "MBeautify.formatFile(\"" (buffer-file-name) "\")"))
)
#+end_src
** Key Bindings
#+begin_src emacs-lisp
(defun 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 ()
(interactive)
(matlab-shell-run-command (concat "dbclear in " (buffer-name) " at " (number-to-string (line-number-at-pos nil)))))
(defun matlab-list-breakpoints ()
(interactive)
(matlab-shell-run-command (concat "dbstatus " (buffer-name))))
(defun matlab-clear-breakpoints ()
(interactive)
(matlab-shell-run-command (concat "dbclear in " (buffer-name))))
(defun 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 ",dl" 'gud-cont
:n ",ds" 'gud-step
:n ",dn" 'gud-next
:n ",dq" 'gud-finish)
#+end_src
** Wrong highlight of comments
#+begin_src emacs-lisp :tangle no
(add-hook 'matlab-mode-hook
2020-03-01 22:09:27 +01:00
;; `highlight-numbers-mode' breaks MATLAB comment coloring --
;; `highlight-numbers-mode' is mostly redundant with
;; `rainbow-identifiers-mode' anyway
(lambda ()
(highlight-numbers-mode -1))
;; We must append the above *after* `spacemacs/run-prog-mode-hooks'
;; in `matlab-mode-hook', since the former hook enables
;; `highlight-numbers-mode'. Note that
;; `spacemacs/run-prog-mode-hooks' is manually added to
;; `matlab-mode-hook' by Spacemacs since the upstream `matlab-mode'
;; package does not derive `matlab-mode' from `prog-mode' (oddly --
;; IIRC the author refused to do so for compatibility with XEmacs).
'append)
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-06 17:10:39 +02:00
* Mu4e
** Ressources
Documentation:
- [ ] Mu4e documentation: http://www.djcbsoftware.nl/code/mu/mu4e/index.html#Top
- [ ] https://github.com/djcb/mu
2020-01-12 00:19:16 +01:00
2020-04-06 17:10:39 +02:00
Use contexts for multiple accounts:
- [ ] https://vxlabs.com/2017/02/07/mu4e-0-9-18-e-mailing-with-emacs-now-even-better/
- [ ] http://cachestocaches.com/2017/3/complete-guide-email-emacs-using-mu-and-/
- [ ] https://notanumber.io/2016-10-03/better-email-with-mu4e/
Send math and source code:
- [ ] https://vxlabs.com/2015/01/28/sending-emails-with-math-and-source-code/
2020-01-12 00:19:16 +01:00
2020-04-06 17:10:39 +02:00
** Cheatsheet
| Command | Usage |
|---------+-----------------------|
| =C-j= | Next mail |
| =C-k= | Previous mail |
| =R/C/F= | Reply/Compose/Forward |
| =t= | Move to Archive |
| =d= | Move to Trash |
2020-01-12 00:19:16 +01:00
2020-04-06 17:10:39 +02:00
** 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.
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-04-06 17:10:39 +02:00
(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)))))
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-06 17:10:39 +02:00
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.
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-04-06 17:10:39 +02:00
(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))))))
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-06 17:10:39 +02:00
** Basic Config
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-04-06 17:10:39 +02:00
(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)
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-06 17:10:39 +02:00
** Additional config
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-04-06 17:10:39 +02:00
(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)
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-06 17:10:39 +02:00
** Provide Information
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-04-06 17:10:39 +02:00
(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")
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-06 17:10:39 +02:00
** Receiving emails using mbsync
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-04-06 17:10:39 +02:00
(use-package! mu4e
:config
(setq mu4e-get-mail-command "~/scripts/checkmail.sh"
mu4e-update-interval nil
mu4e-change-filenames-when-moving t) ;; Fix for mbsync
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-06 17:10:39 +02:00
** Contexts
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-04-06 17:10:39 +02:00
(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")
))
))
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-06 17:10:39 +02:00
** Sending mails
2020-01-12 00:19:16 +01:00
#+begin_src emacs-lisp
2020-04-06 17:10:39 +02:00
(use-package! mu4e
:config
(setq message-send-mail-function 'message-send-mail-with-sendmail
sendmail-program "/usr/bin/msmtp"
user-full-name "Thomas Dehaeze")
2020-01-12 00:19:16 +01:00
2020-04-06 17:10:39 +02:00
;; 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)
2020-01-12 00:19:16 +01:00
2020-04-06 17:10:39 +02:00
;; 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)
)
2020-01-12 00:19:16 +01:00
#+end_src
2020-04-06 17:10:39 +02:00
** Bookmarks
#+begin_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)))
)
#+end_src
2020-01-12 00:19:16 +01:00
* PDF-Tools
#+begin_src emacs-lisp
2020-03-01 22:09:27 +01:00
(use-package! pdf-tools
:config
(add-hook 'pdf-view-mode-hook (lambda() (linum-mode -1)))
2020-01-12 00:19:16 +01:00
)
#+end_src
* Yassnippets
#+begin_src emacs-lisp
(push "~/.config/doom/snippets" yas-snippet-dirs)
(yas-global-mode 1)
#+end_src
* Proxy
#+begin_src emacs-lisp :tangle no
(setq url-proxy-services
'(("http" . "proxy.esrf.fr:3128")
("https" . "proxy.esrf.fr:3128")
("no_proxy" . "^.*esrf.fr")))
#+end_src
2020-03-22 20:12:48 +01:00
* TODO Neomutt connection
2020-01-12 00:19:16 +01:00
https://mentat.za.net/blog/2018/10/31/using-org-mode-with-neomutt/
#+begin_src emacs-lisp :tangle no
2020-01-12 00:19:16 +01:00
(require 'org-protocol)
;; Call this function, which spawns neomutt, whenever org-mode
;; tries to open a link of the form mutt:message-id+goes_here@mail.gmail.com
2020-03-01 22:09:27 +01:00
(defun tdh-mutt-open-message (message-id)
2020-01-12 00:19:16 +01:00
"In neomutt, open the email with the the given Message-ID"
(let*
((message-id (replace-regexp-in-string "^/*" "" message-id))
(mail-file
(replace-regexp-in-string
"\n$" "" (shell-command-to-string
(format "mu find -n 1 -f l i:%s" message-id))))
(mail-dir (replace-regexp-in-string "/\\(cur\\|new\\|tmp\\)/$" ""
(file-name-directory mail-file)))
(message-id-escaped (regexp-quote message-id))
(mutt-keystrokes
(format "L~i %s\n\n" (shell-quote-argument message-id-escaped)))
(mutt-command (list "neomutt" "-R" "-f" mail-dir
"-e" (format "push '%s'" mutt-keystrokes))))
(message "Launching neomutt for message %s" message-id)
(call-process "setsid" nil nil
"-f" "termite" "-e"
(concat "neomutt -R -f " mail-dir " -e \"" (format "push '%s a l'\"" mutt-keystrokes)))))
;; Hook up `message:...` style URLs
2020-03-01 22:09:27 +01:00
(org-add-link-type "message" 'tdh-mutt-open-message)
2020-01-12 00:19:16 +01:00
#+end_src
* Abbreviations
Type the abbreviation and use =C-x a -= to create a new abbreviation.
#+begin_src emacs-lisp
(setq-default abbrev-mode t)
;; save abbreviations upon exiting xemacs
(setq save-abbrevs t)
;; set the file storing the abbreviations
(setq abbrev-file-name "~/.config/doom/my-abbreviations.el")
;; reads the abbreviations file on startup
(quietly-read-abbrev-file)
#+end_src
* Other
Here are some additional functions/macros that could help you configure Doom:
- `load!' for loading external *.el files relative to this one
- `use-package' for configuring packages
- `after!' for running code after a package has loaded
- `add-load-path!' for adding directories to the `load-path', where Emacs
looks when you load packages with `require' or `use-package'.
- `map!' for binding new keys
To get information about any of these functions/macros, move the cursor over
the highlighted symbol at press 'K' (non-evil users must press 'C-c g k').
This will open documentation for it, including demos of how they are used.
You can also try 'gd' (or 'C-c g d') to jump to their definition and see how
they are implemented.
2020-03-19 10:09:30 +01:00
* Doom =init.el=
2020-01-12 00:19:16 +01:00
:PROPERTIES:
:header-args: :tangle ~/.config/doom/init.el
:END:
#+begin_src emacs-lisp
2020-02-14 16:08:11 +01:00
(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
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
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
window-select ; visually switch windows
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 ; making dired pretty [functional]
electric ; smarter, keyword-based electric-indent
ibuffer ; interactive buffer management
vc ; version-control and Emacs, sitting in a tree
:term
eshell ; a consistent, cross-platform shell (WIP)
: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
: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
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
+journal ;
2020-04-01 10:27:25 +02:00
+roam ;
2020-02-14 16:08:11 +01:00
+pomodoro ;
+present) ; using org-mode for presentations
2020-03-30 00:07:44 +02:00
python ; beautiful is better than ugly
2020-02-14 16:08:11 +01:00
sh ; she sells {ba,z,fi}sh shells on the C xor
:email
2020-04-06 17:10:39 +02:00
(mu4e +gmail)
2020-02-14 16:08:11 +01:00
:app
calendar
;;(rss +org) ; emacs as an RSS reader
;;write ; emacs for writers (fiction, notes, papers, etc.)
:config
literate
(default +bindings +smartparens))
2020-01-12 00:19:16 +01:00
#+end_src
* Doom =packages.el=
:PROPERTIES:
:header-args: :tangle ~/.config/doom/packages.el
:END:
#+begin_src emacs-lisp
2020-03-19 10:09:30 +01:00
(package! org-noter)
(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-ql)
(package! org-fancy-priorities)
2020-01-12 00:19:16 +01:00
#+end_src
* Snippets
:PROPERTIES:
:header-args:conf+: :comments none
:header-args:conf+: :mkdirp yes
:END:
** LaTeX
*** Coordinate
#+begin_src conf :tangle ~/.config/doom/snippets/latex/coordinate
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :coordinate
# --
\coordinate[${1:->}] (${2:name}) at (${3:pointcoordinate});
$0
#+end_src
*** Draw
#+begin_src conf :tangle ~/.config/doom/snippets/latex/draw
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :draw
# --
\draw[${1:->}] (${2:point1}) -- (${3:point2});
$0
#+end_src
*** Node
#+begin_src conf :tangle ~/.config/doom/snippets/latex/node
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :node
# --
node[${1:below right}] (${2:name}) {${3:label}};
$0
#+end_src
*** Path
#+begin_src conf :tangle ~/.config/doom/snippets/latex/path
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :path
# --
\path[${1}] (${2:point1}) -- (${3:point2});
$0
#+end_src
** Matlab
*** Clear
#+begin_src conf :tangle ~/.config/doom/snippets/matlab/clear
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :clear and close all
# --
clear; close all; clc;
$0
#+end_src
*** Function
#+begin_src conf :tangle ~/.config/doom/snippets/matlab/function
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :function
# --
function [${4:outputs}] = ${1:functionName}(${2:inputs}, ${3:opts_param})
% $1 - Description
%
% Syntax: $1($2, $3)
%
% Inputs:
% - $2 -
% - $3 - Optionals parameters: structure with the following fields:
% -
%
% Outputs:
% - $4 -
%% Default value for opts
opts = struct(...
'${5:outputs}', ${6:default_value} ...
);
if exist('opts_param','var')
for opt = fieldnames($3)'
if sum(strcmp(fieldnames(opts), opt{1})) == 1
opts.(opt{1}) = $3.(opt{1});
else
warning(sprintf('%s is not a valid option.', opt{1}));
end
end
end
$0
#+end_src
** Org Mode
*** Begin
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/begin
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :LaTeX Environment
# --
\begin{${1:equation}}
$0
\end{$1}
#+end_src
*** Block
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/block
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Org-Mode Block
#key: block
# --
,#+begin_${1:$$(let ((type (yas-choose-value '("src" "example" "quote" "verse" "center" "latex" "html" "ascii"))))
(if type (concat type (if (equal type "src")
(concat " " (yas-choose-value '("emacs-lisp" "latex" "python" "sh" "matlab")))))))}
$0
#+end_${1:$(car (split-string yas-text))}
#+end_src
*** Custom Box
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/cbox
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Custom Box
# --
#+attr_latex: :options [$1]{${2:blue}}{${3:ams nodisplayskip}}
#+begin_cbox
$0
#+end_cbox
#+end_src
*** Latex Class
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/latex-class
#name: latex-class
#key: lc
#expand-env: ((classes (mapcar 'car org-latex-classes)))
# --
#+latex_class: ${1:$$(yas-choose-value classes)}
$0
#+end_src
*** 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
#key: bib
# --
bibliography:${1:$$(yas-choose-value (org-ref-find-bibliography))}
#+end_src
*** Cite
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/cite
#name: org-ref cite link
#key: cite
# --
cite:${1:$$(completing-read
"bibtex key: "
(let ((bibtex-files (org-ref-find-bibliography)))(bibtex-global-key-alist)))}
#+end_src
*** Ref
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/ref
#name: org-ref ref link with completion
#key: ref
# --
ref:${1:$$(completing-read "label: " (org-ref-get-labels))}
#+end_src
*** Beamer - CBOX
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/bcbox
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Beamer Custom Box
# --
,*** ${1:@@latex:@@} :B_cbox:
,:PROPERTIES:
:BEAMER_env: cbox
:BEAMER_opt: {${2:blue}}{${3:ams nodisplayskip}}
:END:
$0
#+end_src
*** Code
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/code
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Code
# --
#+caption: ${1:Listing Caption}
#+label: lst:${2:listing_name}
,#+begin_src ${3:listing_language}
$0
,#+end_src
#+end_src
*** Equation
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/equation
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Equation
# --
#+name: eq:${1:equation_name}
\begin{equation}
$0
\end{equation}
#+end_src
*** Figure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/figure
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Figure
# --
#+name: fig:${1:figure_name}
#+caption: ${2:Figure caption}
#+attr_latex: :${3:scale 1}
[[file:${4:figs/}$1.${5:pdf}]]
$0
#+end_src
*** Frac
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/frac
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :LaTeX Fraction
# --
\frac{$1}{$2} $0
#+end_src
*** Left
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/left
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Left Right mathematical delimitations
# --
\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
# --
2020-02-14 16:08:11 +01:00
#+header: :tangle no :exports results :results none :noweb yes
2020-01-12 00:19:16 +01:00
,#+begin_src matlab :var filepath="${2:figs}/$1.pdf" :var figsize="${3:full-tall}" :post pdf2svg(file=*this*, ext="png")
<<plt-matlab>>$0
,#+end_src
2020-02-14 16:08:11 +01:00
#+name: fig:$1
#+caption: ${4:caption}${5: ([[./figs/$1.png][png]], [[./figs/$1.pdf][pdf]])}
2020-01-12 00:19:16 +01:00
[[file:$2/$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>
#name :minipage
# --
#+BEGIN_EXPORT latex
\begin{figure}[htbp]
\centering
\begin{minipage}[t]{0.49\linewidth}
#+END_EXPORT
#+attr_latex: :float nil :width 0.95\linewidth
$0
#+BEGIN_EXPORT latex
\end{minipage}%
\hfill%
\begin{minipage}[t]{0.49\linewidth}
#+END_EXPORT
#+attr_latex: :float nil :width 0.95\linewidth
#+BEGIN_EXPORT latex
\end{minipage}
\end{figure}
#+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>
#name :Multcolumn
# --
#+attr_latex: :float multicolumn
$0
#+end_src
*** Subfigure
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/subfigure
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Subfigure
# --
#+name: fig:${1:figure_name}
#+caption: ${2:figure caption}
#+attr_latex: :environment subfigure :width 0.49\linewidth :align c
| file:${3:sub_fig_name}.${4:pdf} | file:${5:sub_fig_name}.${6:pdf} |
| <<fig:$3>> ${7:sub figure caption} | <<fig:$5>> ${8:sub figure caption} |
$0
#+end_src
*** Table
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/table
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Table
# --
#+name: tab:${1:table_name}
#+caption: ${2:Table caption}
#+attr_latex: :environment tabularx :width ${3:\linewidth} :align ${4:lXX}
#+attr_latex: :center t :booktabs t :float t
| $0 | | |
|---+---+---|
| | | |
#+end_src
*** Tikz
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/tikz
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Tikz figure
# --
,#+begin_src latex :file ${1:figure_name}.pdf :post pdf2svg(file=*this*, ext="png") :exports both
\begin{tikzpicture}
$0
\end{tikzpicture}
,#+end_src
#+end_src
*** Tikzfig
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/tikzfig
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Tikz Figure
# --
#+NAME: fig:${1:figure_name}
#+HEADER: :headers '("\\\\usepackage{tikz}" "\\\\usepackage{import}" "\\\\import{$HOME/Cloud/thesis/LaTeX/}{config.tex}")
#+HEADER: :imagemagick t :fit yes :iminoptions -scale 100% -density 150 :imoutoptions -quality 100
#+HEADER: :results raw replace :buffer no :eval no-export :exports both :mkdirp yes
#+HEADER: :output-dir ${2:figs}
,#+begin_src latex :file $1.pdf :post pdf2svg(file=*this*, ext="png") :exports both
\begin{tikzpicture}
$0
\end{tikzpicture}
,#+end_src
#+NAME: fig:$1
#+CAPTION: ${3:Caption}
#+RESULTS: fig:$1
#+end_src
*** Tikzheader
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/tikzheader
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Tikz Header
# --
,* ${1:Title/Description of the figure}
,#+begin_src latex :file ${2:figure_name}.pdf :tangle figs/$2.tex :exports ${3:both}
\begin{tikzpicture}
$0
\end{tikzpicture}
,#+end_src
#+name: fig:$2
#+caption: $1 ([[./figs/$2.png][png]], [[./figs/$2.pdf][pdf]], [[./figs/$2.tex][tex]]).
#+RESULTS:
[[file:./figs/$2.png]]
#+end_src
*** User-config
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/user-config
# -*- mode: snippet -*-
# name: user-config
# key: uc
# --
,#+begin_src emacs-lisp :tangle user-config.el
$1
,#+end_src
#+end_src
*** User-init
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/user-init
# -*- mode: snippet -*-
# name: user-init
# key: ui
# --
,#+begin_src emacs-lisp :tangle user-init.el
$1
,#+end_src
#+end_src
*** Wrap
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/wrap
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Wrap
# --
#+attr_latex: :float wrap
$0
#+end_src