lang/org: lazy-load babel libraries
Removes +org-babel-languages and no longer eagerly loads babel libraries. If an ob-*.el exists for the language, it will be loaded once you execute its src block. Warning: this may interfere with tangling. An unloaded library can't register a language extension in org-babel-tangle-lang-exts (if any). This means babel won't be able to figure out the correct file extension for certain src blocks. Either load the package explicitly or provide a filename + extension for the TARGET-FILE argument: (require 'ob-rust) (org-babel-tangle-file "notes.org") ;; or (org-babel-tangle-file "notes.org" "notes.rs")
This commit is contained in:
parent
01a5e9a1d7
commit
78cb47a072
1 changed files with 9 additions and 27 deletions
|
@ -2,29 +2,6 @@
|
|||
|
||||
(add-hook 'org-load-hook #'+org|init-babel)
|
||||
|
||||
(defvar +org-babel-languages
|
||||
'(calc
|
||||
css
|
||||
emacs-lisp
|
||||
haskell
|
||||
js
|
||||
latex
|
||||
ledger
|
||||
lilypond
|
||||
lisp
|
||||
matlab
|
||||
plantuml
|
||||
python
|
||||
restclient ; ob-restclient
|
||||
ruby
|
||||
rust ; ob-rust
|
||||
shell
|
||||
sqlite
|
||||
sql-mode ; ob-sql-mode
|
||||
translate) ; ob-translate
|
||||
"A list of org-babel languages to load.")
|
||||
|
||||
|
||||
(defun +org|init-babel ()
|
||||
(setq org-src-fontify-natively t ; make code pretty
|
||||
org-src-preserve-indentation t ; use native major-mode indentation
|
||||
|
@ -32,10 +9,15 @@
|
|||
org-src-window-setup 'current-window
|
||||
org-confirm-babel-evaluate nil) ; you don't need my permission
|
||||
|
||||
(org-babel-do-load-languages
|
||||
'org-babel-load-languages
|
||||
(cl-loop for sym in +org-babel-languages
|
||||
collect (cons sym t)))
|
||||
(defun +org*babel-execute-src-block (orig-fn &rest args)
|
||||
"Load babel libraries as needed when babel blocks are executed."
|
||||
(let* ((language (org-element-property :language (org-element-at-point)))
|
||||
(lang-sym (intern language)))
|
||||
(unless (cdr (assoc lang-sym org-babel-load-languages))
|
||||
(require (intern (format "ob-%s" language)))
|
||||
(add-to-list 'org-babel-load-languages (cons lang-sym t)))
|
||||
(apply orig-fn args)))
|
||||
(advice-add #'org-babel-execute-src-block :around #'+org*babel-execute-src-block)
|
||||
|
||||
;; I prefer C-c C-c for confirming over the default C-c '
|
||||
(map! :map org-src-mode-map "C-c C-c" #'org-edit-src-exit)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue