Commit 1635efcd authored by Konrad Hinsen's avatar Konrad Hinsen

init.el pleinement compatible avec orgmode 9.2

parent cff12ba6
...@@ -227,51 +227,64 @@ Entered on %U ...@@ -227,51 +227,64 @@ Entered on %U
)) ))
(setq org-src-preserve-indentation t) (setq org-src-preserve-indentation t)
(require 'org-tempo nil t) (setq rrmooc/new-org-templates (version<= "9.2" (org-version)))
(when rrmooc/new-org-templates
(require 'org-tempo))
(add-to-list 'org-structure-template-alist (require 'subr-x)
'("s" "#+begin_src ?\n\n#+end_src" "<src lang=\"?\">\n\n</src>")) (defun rrmooc/add-org-template (old-style-template)
(add-to-list 'org-structure-template-alist
(if rrmooc/new-org-templates
(cons
(first old-style-template)
(string-trim-right (substring (second old-style-template) 8 -9)))
old-style-template)))
(unless rrmooc/new-org-templates
;; this template is predefined in the new templating system
(rrmooc/add-org-template
'("s" "#+begin_src ?\n\n#+end_src" "<src lang=\"?\">\n\n</src>")))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("m" "#+begin_src emacs-lisp :tangle init.el\n\n#+end_src" "<src lang=\"emacs-lisp\">\n\n</src>")) '("m" "#+begin_src emacs-lisp\n\n#+end_src" "<src lang=\"emacs-lisp\">\n\n</src>"))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("r" "#+begin_src R :results output :session *R* :exports both\n\n#+end_src" "<src lang=\"R\">\n\n</src>")) '("r" "#+begin_src R :results output :session *R* :exports both\n\n#+end_src" "<src lang=\"R\">\n\n</src>"))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("R" "#+begin_src R :results output graphics :file (org-babel-temp-file \"figure\" \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>")) '("R" "#+begin_src R :results output graphics :file (org-babel-temp-file \"figure\" \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>"))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("RR" "#+begin_src R :results output graphics :file (org-babel-temp-file (concat (file-name-directory (or load-file-name buffer-file-name)) \"figure-\") \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>")) '("RR" "#+begin_src R :results output graphics :file (org-babel-temp-file (concat (file-name-directory (or load-file-name buffer-file-name)) \"figure-\") \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>"))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("p" "#+begin_src python :results output :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>")) '("p" "#+begin_src python :results output :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>"))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("P" "#+begin_src python :results output :session :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>")) '("P" "#+begin_src python :results output :session :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>"))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("PP" "#+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file \"figure\" \".png\") :exports both\nimport matplotlib.pyplot as plt\n\nimport numpy\nx=numpy.linspace(-15,15)\nplt.figure(figsize=(10,5))\nplt.plot(x,numpy.cos(x)/x)\nplt.tight_layout()\n\nplt.savefig(matplot_lib_filename)\nmatplot_lib_filename\n#+end_src" "<src lang=\"python\">\n\n</src>")) '("PP" "#+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file \"figure\" \".png\") :exports both\nimport matplotlib.pyplot as plt\n\nimport numpy\nx=numpy.linspace(-15,15)\nplt.figure(figsize=(10,5))\nplt.plot(x,numpy.cos(x)/x)\nplt.tight_layout()\n\nplt.savefig(matplot_lib_filename)\nmatplot_lib_filename\n#+end_src" "<src lang=\"python\">\n\n</src>"))
(if (memq system-type '(windows-nt ms-dos)) (if (memq system-type '(windows-nt ms-dos))
;; Non-session shell execution does not seem to work under Windows, so we use ;; Non-session shell execution does not seem to work under Windows, so we use
;; a named session just like for B. ;; a named session just like for B.
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("b" "#+begin_src shell :session session :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>")) '("b" "#+begin_src shell :session session :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("b" "#+begin_src shell :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))) '("b" "#+begin_src shell :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>")))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("B" "#+begin_src shell :session *shell* :results output :exports both \n\n#+end_src" "<src lang=\"sh\">\n\n</src>")) '("B" "#+begin_src shell :session *shell* :results output :exports both \n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("g" "#+begin_src dot :results output graphics :file \"/tmp/graph.pdf\" :exports both '("g" "#+begin_src dot :results output graphics :file \"/tmp/graph.pdf\" :exports both
digraph G { digraph G {
node [color=black,fillcolor=white,shape=rectangle,style=filled,fontname=\"Helvetica\"]; node [color=black,fillcolor=white,shape=rectangle,style=filled,fontname=\"Helvetica\"];
A[label=\"A\"] A[label=\"A\"]
B[label=\"B\"] B[label=\"B\"]
A->B A->B
}\n#+end_src" "<src lang=\"dot\">\n\n</src>")) }\n#+end_src" "<src lang=\"dot\">\n\n</src>"))
(global-set-key (kbd "C-c S-t") 'org-babel-execute-subtree) (global-set-key (kbd "C-c S-t") 'org-babel-execute-subtree)
......
...@@ -83,7 +83,7 @@ document, simply =M-x org-babel-tangle=. ...@@ -83,7 +83,7 @@ document, simply =M-x org-babel-tangle=.
("melpa-stable" . 10))) ("melpa-stable" . 10)))
#+END_SRC #+END_SRC
* Install missing packages * Install missing packages
#+begin_src emacs-lisp #+begin_src emacs-lisp :tangle init.el
(dolist (pkg '(ess (dolist (pkg '(ess
auctex auctex
htmlize htmlize
...@@ -92,7 +92,7 @@ document, simply =M-x org-babel-tangle=. ...@@ -92,7 +92,7 @@ document, simply =M-x org-babel-tangle=.
(package-install pkg))) (package-install pkg)))
#+end_src #+end_src
* Import environment variables * Import environment variables
#+begin_src emacs-lisp #+begin_src emacs-lisp :tangle init.el
(exec-path-from-shell-initialize) (exec-path-from-shell-initialize)
(exec-path-from-shell-copy-env "PYTHONPATH") (exec-path-from-shell-copy-env "PYTHONPATH")
#+end_src #+end_src
...@@ -366,57 +366,72 @@ Additional shortcuts for navigating through org-mode documents: ...@@ -366,57 +366,72 @@ Additional shortcuts for navigating through org-mode documents:
** Adding source code blocks: :LUKA: ** Adding source code blocks: :LUKA:
*** Enable the old template system with Orgmode 9.2 and later *** Enable the old template system with Orgmode 9.2 and later
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(require 'org-tempo nil t) (setq rrmooc/new-org-templates (version<= "9.2" (org-version)))
(when rrmooc/new-org-templates
(require 'org-tempo))
#+end_src
*** Template definitions that work with the old and new templating systems
#+begin_src emacs-lisp :tangle init.el
(require 'subr-x)
(defun rrmooc/add-org-template (old-style-template)
(add-to-list 'org-structure-template-alist
(if rrmooc/new-org-templates
(cons
(first old-style-template)
(string-trim-right (substring (second old-style-template) 8 -9)))
old-style-template)))
#+end_src #+end_src
*** With capital letters: *** With capital letters:
To use this type <s and then TAB To use this type <s and then TAB
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (unless rrmooc/new-org-templates
'("s" "#+begin_src ?\n\n#+end_src" "<src lang=\"?\">\n\n</src>")) ;; this template is predefined in the new templating system
(rrmooc/add-org-template
'("s" "#+begin_src ?\n\n#+end_src" "<src lang=\"?\">\n\n</src>")))
#+end_src #+end_src
*** Emacs-elisp code: *** Emacs-elisp code:
To use this type <m and then TAB To use this type <m and then TAB
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("m" "#+begin_src emacs-lisp :tangle init.el\n\n#+end_src" "<src lang=\"emacs-lisp\">\n\n</src>")) '("m" "#+begin_src emacs-lisp\n\n#+end_src" "<src lang=\"emacs-lisp\">\n\n</src>"))
#+end_src #+end_src
*** R code: *** R code:
To use this type <r and then TAB. This creates an R block for textual output. To use this type <r and then TAB. This creates an R block for textual output.
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("r" "#+begin_src R :results output :session *R* :exports both\n\n#+end_src" "<src lang=\"R\">\n\n</src>")) '("r" "#+begin_src R :results output :session *R* :exports both\n\n#+end_src" "<src lang=\"R\">\n\n</src>"))
#+end_src #+end_src
To use this type <R and then TAB. This creates an R block for graphics To use this type <R and then TAB. This creates an R block for graphics
that are stored in the =/tmp/=. that are stored in the =/tmp/=.
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("R" "#+begin_src R :results output graphics :file (org-babel-temp-file \"figure\" \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>")) '("R" "#+begin_src R :results output graphics :file (org-babel-temp-file \"figure\" \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>"))
#+end_src #+end_src
To use this type <RR and then TAB. This creates an R block for To use this type <RR and then TAB. This creates an R block for
graphics that are stored in the directory of the current file. graphics that are stored in the directory of the current file.
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("RR" "#+begin_src R :results output graphics :file (org-babel-temp-file (concat (file-name-directory (or load-file-name buffer-file-name)) \"figure-\") \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>")) '("RR" "#+begin_src R :results output graphics :file (org-babel-temp-file (concat (file-name-directory (or load-file-name buffer-file-name)) \"figure-\") \".png\") :exports both :width 600 :height 400 :session *R* \n\n#+end_src" "<src lang=\"R\">\n\n</src>"))
#+end_src #+end_src
*** Python code *** Python code
To use this type <p and then TAB To use this type <p and then TAB
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("p" "#+begin_src python :results output :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>")) '("p" "#+begin_src python :results output :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>"))
#+end_src #+end_src
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("P" "#+begin_src python :results output :session :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>")) '("P" "#+begin_src python :results output :session :exports both\n\n#+end_src" "<src lang=\"python\">\n\n</src>"))
#+end_src #+end_src
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("PP" "#+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file \"figure\" \".png\") :exports both\nimport matplotlib.pyplot as plt\n\nimport numpy\nx=numpy.linspace(-15,15)\nplt.figure(figsize=(10,5))\nplt.plot(x,numpy.cos(x)/x)\nplt.tight_layout()\n\nplt.savefig(matplot_lib_filename)\nmatplot_lib_filename\n#+end_src" "<src lang=\"python\">\n\n</src>")) '("PP" "#+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file \"figure\" \".png\") :exports both\nimport matplotlib.pyplot as plt\n\nimport numpy\nx=numpy.linspace(-15,15)\nplt.figure(figsize=(10,5))\nplt.plot(x,numpy.cos(x)/x)\nplt.tight_layout()\n\nplt.savefig(matplot_lib_filename)\nmatplot_lib_filename\n#+end_src" "<src lang=\"python\">\n\n</src>"))
#+end_src #+end_src
*** Bash "sh" code: *** Bash "sh" code:
To use this type <b and then TAB To use this type <b and then TAB
...@@ -424,28 +439,28 @@ To use this type <b and then TAB ...@@ -424,28 +439,28 @@ To use this type <b and then TAB
(if (memq system-type '(windows-nt ms-dos)) (if (memq system-type '(windows-nt ms-dos))
;; Non-session shell execution does not seem to work under Windows, so we use ;; Non-session shell execution does not seem to work under Windows, so we use
;; a named session just like for B. ;; a named session just like for B.
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("b" "#+begin_src shell :session session :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>")) '("b" "#+begin_src shell :session session :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("b" "#+begin_src shell :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))) '("b" "#+begin_src shell :results output :exports both\n\n#+end_src" "<src lang=\"sh\">\n\n</src>")))
#+end_src #+end_src
To use this type <B and then TAB. This comes with a session argument To use this type <B and then TAB. This comes with a session argument
(e.g., in case you want to keep ssh connexions open). (e.g., in case you want to keep ssh connexions open).
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("B" "#+begin_src shell :session *shell* :results output :exports both \n\n#+end_src" "<src lang=\"sh\">\n\n</src>")) '("B" "#+begin_src shell :session *shell* :results output :exports both \n\n#+end_src" "<src lang=\"sh\">\n\n</src>"))
#+end_src #+end_src
*** Graphviz *** Graphviz
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
(add-to-list 'org-structure-template-alist (rrmooc/add-org-template
'("g" "#+begin_src dot :results output graphics :file \"/tmp/graph.pdf\" :exports both '("g" "#+begin_src dot :results output graphics :file \"/tmp/graph.pdf\" :exports both
digraph G { digraph G {
node [color=black,fillcolor=white,shape=rectangle,style=filled,fontname=\"Helvetica\"]; node [color=black,fillcolor=white,shape=rectangle,style=filled,fontname=\"Helvetica\"];
A[label=\"A\"] A[label=\"A\"]
B[label=\"B\"] B[label=\"B\"]
A->B A->B
}\n#+end_src" "<src lang=\"dot\">\n\n</src>")) }\n#+end_src" "<src lang=\"dot\">\n\n</src>"))
#+end_src #+end_src
** Evaluating whole subtree: :LUKA: ** Evaluating whole subtree: :LUKA:
#+begin_src emacs-lisp :tangle init.el #+begin_src emacs-lisp :tangle init.el
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment