mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
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")
33 lines
1.4 KiB
EmacsLisp
33 lines
1.4 KiB
EmacsLisp
;;; lang/org/+babel.el -*- lexical-binding: t; -*-
|
|
|
|
(add-hook 'org-load-hook #'+org|init-babel)
|
|
|
|
(defun +org|init-babel ()
|
|
(setq org-src-fontify-natively t ; make code pretty
|
|
org-src-preserve-indentation t ; use native major-mode indentation
|
|
org-src-tab-acts-natively t
|
|
org-src-window-setup 'current-window
|
|
org-confirm-babel-evaluate nil) ; you don't need my permission
|
|
|
|
(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)
|
|
|
|
;; In a recent update, `org-babel-get-header' was removed from org-mode, which
|
|
;; is something a fair number of babel plugins use. So until those plugins
|
|
;; update, this polyfill will do:
|
|
(defun org-babel-get-header (params key &optional others)
|
|
(cl-loop with fn = (if others #'not #'identity)
|
|
for p in params
|
|
if (funcall fn (eq (car p) key))
|
|
collect p)))
|