literate-dotfiles/dotfiles/spacemacs.org

2595 lines
91 KiB
Org Mode
Raw Normal View History

2019-05-16 21:28:33 +02:00
#+TITLE: Spacemacs configuration
#+PROPERTY: header-args:emacs-lisp :comments link :results silent
Ressources:
- https://github.com/munen/emacs.d
2019-05-16 21:28:33 +02:00
* User Init
:PROPERTIES:
:header-args:emacs-lisp+: :tangle ~/.spacemacs.d/user-init.el
:END:
2019-05-16 21:28:33 +02:00
** Melpa
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(add-to-list 'package-archives '("melpa" . "http://www.mirrorservice.org/sites/melpa.org/packages/"))
#+end_src
2019-05-16 21:28:33 +02:00
** Ispell
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq ispell-program-name "/usr/bin/aspell")
#+end_src
2019-05-16 21:28:33 +02:00
** Org latex fragment
#+begin_src emacs-lisp
(defvar tdh/org-latex-fragment-last nil
2019-05-16 21:28:33 +02:00
"Holds last fragment/environment you were on.")
(defun tdh/org-in-latex-fragment-p ()
2019-05-16 21:28:33 +02:00
"Return the point where the latex fragment begins, if inside
a latex fragment. Else return false"
(let* ((el (org-element-context))
(el-type (car el)))
(and (or (eq 'latex-fragment el-type) (eq 'latex-environment el-type))
(org-element-property :begin el))))
(defun tdh/org-latex-fragment-toggle ()
2019-05-16 21:28:33 +02:00
"Toggle a latex fragment image "
(and (eq 'org-mode major-mode)
(let ((begin (tdh/org-in-latex-fragment-p)))
2019-05-16 21:28:33 +02:00
(cond
;; were on a fragment and now on a new fragment
((and
;; fragment we were on
tdh/org-latex-fragment-last
2019-05-16 21:28:33 +02:00
;; and are on a fragment now
begin
;; but not on the last one this is a little tricky. as you edit the
;; fragment, it is not equal to the last one. We use the begin
;; property which is less likely to change for the comparison.
(not (and tdh/org-latex-fragment-last
2019-05-16 21:28:33 +02:00
(= begin
tdh/org-latex-fragment-last))))
2019-05-16 21:28:33 +02:00
;; go back to last one and put image back, provided there is still a fragment there
(save-excursion
(goto-char tdh/org-latex-fragment-last)
(when (tdh/org-in-latex-fragment-p) (org-preview-latex-fragment))
2019-05-16 21:28:33 +02:00
;; now remove current image
(goto-char begin)
(let ((ov (loop for ov in (org--list-latex-overlays)
if
(and
r (<= (overlay-start ov) (point))
2019-05-16 21:28:33 +02:00
(>= (overlay-end ov) (point)))
return ov)))
(when ov
(delete-overlay ov)))
;; and save new fragment
(setq tdh/org-latex-fragment-last begin)))
2019-05-16 21:28:33 +02:00
;; were on a fragment and now are not on a fragment
((and
;; not on a fragment now
(not begin)
;; but we were on one
tdh/org-latex-fragment-last)
2019-05-16 21:28:33 +02:00
;; put image back on, provided that there is still a fragment here.
(save-excursion
(goto-char tdh/org-latex-fragment-last)
(when (tdh/org-in-latex-fragment-p) (org-preview-latex-fragment)))
2019-05-16 21:28:33 +02:00
;; unset last fragment
(setq tdh/org-latex-fragment-last nil))
2019-05-16 21:28:33 +02:00
;; were not on a fragment, and now are
((and
;; we were not one one
(not tdh/org-latex-fragment-last)
2019-05-16 21:28:33 +02:00
;; but now we are
begin)
;; remove image
(save-excursion
(goto-char begin)
(let ((ov (loop for ov in (org--list-latex-overlays)
if
(and
(<= (overlay-start ov) (point))
(>= (overlay-end ov) (point)))
return ov)))
(when ov
(delete-overlay ov))))
(setq tdh/org-latex-fragment-last begin))))))
#+end_src
2019-05-16 21:28:33 +02:00
** Default Browser
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "qutebrowser")
#+end_src
2019-05-16 21:28:33 +02:00
* User-Config
:PROPERTIES:
:header-args:emacs-lisp+: :tangle ~/.spacemacs.d/user-config.el
:END:
2019-05-16 21:28:33 +02:00
** Others
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
;; Line Wrapping
(spacemacs/toggle-truncate-lines-on)
;; Visual line navigation for textual modes
(add-hook 'text-mode-hook 'spacemacs/toggle-visual-line-navigation-on)
;; leader-q-q just kill the frame without killink the server
(evil-leader/set-key
"q q" 'spacemacs/frame-killer)
;; Remove current light highlight
(spacemacs/toggle-highlight-current-line-globally-off)
#+end_src
2019-05-16 21:28:33 +02:00
** Windows Management
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(global-set-key (kbd "<C-up>") 'shrink-window)
(global-set-key (kbd "<C-down>") 'enlarge-window)
(global-set-key (kbd "<C-left>") 'shrink-window-horizontally)
(global-set-key (kbd "<C-right>") 'enlarge-window-horizontally)
#+end_src
2019-05-30 16:22:26 +02:00
2019-05-16 21:28:33 +02:00
** Lockfiles
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq create-lockfiles nil)
#+end_src
** Autosave
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq backup-directory-alist `(("." . "~/.saves")))
(setq backup-by-copying t)
#+end_src
2019-05-16 21:28:33 +02:00
** Magit
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setenv "GIT_ASKPASS" "git-gui--askpass")
(setq magit-diff-refine-hunk 'all)
#+end_src
2019-05-16 21:28:33 +02:00
** User informations
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
;; Used to the \author for LaTeX export
(setq user-full-name "Thomas Dehaeze")
2019-05-30 16:22:26 +02:00
2019-05-16 21:28:33 +02:00
;; Used to set \email for LaTeX export
(setq user-mail-address "dehaeze.thomas@gmail.com")
#+end_src
2019-05-16 21:28:33 +02:00
** Change default alert backend
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq alert-default-style 'libnotify)
#+end_src
2019-05-16 21:28:33 +02:00
** LaTeX
2019-05-16 21:28:33 +02:00
- 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
2019-05-30 16:22:26 +02:00
*** Basic LaTeX configuration
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(defun latex/clean ()
"Clean LaTeX output using latexmk"
(interactive)
(async-shell-command
;; command and parameters
"latexmk -c "
(shell-quote-argument buffer-file-name)
" &"
))
(evil-define-key 'normal LaTeX-mode-map (kbd ", C") 'latex/clean)
(add-hook 'TeX-mode-hook #'TeX-fold-mode)
#+end_src
2019-05-16 21:28:33 +02:00
*** Master file
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq-default TeX-master nil)
#+end_src
2019-05-16 21:28:33 +02:00
*** Pdf Viewer
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(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
2019-05-16 21:28:33 +02:00
2019-05-30 16:22:26 +02:00
** Helm-Bibtex
*** General Config
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'helm-bibtex
;; Use "tags" field when looking for bib entries
(setq helm-bibtex-additional-search-fields '(keywords))
;; Special Tags:
;; - favorite
;; Reverse the order of display
;; (advice-add 'bibtex-completion-candidates
;; :filter-return 'reverse)
;; 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 "✎")
;; Use file field to find the PDF
;; (setq bibtex-completion-pdf-field "file")
;; Bibliography file
(setq bibtex-completion-bibliography "~/Cloud/thesis/ressources/references.bib")
2019-05-16 21:28:33 +02:00
;; Directory with all the pdfs
(setq bibtex-completion-library-path "~/Cloud/thesis/ressources/pdfs")
2019-05-16 21:28:33 +02:00
;; Directory with notes files
(setq bibtex-completion-notes-path "~/Cloud/thesis/ressources/notes")
2019-05-16 21:28:33 +02:00
;; Template used when creating new Note file
(setq bibtex-completion-notes-template-multiple-files (concat "#+TITLE: ${title}\n"
":DRAWER:\n"
"#+LATEX_CLASS: biblioreport\n"
"\n"
"#+OPTIONS: toc:nil title:nil\n"
"#+OPTIONS: ':t -:t\n"
2019-05-16 21:28:33 +02:00
"\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}{${keywords}}\n"
"#+LATEX_HEADER: \\input{config.tex}\n"
2019-06-22 17:34:07 +02:00
"#+LATEX_HEADER: \\graphicspath{{./figs/${=key=}/}}\n"
"# #+TOC: headlines 2\n"
2019-06-22 17:34:07 +02:00
":END:\n"
2019-05-16 21:28:33 +02:00
"\n"
"#+BEGIN_abstract\n"
"\n"
"#+END_abstract\n"
"\n"
"* ${title} :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"
2019-05-16 21:28:33 +02:00
"\n"))
;; Make "Edit notes" the default action
(helm-delete-action-from-source "Edit notes" helm-source-bibtex)
(helm-add-action-to-source "Edit notes" 'helm-bibtex-edit-notes helm-source-bibtex 0)
)
#+end_src
2019-05-16 21:28:33 +02:00
2019-05-30 16:22:26 +02:00
*** Open pdf externally
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'helm-bibtex
(defun tdehaeze/open-pdf-externally (key)
(call-process "zathura" nil 0 nil (nth 0 (-cons-to-list (bibtex-completion-find-pdf key)))))
;; Action to open the pdf with Zathura
(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)
)
#+end_src
2019-05-16 21:28:33 +02:00
2019-05-30 16:22:26 +02:00
*** Special Commands
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(defun helm-bibtex-favorites (&optional arg)
"Search Favorite BibTeX entries"
(interactive "P")
(helm-bibtex arg nil "favorite "))
#+end_src
2019-12-16 21:42:29 +01:00
*** 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
** Auto Complete
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(global-company-mode)
#+end_src
2019-05-16 21:28:33 +02:00
** Yas Snippets
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq yas-indent-line "fixed")
#+end_src
2019-05-16 21:28:33 +02:00
** Org-Mode
2019-05-16 21:28:33 +02:00
- 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
(with-eval-after-load 'org
(setq org-directory "~/Cloud/org/")
(setq org-default-notes-file "~/Cloud/org/refile.org")
;; Highligh latex parts in org mode
(setq org-highlight-latex-and-related '(native))
;; Disable automatic highlight of TODO keywords in orgmode buffers
(add-hook 'org-mode-hook (lambda () (hl-todo-mode -1)))
;; The following setting hides blank lines between headings which keeps folded view nice and compact.
(setq org-cycle-separator-lines 0)
(setq org-startup-indented t)
)
#+end_src
*** Org Tagging
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
;; Tags with fast selection keys
(setq org-tag-alist (quote (("@christophe" . ?c)
("@muriel" . ?m))))
)
#+end_src
*** Org Gcal
2019-05-16 21:28:33 +02:00
- https://cestlaz.github.io/posts/using-emacs-26-gcal/#.WIqBud9vGAk
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(setq org-gcal-client-id "396102378658-dcmbcmrnthbe925519otsjbd921otq0v.apps.googleusercontent.com"
org-gcal-client-secret "4M5PWrbhQjwYEMXGK85lDYX9"
org-gcal-file-alist '(("dehaeze.thomas@gmail.com" . "~/Cloud/org/gcal.org")
("8kjmhe2ar0abnm054ill1fb0gc@group.calendar.google.com" . "~/Cloud/org/gcal_phd.org")))
2019-05-16 21:28:33 +02:00
;; Automatic fetch of the new events
(add-hook 'org-agenda-mode-hook (lambda () (org-gcal-fetch) ))
2019-05-16 21:28:33 +02:00
)
#+end_src
2019-05-16 21:28:33 +02:00
*** Org Refile
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(setq org-refile-targets '((org-agenda-files . (:maxlevel . 6))))
)
#+end_src
*** Org Todos
2019-05-16 21:28:33 +02:00
http://sachachua.com/blog/2014/04/thinking-todo-keywords/
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load '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
)
#+end_src
*** Archive subtrees under the same hierarchy as original in the archive files
https://gist.github.com/Fuco1/e86fb5e0a5bb71ceafccedb5ca22fcfb
#+begin_src emacs-lisp
(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))))))))
#+end_src
*** Org Agenda
**** General configuration
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
;; File to save todo items
(setq org-agenda-files (list "~/Cloud/org/" "~/.config/literate-dotfiles/dotfiles"))
2019-05-16 21:28:33 +02:00
;; Include archived files
(setq org-agenda-archives-mode t)
;; Set priority range from A to C with default A
(setq org-highest-priority ?A)
(setq org-lowest-priority ?C)
(setq org-default-priority ?C)
;; Set colours for priorities
(setq org-priority-faces '((?A . (:foreground "#CC241D"))
(?B . (:foreground "#D65D0E"))
(?C . (:foreground "#D79921"))))
;; Open agenda in current window
(setq org-agenda-window-setup 'current-window)
2019-05-16 21:28:33 +02: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"))
)
)
#+end_src
**** Org Agenda Custom Views
2019-05-16 21:28:33 +02:00
https://blog.aaronbieber.com/2016/09/24/an-agenda-for-life-with-org-mode.html
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(defun tdh/org-agenda-skip-scheduled ()
2019-05-16 21:28:33 +02:00
(org-agenda-skip-entry-if 'scheduled 'deadline 'regexp "\n]+>"))
(setq org-agenda-custom-commands
'(("w" "Work" tags-todo "@work") ;; All todos related to work
("h" "Home" tags-todo "@home") ;; All todos not related to work
("q" . "Questions to ask")
2019-05-16 21:28:33 +02:00
("qc" "Questions to Cristophe" tags "@christophe/QUES" ((org-agenda-overriding-header "Questions to Christophe")))
("qm" "Questions to Muriel" tags "@muriel/QUES" ((org-agenda-overriding-header "Questions to Muriel")))
("qo" "Questions to Olivier" tags "@olivier/QUES" ((org-agenda-overriding-header "Questions to Olivier")))
("qq" "All questions" tags "/QUES" ((org-agenda-overriding-header "Other questions")))
("n" "Next things to do"
((tags "+PRIORITY+\"A\""
((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
(org-agenda-overriding-header "High-priority unfinished tasks:")))
(agenda "")
(todo "NEXT" ((org-agenda-skip-function 'tdh/org-agenda-skip-scheduled)(org-agenda-overriding-header "Next thing to do that are not scheduled")))
2019-05-16 21:28:33 +02:00
(todo "MAIL" ((org-agenda-overriding-header "Email to write/reply")))
(todo "WAIT" ((org-agenda-overriding-header "Things Waiting")))))
("u" "Unscheduled tasks" todo "TODO"
((org-agenda-skip-function 'tdh/org-agenda-skip-scheduled)
2019-05-16 21:28:33 +02:00
(org-agenda-overriding-header "Unscheduled TODO entries: ")))
("r" "Things to read"
((todo "READ" ((org-agenda-overriding-header "Things to read"))))
((org-agenda-files '("~/Cloud/thesis/ressources/notes/")))))
2019-05-16 21:28:33 +02:00
)
)
#+end_src
2019-06-22 17:34:07 +02:00
*** Org Notification based on calendar event
2019-05-16 21:28:33 +02:00
https://emacs.stackexchange.com/questions/3844/good-methods-for-setting-up-alarms-audio-visual-triggered-by-org-mode-events
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(setq appt-message-warning-time 5)
(defun my-org-agenda-to-appt ()
(interactive)
(setq appt-time-msg-list nil)
(org-agenda-to-appt))
(my-org-agenda-to-appt)
; Display appointments as a window manager notification
(setq appt-disp-window-function 'my-appt-display)
(setq appt-delete-window-function (lambda () t))
(setq my-appt-notification-app (concat (getenv "HOME") "/bin/appt-notification"))
(defun my-appt-display (min-to-app new-time msg)
(if (atom min-to-app)
(start-process "my-appt-notification-app" nil my-appt-notification-app min-to-app msg)
(dolist (i (number-sequence 0 (1- (length min-to-app))))
(start-process "my-appt-notification-app" nil my-appt-notification-app (nth i min-to-app) (nth i msg)))))
)
#+end_src
2019-05-16 21:28:33 +02:00
**** appt-notification script
:PROPERTIES:
:header-args: :tangle ~/.spacemacs.d/bin/appt-notification
:header-args+: :comments none :mkdirp yes
:header-args+: :shebang "#!/usr/bin/env bash"
:END:
2019-05-16 21:28:33 +02:00
#+begin_src bash
TIME="$1"TODO
2019-05-16 21:28:33 +02:00
MSG="$2"
dunstify --replace=85401 "Event in $TIME minutes" "$MSG"
#+end_src
*** Org Structure Template
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(setq org-structure-template-alist
'(("c" . "center")
2019-05-16 21:28:33 +02:00
("C" . "comment")
("i" . "important")
2019-05-16 21:28:33 +02:00
("e" . "example")
("q" . "quote")
("s" . "src"))
2019-05-16 21:28:33 +02:00
)
)
#+end_src
2019-05-16 21:28:33 +02:00
*** 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
2019-05-16 21:28:33 +02:00
#+begin_src emacs-lisp
(with-eval-after-load 'org
2019-05-16 21:28:33 +02:00
(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
2019-05-16 21:28:33 +02:00
)
("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
2019-05-16 21:28:33 +02:00
)
("pm"
"Org-Protocol Mail"
2019-05-16 21:28:33 +02:00
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
2019-05-16 21:28:33 +02:00
)
)))
)
#+end_src
2019-05-16 21:28:33 +02:00
*** Org Babel
**** Main configuration
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
;; Don't ask for confirmation when evalutating latex blocs
(defun my-org-confirm-babel-evaluate (lang body)
(not (member lang '("emacs-lisp" "latex" "matlab" "sh"))))
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
;; Enable Babel evalutation
(org-babel-do-load-languages 'org-babel-load-languages '((latex . t)
(shell . t)
(matlab . t)
(python . t)
(emacs-lisp . t)))
)
#+end_src
2019-05-16 21:28:33 +02:00
**** Library of Babel
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(org-babel-lob-ingest "~/Cloud/thesis/org-mode/org-babel-tutorial/org-babel-library.org")
2019-05-16 21:28:33 +02:00
)
#+end_src
2019-05-16 21:28:33 +02:00
**** Org-Babel Matlab
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
2019-12-16 21:42:29 +01:00
(setq org-babel-matlab-shell-command "/home/thomas/bin/matlab -nodesktop -nosplash")
2019-05-16 21:28:33 +02:00
(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
2019-05-16 21:28:33 +02:00
**** Default options
#+begin_src emacs-lisp
(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
**** TODO Asynchronous execution
#+begin_src emacs-lisp :tangle no
(push "~/.emacs.d/private/ob-session-async/lisp/" load-path)
(require 'ob-session-async)
#+end_src
#+begin_src emacs-lisp
;; (with-eval-after-load "ob"
;; (require 'org-babel-eval-in-repl))
#+end_src
#+begin_src emacs-lisp
;; (with-eval-after-load "eval-in-repl"
;; (setq eir-jump-after-eval nil))
#+end_src
**** TODO Theme
#+begin_src emacs-lisp
(with-eval-after-load 'org
(require 'color)
(set-face-attribute 'org-block nil :background (color-darken-name (face-attribute 'default :background) 3))
2019-05-16 21:28:33 +02:00
)
#+end_src
**** Indentation
#+begin_src emacs-lisp
(with-eval-after-load 'org
(setq org-edit-src-content-indentation 2
org-src-tab-acts-natively nil
org-src-preserve-indentation nil)
)
2019-05-16 21:28:33 +02:00
#+end_src
**** Org-Babel Tangle Subtree
#+begin_src emacs-lisp
(defun tdh/org-babel-tangle-subtree ()
"Tangle the current subtree"
(interactive)
(progn
(org-narrow-to-subtree)
(org-babel-tangle)
(widen))
)
(evil-define-key 'normal org-mode-map (kbd ", b T") 'tdh/org-babel-tangle-subtree)
#+end_src
**** TODO Org-Babel Jump to Tangle File
Actually this tangle the file and then go to the file. Maybe I would like to ignore the tangling phase.
#+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)))))
(evil-define-key 'normal org-mode-map (kbd ", b F") 'tdh/org-babel-jump-to-tangle-file)
2019-05-16 21:28:33 +02:00
#+end_src
*** Org Export
**** Basic
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
;; How many levels of headline to export
(setq org-export-headline-levels 4)
;; Authorize BIND to set local variables
(setq org-export-allow-bind-keywords t)
(setq org-odt-preferred-output-format "doc")
;; Used to not export headings with :ignore: tag
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))
)
#+end_src
**** Ox Latex Subfigure package
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(use-package ox-latex-subfigure
:config (require 'ox-latex-subfigure)
)
#+end_src
2019-05-16 21:28:33 +02:00
**** Clear page before heading
2019-05-16 21:28:33 +02:00
https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-heading/30892
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(with-eval-after-load 'ox-latex
(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))))
(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)))))
(add-to-list 'org-export-filter-headline-functions
'org/ensure-latex-clearpage)
)
)
#+end_src
2019-12-16 21:42:29 +01:00
**** TODO HTML Export
***** MathJax
#+begin_src emacs-lisp
(setq org-html-mathjax-template
"<script type=\"text/x-mathjax-config\">
MathJax.Hub.Config({
displayAlign: \"%ALIGN\",
displayIndent: \"%INDENT\",
\"HTML-CSS\": { scale: %SCALE,
linebreaks: { automatic: \"%LINEBREAKS\" },
webFont: \"%FONT\"
},
SVG: {scale: %SCALE,
linebreaks: { automatic: \"%LINEBREAKS\" },
font: \"%FONT\"},
NativeMML: {scale: %SCALE},
TeX: { equationNumbers: {autoNumber: \"%AUTONUMBER\"},
MultLineWidth: \"%MULTLINEWIDTH\",
TagSide: \"%TAGSIDE\",
TagIndent: \"%TAGINDENT\",
Macros: {
bm: [\"{\\\\boldsymbol #1}\",1],
}
}
});
</script>
<script type=\"text/javascript\"
src=\"%PATH\"></script>")
#+end_src
***** Export with css class instead of inline css
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(setq org-html-htmlize-output-type 'css)
)
#+end_src
2019-05-16 21:28:33 +02:00
***** TODO MP4 movies
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(setq org-html-html5-fancy t)
(setq org-html-doctype "xhtml-strict")
)
#+end_src
2019-05-16 21:28:33 +02:00
***** TODO MathJax with SIunix
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(setq org-html-mathjax-template
"<script type=\"text/x-mathjax-config\">
MathJax.Hub.Config({
extensions: [\"tex2jax.js\", \"[siunitx]/siunitx.js\"],
jax: [\"input/TeX\",\"output/HTML-CSS\"],
tex2jax: {inlineMath: [[\"$\",\"$\"],[\"\\(\",\"\\)\"]]},
displayAlign: \"%ALIGN\",
displayIndent: \"%INDENT\",
\"HTML-CSS\": { scale: %SCALE,
linebreaks: { automatic: \"%LINEBREAKS\" },
webFont: \"%FONT\"
},
SVG: {scale: %SCALE,
linebreaks: { automatic: \"%LINEBREAKS\" },
font: \"%FONT\"},
NativeMML: {scale: %SCALE},
TeX: { equationNumbers: {autoNumber: \"%AUTONUMBER\"},
extensions: [\"AMSmath.js\",\"AMSsymbols.js\", \"sinuitx.js\"],
MultLineWidth: \"%MULTLINEWIDTH\",
TagSide: \"%TAGSIDE\",
TagIndent: \"%TAGINDENT\"
}
});
MathJax.Ajax.config.path['siunitx'] = '../js';
</script>
<script type=\"text/javascript\"
src=\"%PATH\"></script>"
)
)
#+end_src
2019-05-16 21:28:33 +02:00
*** Org LaTeX
**** Org CdLatex
https://orgmode.org/manual/CDLaTeX-mode.html#CDLaTeX-mode
#+begin_src emacs-lisp
(with-eval-after-load 'org
(push "~/.spacemacs.d/local/" load-path)
(require 'cdlatex)
(add-hook 'org-mode-hook 'turn-on-org-cdlatex))
#+end_src
**** LaTeX Classes
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(with-eval-after-load 'ox-latex
;; Custom classes to use when exporting to latex
(add-to-list 'org-latex-classes
2019-05-16 21:28:33 +02:00
`("beamer"
,(concat "\\documentclass[presentation]{beamer}\n"
"[DEFAULT-PACKAGES]"
"[PACKAGES]"
"[EXTRA]\n")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
(add-to-list 'org-latex-classes
'("clean-cheatsheet"
"\\documentclass{clean-cheatsheet}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
)
(add-to-list 'org-latex-classes
'("clean-beamer"
"\\documentclass{clean-beamer}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
)
(add-to-list 'org-latex-classes
'("cleanreport"
"\\documentclass{cleanreport}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
)
(add-to-list 'org-latex-classes
'("scrreprt"
"\\documentclass{scrreprt}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
)
2019-05-16 21:28:33 +02:00
(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}"))
)
)
)
#+end_src
2019-05-16 21:28:33 +02:00
**** Basic
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(with-eval-after-load 'ox-latex
;; 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))
2019-05-16 21:28:33 +02:00
(add-to-list 'org-latex-packages-alist '("most" "tcolorbox" t))
;; Setup default option for image size when exporting to LaTeX
(setq org-latex-image-default-option "scale=1")
(setq org-latex-image-default-width nil)
;; 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))
2019-05-16 21:28:33 +02:00
;; 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"))
2019-05-16 21:28:33 +02:00
)
)
#+end_src
2019-05-16 21:28:33 +02:00
**** Beamer
***** Bold Text
#+begin_src emacs-lisp
(defun my-beamer-bold (contents backend info)
(when (eq backend 'beamer)
(replace-regexp-in-string "\\`\\\\[A-Za-z0-9]+" "\\\\textbf" contents)))
(add-to-list 'org-export-filter-bold-functions 'my-beamer-bold)
#+end_src
***** TODO Make a custom environment for columns with title
# #+beamer: \csubtitle{title}\vspace{1em}
***** TODO Custom Environments
- [ ] Make some comment those special environments
2019-05-16 21:28:33 +02:00
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(with-eval-after-load 'ox-beamer
(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}"
"}"))
)
)
#+end_src
2019-05-16 21:28:33 +02:00
**** TODO Latex Fragments
- [ ] The remove hook does not seems to work
2019-05-16 21:28:33 +02:00
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(with-eval-after-load 'ox-latex
;; Automatic toggle of latex fragments http://slumpy.org/blog/2017-02-01-automatic-latex-preview-in-org-mode/
;; Activate Automatic LaTeX fragment
(spacemacs/set-leader-keys "ol" '(lambda () (interactive) (add-hook 'post-command-hook 'tdh/org-latex-fragment-toggle t)))
2019-05-16 21:28:33 +02:00
;; Disable Automatic LaTeX fragment
(spacemacs/set-leader-keys "oL" '(lambda () (interactive) (remove-hook 'post-command-hook 'tdh/org-latex-fragment-toggle)))
2019-05-16 21:28:33 +02:00
;; Use F9 to globally generate all the latex fragments
(global-set-key (kbd "<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 ("latex" "convert")
:description "pdf > png"
:message "you need to install the programs: latex and imagemagick."
2019-05-16 21:28:33 +02:00
:image-input-type "pdf"
:image-output-type "png"
:image-size-adjust (0.6 . 0.6)
:latex-compiler ("pdflatex -interaction nonstopmode -output-directory %o %f")
2019-05-16 21:28:33 +02:00
:image-converter ("convert -density %D -trim -antialias %f -quality 100 %O"))
(pdf2svg
:programs ("latex" "pdf2svg")
:description "pdf > svg"
:message "you need to install the programs: pdflatex and pdf2svg."
:image-input-type "pdf"
:image-output-type "svg"
:image-size-adjust (1.0 . 1.0)
:latex-compiler ("pdflatex -interaction nonstopmode -output-directory %o %f")
:image-converter ("pdfcrop %f %f && pdftocairo -svg %f %O"))
;; :image-converter ("pdf2svg %f %O"))
2019-05-16 21:28:33 +02:00
(dvisvgm
:programs ("latex" "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 (1.0 . 1.0)
: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 'imagemagick)
2019-05-16 21:28:33 +02:00
))
#+end_src
2019-05-16 21:28:33 +02:00
**** TODO Custom Export - Add Page and Label for LaTeX export
2019-05-16 21:28:33 +02:00
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
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(defcustom tdehaeze/org-property-mapping
'((latex ("CUSTOM_PAGE" . tdehaeze/insert-org-page-latex)
("CUSTOM_LABEL" . tdehaeze/insert-org-label-latex)))
"List of mappings from org property to arbitrary strings.
Each element is a list:
(BACKEND (PROPERTY1 . FUNCTION1) (PROPERTY2 . FUNCTION2) ...)
FUNCTION are functions which get called with a single
argument (the value of PROPERTY) and are responsible for doing
whatever should be done."
:type '(repeat (cons symbol (repeat (cons string string)))))
)
#+end_src
2019-05-16 21:28:33 +02:00
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(defun tdehaeze/replace-org-property (backend)
"Convert org properties using `tdehaeze/org-property-mapping'.
Lookup BACKEND in `tdehaeze/org-property-mapping' for a list of
(PROPERTY REPLACEMENT). For each healine being exported, if it has a
PROPERTY listed insert a string immediately after the healine given by
(format REPLACEMENT PROPERTY-VALUE)"
(let ((map (cdr (assoc backend tdehaeze/org-property-mapping)))
value replacement)
(when map
(org-map-entries
(lambda ()
(dolist (it map)
(save-excursion
(when (setq value (org-entry-get (point) (car it)))
(funcall (cdr it) value)))))))))
(add-hook 'org-export-before-processing-hook #'tdehaeze/replace-org-property)
)
#+end_src
2019-05-16 21:28:33 +02:00
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(defun tdehaeze/insert-org-label-latex (label)
"Insert \"\\\\label{LABEL}\\n\" after the :PROPERTY: drawer."
(search-forward-regexp org-property-end-re)
(forward-char 1)
(insert (format "\\label{%s}\n" label)))
(defun tdehaeze/insert-org-page-latex (page)
"Insert \"\\\\page{PAGE}\\n\" after the :PROPERTY: drawer."
(search-forward-regexp org-property-end-re)
(forward-char 1)
(insert (format "\\page{%s}\n" page)))
)
#+end_src
2019-05-16 21:28:33 +02:00
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(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
(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)
#+end_src
2019-12-16 21:42:29 +01:00
*** TODO [#A] View PDF in org mode
#+begin_src emacs-lisp :tangle no
(defun tdh/org-include-img-from-pdf (&rest _)
"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")))
(add-hook 'org-export-before-processing-hook #'tdh/org-include-img-from-pdf)
#+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))
(setq org-image-actual-width 600)
#+end_src
#+begin_src emacs-lisp :tangle no
(defun my-latex-filter-nobreaks (text backend info)
"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
'my-latex-filter-nobreaks)
#+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-image-actual-width 600)
(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
(defun tdh/change-png-to-pdf (text backend info)
"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))))
(add-to-list 'org-export-filter-plain-text-fucntions 'my-html-mark-tag)
#+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
2019-05-16 21:28:33 +02:00
*** Org Ref
2019-05-16 21:28:33 +02:00
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/
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
;; 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")
2019-05-16 21:28:33 +02:00
;; Bibliography File
(setq reftex-default-bibliography '("~/Cloud/thesis/ressources/references.bib"))
(setq org-ref-default-bibliography '("~/Cloud/thesis/ressources/references.bib"))
2019-05-16 21:28:33 +02:00
;; Folder where all the pdf are located
(setq org-ref-pdf-directory "~/Cloud/thesis/ressources/pdfs")
2019-05-16 21:28:33 +02:00
;; Tell org-ref to let helm-bibtex find notes for it
(setq org-ref-notes-function
(lambda (thekey)
(let ((bibtex-completion-bibliography (org-ref-find-bibliography)))
(bibtex-completion-edit-notes
(list (car (org-ref-get-bibtex-key-and-file thekey)))))))
;; Problem with speed: don't display broken links
(setq org-ref-show-broken-links nil)
;; Display information on the citation
(setq org-ref-show-citation-on-enter t)
)
#+end_src
2019-05-16 21:28:33 +02:00
*** Org Noter
2019-05-16 21:28:33 +02:00
- https://github.com/weirdNox/org-noter
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
2019-06-22 17:34:07 +02:00
(setq org-noter-always-create-frame nil)
(setq org-noter-kill-frame-at-session-end nil)
2019-05-16 21:28:33 +02:00
;; 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 t)
;; 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")
2019-05-16 21:28:33 +02:00
)
#+end_src
2019-05-16 21:28:33 +02:00
*** Custom key bindings
Export to LaTeX
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(evil-define-key 'normal org-mode-map (kbd ", l") 'org-latex-export-to-latex)
#+end_src
2019-05-16 21:28:33 +02:00
Open pdf externally.
#+begin_src emacs-lisp
(defun tdh/open-org-pdf-externally ()
(interactive)
(call-process "xdg-open" nil 0 nil (concat (file-name-sans-extension (buffer-file-name)) ".pdf"))
)
(evil-define-key 'normal org-mode-map (kbd ", v p") 'tdh/open-org-pdf-externally)
#+end_src
Open HTML 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"))
)
(evil-define-key 'normal org-mode-map (kbd ", v h") 'tdh/open-org-html-externally)
#+end_src
*** TODO Org-Contacts
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(setq org-contacts-files (list "~/Cloud/org/contacts.org"))
2019-05-16 21:28:33 +02:00
)
#+end_src
2019-05-16 21:28:33 +02:00
*** TODO Org-Wunderlist
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(require 'org-wunderlist)
(setq org-wunderlist-client-id "6799d9caeb2f5d8bd641"
org-wunderlist-token "fd5965cde436c2587850a7c517d366561d8a1cbf7b6d96ab62f3fc8c9930"
org-wunderlist-file "~/Cloud/thesis/todos/wunderlist.org"
2019-05-16 21:28:33 +02:00
org-wunderlist-dir "~/.emacs.d/org-wunderlist/")
2019-07-20 16:29:41 +02:00
#+end_src
*** TODO ox-hugo
*** Automatically run =startblock= when opening org-mode files
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'org
(defun tdh/eval-startblock ()
(if (member "startblock" (org-babel-src-block-names))
(save-excursion
(org-babel-goto-named-src-block "startblock")
(org-babel-execute-src-block))
nil
)
)
(add-hook 'org-mode-hook 'tdh/eval-startblock)
2019-05-16 21:28:33 +02: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
;; required libraries
(require 'dash)
;; (require 'swiper)
(require 's)
;; start directory
(defvar tdh/image-dir (expand-file-name "/home/thomas/Pictures"))
(defun tdh/insert-conference-image ()
"Insert image from conference directory, rename and add link in current file.
The file is taken from a start directory set by `tdh/image-dir' and moved to the current directory, renamed and embedded at the point as an org-mode link. The user is presented with a list of files in the start directory, from which to select the file to move, sorted by most recent first."
(interactive)
(let (file-list target-dir file-list-sorted start-file start-file-full file-ext end-file end-file-base end-file-full file-number)
;; Clean directories from list but keep times
(setq file-list
(-remove (lambda (x) (nth 1 x))
(directory-files-and-attributes tdh/image-dir)))
;; Get target directory
(setq target-dir (file-name-directory (buffer-file-name)))
;; Sort list by most recent
(setq file-list-sorted
(mapcar #'car
(sort file-list
#'(lambda (x y) (time-less-p (nth 6 y) (nth 6 x))))))
;; Use ivy to select start-file
(setq start-file (ivy-read
(concat "Move selected file to " target-dir ":")
file-list-sorted
:re-builder #'ivy--regex
:sort nil
:initial-input nil))
;; add full path to start file and end-file
(setq start-file-full
(expand-file-name start-file tdh/image-dir))
;; final file name including path
(setq end-file-full
(expand-file-name start-file target-dir))
;; rename file
(rename-file start-file-full end-file-full)
(message "moved %s to %s" start-file-full start-file)
;; insert link
(insert (org-make-link-string (format "file:%s" start-file)))
;; display image
(org-display-inline-images t t)))
#+end_src
*** TODO [#B] Render Tables
https://www.reddit.com/r/emacs/comments/d3a8or/pretty_org_tables_in_the_buffer_chapter_2_it/
#+begin_src emacs-lisp
(defun my-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))
(my-render-org-table (org-element-at-point))
)))))
(defun my-render-org-table (table)
(interactive)
(let* ((begin (org-element-property :begin table))
(end (let ((pos (org-element-property :end table)))
(goto-char pos)
(beginning-of-line)
;; skip possible space after table
(while (not (looking-at " *[|#]"))
(setq pos (point))
(forward-line -1))
pos))
(tabletxt (buffer-substring-no-properties begin end))
(img (with-temp-buffer
(insert tabletxt)
(mark-whole-buffer)
(org-latex-convert-region-to-latex)
(org-latex-preview)
(goto-char (point-min))
(overlay-get (car (overlays-at (point))) 'display)))
(overlay (make-overlay begin end)))
(overlay-put overlay 'display img)
(forward-line -1))
)
(defun my-render-org-tables-in-buffer ()
(save-excursion
(org-element-map (org-element-parse-buffer) 'table 'my-render-org-table)))
;; Use F9 to globally generate tables
(global-set-key (kbd "<f8>") (lambda () (interactive) (my-render-org-table-at-point)))
#+end_src
2019-05-16 21:28:33 +02:00
2019-05-30 16:22:26 +02:00
** Projectile
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq projectile-generic-command "fd -H --ignore-file .projectile -t f -0")
#+end_src
2019-05-30 16:22:26 +02:00
** TODO [#B] Matlab
2019-05-16 21:28:33 +02:00
- https://github.com/yuhonglin/matlab-mode
- https://github.com/pronobis/matlab-mode
*** TODO [#A] Test with Org Babel
#+begin_src emacs-lisp :tangle no
(let* ((session
(funcall (intern "org-babel-matlab-initiate-session")
"*MATLAB*" params))
(result (org-babel-octave-evaluate session "ls" "output"))))
#+end_src
*** Setup Matlab Mode
#+begin_src emacs-lisp
2019-12-16 21:42:29 +01:00
(setq matlab-shell-command "/home/thomas/bin/matlab")
(setq matlab-shell-command-switches (list "-nodesktop -nosplash"))
2019-12-16 21:42:29 +01:00
(setq mlint-programs '("mlint" "/home/thomas/bin/mlint"))
#+end_src
2019-05-16 21:28:33 +02:00
*** Setup Flycheck
#+begin_src emacs-lisp
2019-12-16 21:42:29 +01:00
(defvar mlint-executable "/home/thomas/bin/mlint")
2019-05-16 21:28:33 +02:00
(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
2019-05-16 21:28:33 +02:00
#+begin_src emacs-lisp :tangle no
2019-06-22 17:34:07 +02:00
(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
2019-05-16 21:28:33 +02:00
*** TODO Setup Company - not working
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
;; (add-to-list 'company-backends 'company-matlab)
#+end_src
2019-05-16 21:28:33 +02: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) "\")"))
)
;; (global-set-key [C-f1] 'show-file-name)
#+end_src
2019-05-30 16:22:26 +02:00
*** 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
(evil-define-key 'normal matlab-mode-map (kbd ", g") 'matlab-go-to-file-directory)
(evil-define-key 'normal matlab-mode-map (kbd ", d a") 'matlab-add-breakpoint)
(evil-define-key 'normal matlab-mode-map (kbd ", d r") 'matlab-remove-breakpoint)
(evil-define-key 'normal matlab-mode-map (kbd ", d L") 'matlab-list-breakpoints)
(evil-define-key 'normal matlab-mode-map (kbd ", d c") 'matlab-clear-breakpoints)
(evil-define-key 'normal matlab-mode-map (kbd ", d l") 'gud-cont)
(evil-define-key 'normal matlab-mode-map (kbd ", d s") 'gud-step)
(evil-define-key 'normal matlab-mode-map (kbd ", d n") 'gud-next)
(evil-define-key 'normal matlab-mode-map (kbd ", d q") 'gud-finish)
#+end_src
** TODO [#B] Mails With Mu4e
:PROPERTIES:
:header-args:emacs-lisp+: :tangle no
:END:
2019-05-16 21:28:33 +02:00
- https://github.com/kzar/davemail
- http://cachestocaches.com/2017/3/complete-guide-email-emacs-using-mu-and-/
- http://spacemacs.org/layers/+email/mu4e/README.html
- http://www.djcbsoftware.nl/code/mu/mu4e/index.html#Top
- https://notanumber.io/2016-10-03/better-email-with-mu4e/
- https://vxlabs.com/2017/02/07/mu4e-0-9-18-e-mailing-with-emacs-now-even-better/
- http://www.brool.com/post/using-mu4e/
- https://www.reddit.com/r/emacs/comments/8q84dl/tip_how_to_easily_manage_your_emails_with_mu4e/
- https://vxlabs.com/2017/02/07/mu4e-0-9-18-e-mailing-with-emacs-now-even-better/
2019-05-16 21:28:33 +02:00
*** Set default mail user agent to mu4e
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mail-user-agent 'mu4e-user-agent)
#+end_src
2019-05-16 21:28:33 +02:00
*** Default config
**** Default behavior
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mu4e-maildir "~/.mail"
mu4e-update-interval nil
mu4e-compose-signature-auto-include t
mu4e-view-show-images t
mu4e-view-show-addresses t)
#+end_src
2019-05-16 21:28:33 +02:00
**** Default folders
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mu4e-sent-folder "/gmail/Sent"
mu4e-drafts-folder "/gmail/Drafts"
mu4e-trash-folder "/gmail/Trash"
mu4e-refile-folder "/gmail/Archive"
mu4e-compose-signature "Thomas Dehaeze\n"
user-mail-address "dehaeze.thomas@gmail.com")
#+end_src
2019-05-16 21:28:33 +02:00
**** Default signature and email address
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mu4e-compose-signature "Thomas Dehaeze\n"
user-mail-address "dehaeze.thomas@gmail.com")
#+end_src
2019-05-16 21:28:33 +02:00
**** Saving the attachment to Downloads directory
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mu4e-attachment-dir "~/Downloads")
#+end_src
2019-05-16 21:28:33 +02:00
**** A list of user's e-mail addresses
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mu4e-user-mail-address-list '("dehaeze.thomas@gmail.com" "thomas.dehaeze@esrf.fr" "thomas.dehaeze@doct.ulg.ac.be"))
#+end_src
2019-05-16 21:28:33 +02:00
**** Mail directory shortcuts
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mu4e-maildir-shortcuts
'(
("/gmail/Inbox" . ?g)
("/esrf/Inbox" . ?e)
("/ulg/Inbox" . ?u)
))
#+end_src
2019-05-16 21:28:33 +02:00
*** TODO Contexts - Email accounts
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(setq mu4e-contexts
`( ,(make-mu4e-context
:name "gmail"
:enter-func (lambda () (mu4e-message "Entering Gmail context"))
:leave-func (lambda () (mu4e-message "Leaving Gmail context"))
:match-func (lambda (msg)
(when msg
(string-match-p "^/gmail" (mu4e-message-field msg :maildir))))
:vars '(
(mu4e-sent-messages-behavior . (delete))
(user-mail-address . "dehaeze.thomas@gmail.com")
(mu4e-sent-folder . "/gmail/Sent")
(mu4e-trash-folder . "/gmail/Trash")
(mu4e-drafts-folder . "/gmail/Drafts")
(mu4e-refile-folder . "/gmail/Archive")
(mu4e-compose-signature .
(concat
"Thomas Dehaeze\n"
"\n"))
))
,(make-mu4e-context
:name "esrf"
:enter-func (lambda () (mu4e-message "Entering ESRF context"))
:leave-func (lambda () (mu4e-message "Leaving ESRF context"))
:match-func (lambda (msg)
(when msg
(string-match-p "^/esrf" (mu4e-message-field msg :maildir))))
:vars '(
(user-mail-address . "thomas.dehaeze@esrf.fr")
(mu4e-sent-folder . "/esrf/Sent")
(mu4e-trash-folder . "/esrf/Trash")
(mu4e-drafts-folder . "/esrf/Drafts")
(mu4e-refile-folder . "/esrf/Archive")
(mu4e-compose-signature .
(concat
"Thomas Dehaeze\n"
"\n"))
))
,(make-mu4e-context
:name "ulg"
:enter-func (lambda () (mu4e-message "Entering ULG context"))
:leave-func (lambda () (mu4e-message "Leaving ULG context"))
:match-func (lambda (msg)
(when msg
(string-match-p "^/ulg" (mu4e-message-field msg :maildir))))
:vars '(
(user-mail-address . "thomas.dehaeze@doct.ulg.ac.be")
(mu4e-sent-folder . "/ulg/Sent")
(mu4e-trash-folder . "/ulg/Trash")
(mu4e-drafts-folder . "/ulg/Drafts")
(mu4e-refile-folder . "/ulg/Archive")
(mu4e-compose-signature .
(concat
"Thomas Dehaeze\n"
"\n"))
))
))
(setq mu4e-context-policy 'pick-first)
#+end_src
2019-05-16 21:28:33 +02:00
*** Receiving emails - Mbsync
2019-05-16 21:28:33 +02:00
Let systemd get the mail, then pressing =U= will just run =mu= to reindex everything.
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mu4e-get-mail-command "true")
#+end_src
Fix for mbsync found [[http://pragmaticemacs.com/emacs/fixing-duplicate-uid-errors-when-using-mbsync-and-mu4e/][here]].
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mu4e-change-filenames-when-moving t)
#+end_src
*** Sending emails - Msmtp
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq smtpmail-default-smtp-server "smtp.gmail.com"
smtpmail-smtp-server "smtp.gmail.com"
smtpmail-smtp-service 587)
(setq message-send-mail-function 'message-send-mail-with-sendmail
sendmail-program "msmtp"
user-full-name "Thomas Dehaeze")
#+end_src
2019-05-16 21:28:33 +02:00
*** Bookmarks
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(setq mu4e-bookmarks
`(("flag:unread AND NOT flag:trashed" "Unread messages" ?u)
("date:today..now" "Today's messages" ?t)
("date:7d..now" "Last 7 days" ?w)
("mime:image/*" "Messages with images" ?p)
(,(mapconcat 'identity
(mapcar
(lambda (maildir)
(concat "maildir:" (car maildir)))
mu4e-maildir-shortcuts) " OR ")
"All inboxes" ?i)))
#+end_src
2019-05-16 21:28:33 +02:00
*** TODO Notifications
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(with-eval-after-load 'mu4e-alert
(mu4e-alert-set-default-style 'libnotify))
(mu4e-alert-enable-notifications)
#+end_src
2019-05-16 21:28:33 +02:00
Mode-line notifications
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(setq mu4e-enable-mode-line t)
#+end_src
*** Use Org-Mode Tables In Emails
#+begin_src emacs-lisp
(add-hook 'message-mode-hook 'turn-on-orgtbl)
(add-hook 'message-mode-hook 'turn-on-orgstruct++)
#+end_src
*** TODO Integration with Org-Mode
Store link to message if in header view, not to header query
#+begin_src emacs-lisp
(setq org-mu4e-link-query-in-headers-mode nil)
#+end_src
2019-05-16 21:28:33 +02:00
*** TODO [#A] When putting something on the Trash, it will be in the archive folder on gmail
Even when totally deleting it. It will stay on gmail. How to fix that?
2019-05-16 21:28:33 +02:00
*** TODO Verify that sending mails with gmail account works and that there is no duplicate
2019-05-16 21:28:33 +02:00
Should check this variable: mu4e-sent-messages-behavior
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(setq mu4e-sent-messages-behavior 'delete)
#+end_src
2019-05-16 21:28:33 +02:00
And [[https://www.djcbsoftware.nl/code/mu/mu4e/Gmail-configuration.html][here]].
2019-05-16 21:28:33 +02:00
If I put it to delete, it works for gmail but not for the other ones...
Check [[https://github.com/djcb/mu/issues/179][here]].
*** TODO Cheatsheet
2019-05-16 21:28:33 +02:00
| Command | Usage |
|---------+-----------------------|
| =C-j= | Next mail |
| =C-k= | Previous mail |
| =R/C/F= | Reply/Compose/Forward |
| =t= | Move to Archive |
| =d= | Move to Trash |
** PDF-Tools
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(add-hook 'pdf-view-mode-hook (lambda() (linum-mode -1)))
#+end_src
2019-05-16 21:28:33 +02:00
** Custom command and leader keys
*** Watch LaTeX file using latexmk
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(defun 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))))
(defun latex/watch/kill ()
"Kill the currently running TeX job."
(interactive)
(delete-process "latexmk-watch")
)
(spacemacs/set-leader-keys "ow" 'latex/watch)
(spacemacs/set-leader-keys "ok" 'latex/watch/kill)
#+end_src
2019-05-16 21:28:33 +02:00
*** Helm-Bibtex
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(spacemacs/set-leader-keys "ob" 'helm-bibtex)
(spacemacs/set-leader-keys "of" 'helm-bibtex-favorites)
(spacemacs/set-leader-keys "or" 'helm-resume)
#+end_src
2019-05-16 21:28:33 +02:00
*** Eshell
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(spacemacs/set-leader-keys "os" 'eshell)
#+end_src
2019-05-16 21:28:33 +02:00
*** Open terminal in current directory
#+begin_src emacs-lisp
(defun open-terminal-in-workdir ()
(interactive)
(call-process-shell-command
(concat "termite --directory=" default-directory) nil 0))
(spacemacs/set-leader-keys "ot" 'open-terminal-in-workdir)
#+end_src
*** Open ranger in current directory
#+begin_src emacs-lisp
(defun open-ranger-in-workdir ()
(interactive)
(call-process-shell-command
(concat "termite --directory=" default-directory " --exec=ranger") nil 0))
(spacemacs/set-leader-keys "oo" 'open-ranger-in-workdir)
#+end_src
2019-05-16 21:28:33 +02:00
** Path for Shell
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize))
#+end_src
2019-05-16 21:28:33 +02:00
** Proxy
#+begin_src emacs-lisp :tangle no
2019-05-16 21:28:33 +02:00
(setq url-proxy-services
'(("http" . "proxy.esrf.fr:3128")
("https" . "proxy.esrf.fr:3128")
("no_proxy" . "^.*esrf.fr")))
#+end_src
2019-05-16 21:28:33 +02:00
** Remove the problem of recentf files
#+begin_src emacs-lisp
2019-05-16 21:28:33 +02:00
(cancel-timer recentf-auto-save-timer)
#+end_src
** TODO [#B] Slack
:PROPERTIES:
:header-args:emacs-lisp+: :tangle no
:END:
#+begin_src emacs-lisp
(slack-register-team
:name "emacs-slack"
:default t
:client-id "299050134212.316863429523"
:client-secret "7168a660375090e517fe812ea2d136e5"
:token "xoxp-299050134212-299063259042-715794254097-7c319fdd63315620e86f1fad42c126a2"
:subscribed-channels '())
#+end_src
#+begin_src emacs-lisp
(advice-add 'slack-counts-update :override #'ignore)
#+end_src
#+begin_src emacs-lisp
(setq slack-prefer-current-team t)
#+end_src
2019-06-22 17:34:07 +02:00
** TODO [#C] Neomutt connection
https://mentat.za.net/blog/2018/10/31/using-org-mode-with-neomutt/
#+begin_src emacs-lisp
2019-06-22 17:34:07 +02: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
(defun tdehaeze/mutt-open-message (message-id)
"In neomutt, open the email with the the given Message-ID"
(let*
((message-id (replace-regexp-in-string "^/*" "" message-id))
(mail-file
(replace-regexp-in-string
"\n$" "" (shell-command-to-string
(format "mu find -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
(org-add-link-type "message" 'tdehaeze/mutt-open-message)
#+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 "~/.spacemacs.d/my-abbreviations.el")
;; reads the abbreviations file on startup
(quietly-read-abbrev-file)
#+end_src
** Elfeed
** Telegram
:PROPERTIES:
:header-args:emacs-lisp+: :tangle no
:END:
#+begin_src emacs-lisp
(telega-notifications-mode 1)
#+end_src
2019-08-23 10:03:32 +02:00
* Snippets
:PROPERTIES:
:header-args:conf+: :comments none
:header-args:conf+: :mkdirp yes
:END:
** LaTeX
*** Coordinate
#+begin_src conf :tangle ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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
2019-08-23 10:03:32 +02:00
*** Custom Box
#+begin_src conf :tangle ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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
2019-08-23 10:03:32 +02:00
*** Code
#+begin_src conf :tangle ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/snippets/org-mode/mfigure
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Figure
# --
#+HEADER: :tangle no :exports results :results none :noweb yes
,#+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
#+NAME: fig:$1
#+CAPTION: ${4:caption}${5: ([[./figs/$1.png][png]], [[./figs/$1.pdf][pdf]])}
[[file:$2/$1.png]]
#+end_src
*** Mfunction
#+begin_src conf :tangle ~/.spacemacs.d/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
2019-12-16 21:42:29 +01:00
:header-args:matlab+: :comments none :mkdirp yes :eval no
:END:
<<sec:$2>>
2019-08-23 10:03:32 +02:00
This Matlab function is accessible [[file:src/$2.m][here]].
,#+begin_src matlab
function [${4:in_data}] = $2(${3:in_data})
% $2 - $0
%
2019-12-16 21:42:29 +01:00
% Syntax: [$4] = $2($3)
2019-08-23 10:03:32 +02:00
%
% Inputs:
% - $3 -
%
% Outputs:
% - $4 -
end
,#+end_src
#+end_src
*** Mheader
#+begin_src conf :tangle ~/.spacemacs.d/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>>
2019-08-23 10:03:32 +02:00
,** 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 ~/.spacemacs.d/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 ~/.spacemacs.d/snippets/org-mode/minit
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Init
# --
,** Matlab Init :noexport:ignore:
2019-08-23 10:03:32 +02:00
,#+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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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
2019-08-23 10:03:32 +02:00
| $0 | | |
|---+---+---|
| | | |
#+end_src
*** Tikz
#+begin_src conf :tangle ~/.spacemacs.d/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 ~/.spacemacs.d/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}")
2019-08-23 10:03:32 +02:00
#+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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/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 ~/.spacemacs.d/snippets/org-mode/wrap
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Wrap
# --
#+attr_latex: :float wrap
$0
#+end_src
*** Latex
**** Integral
#+begin_src conf :tangle ~/.spacemacs.d/snippets/org-mode/latex/int
# -*- mode: snippet -*-
# name: latex integral
# key: int
# contributor: John Kitchin <jkitchin@andrew.cmu.edu>
# --
\int_{$1}^{$2} $3d$4$0
#+end_src