Overhaul setting the `org-babel-load-languages' option

This commit is contained in:
Gerard Vermeulen 2023-01-20 07:06:51 +01:00
parent 69b818c493
commit 8a6071f20e

View File

@ -2015,11 +2015,8 @@ of the [[info:org#Top][Org (info)]] manual.
I have split the initial [[https://orgmode.org/][Org-mode]] setup over several listings. Here, follows a
list detailing and motivating each listing:
1. Listing [[lst:set-org-options]] handles basic [[https://orgmode.org/][Org-mode]] options.
2. Listing [[lst:set-org-babel-options]] handles basic [[https://orgmode.org/][Org-mode]] options specific to
[[info:org#Working with Source Code][work with source code (info)]] and it
selects the Python interpreter by means of
src_emacs-lisp{(choose-common-python-interpreter)} defined in listing
[[lst:choose-common-python-interpreter]].
2. Listing [[lst:setup-org-babel]] handles basic [[https://orgmode.org/][Org-mode]] options specific to
[[info:org#Working with Source Code][work with source code (info)]].
3. Listing [[lst:set-org-link-options]] handles [[https://orgmode.org/][Org-mode]] options specific to
[[info:org#Hyperlinks][hyperlinks (info)]].
4. Listing [[lst:setup-org-mode-map]] extends the =org-mode-map= with useful
@ -2050,19 +2047,18 @@ list detailing and motivating each listing:
(calc . t)
(dot . ,(fboundp 'grapviz-dot-mode))
(emacs-lisp . t)
;; (eshell . t) ; bug
(fortran . t)
(gnuplot . ,(fboundp 'gnuplot-mode))
(js . t)
(latex . t)
(lisp . t)
(lua . ,(fboundp 'lua-mode))
;; (lua . ,(fboundp 'lua-mode)) ; bug
(maxima . ,(fboundp 'maxima-mode))
(org . t)
(perl . t)
;; The Python setup uses the two functions below.
;; Those functions are not yet bound during bootstrap.
(python . ,(and (fboundp 'choose-common-python-interpreter)
(fboundp 'choose-common-python-linter)))
;; Postpone Python activation to prevent calling still unbound functions.
(python . nil)
(shell . t))
org-export-backends '(ascii beamer html icalendar latex odt texinfo)
org-file-apps '((auto-mode . emacs)
@ -2110,8 +2106,38 @@ list detailing and motivating each listing:
(with-eval-after-load 'sly
(setopt org-babel-lisp-eval-fn #'sly-eval)))
(with-eval-after-load 'ob-python
(choose-common-python-interpreter 'python))
(with-eval-after-load 'emacs
(defun set-org-babel-language-activity (lang active)
"Set the `org-babel' activity of language LANG to ACTIVE.
Let `org-babel-do-load-languages' load ob-LANG when ACTIVE is t or
unbind the `org-babel' interface functions when ACTIVE is nil."
(if (locate-library (format "ob-%s" lang))
(or (org-babel-do-load-languages
'org-babel-load-languages
(cons (cons lang active)
(assq-delete-all
lang (default-toplevel-value 'org-babel-load-languages))))
org-babel-load-languages)
(warn "Can't locate `ob-%s', hence don't set `%s' activity" lang lang)))
(defun activate-org-babel-language (lang)
"Activate LANG for `org-babel'."
(interactive "SActivate language: ")
(if (set-org-babel-language-activity lang t)
(message "Did activate `%s' for `org-babel'" lang)
(message "Can't activate `%s' for `org-babel'" lang)))
(defun deactivate-org-babel-language (lang)
"Activate LANG for `org-babel'."
(interactive "SDeactivate language: ")
(if (set-org-babel-language-activity lang nil)
(message "Did deactivate `%s' for `org-babel'" lang)
(message "Can't deactivate `%s' for `org-babel'" lang)))
;; Work around a "(defcustom org-babel-load-languages)" call bug.
(set-org-babel-language-activity 'eshell t)
(set-org-babel-language-activity 'ruby (fboundp 'lua-mode)))
#+end_src
#+caption[Set =org-link= options]:
@ -4273,7 +4299,7 @@ install and use [[https://gitlab.com/andreyorst/ob-fennel][ob-fennel]] with the
(unless (package-installed-p 'ob-fennel)
(quelpa '(ob-fennel :repo "andreyorst/ob-fennel" :fetcher gitlab)))
(when (ensure-package-selection 'ob-fennel)
(org-babel-do-load-languages 'fennel (fboundp 'fennel-mode))))
(set-org-babel-language-activity 'fennel (fboundp 'fennel-mode))))
#+end_src
#+caption[Fennel example]:
@ -4426,6 +4452,8 @@ Finally, listing [[lst:flake8-nocolor][flake8-nocolor]] and [[lst:ruff-nocolor][
(defun choose-common-python-interpreter (&optional interpreter)
"Let `ob-python' and `python-mode' use the same Python INTERPRETER."
(interactive)
(unless (featurep 'ob-python)
(set-org-babel-language-activity 'python (fboundp 'python-mode)))
(let* ((prompt (format "Choose Python (%s): "
(bound-and-true-p python-shell-interpreter)))
(choices '(ipython python))