Discussion:
[O] org-babel-do-load-languages
N. Raghavendra
2018-05-03 11:19:01 UTC
Permalink
I am puzzled with this definition:

------------------------------------------------------------
(defun org-babel-do-load-languages (sym value)
"Load the languages defined in `org-babel-load-languages'."
(set-default sym value)
(dolist (pair org-babel-load-languages)
(let ((active (cdr pair)) (lang (symbol-name (car pair))))
(if active
(require (intern (concat "ob-" lang)))
(funcall 'fmakunbound
(intern (concat "org-babel-execute:" lang)))
(funcall 'fmakunbound
(intern (concat "org-babel-expand-body:" lang)))))))
------------------------------------------------------------

First, the documentation string doesn't explain the significance of the
parameters SYM and VALUE. Second, the main part of the function, that
is, the expression

(dolist (pair org-babel-load-languages) ...)

does not refer either to SYM or VALUE. Therefore, I suggest changing
the definition along the following lines:

------------------------------------------------------------
(defun my-org-babel-do-load-languages (languages)
"Load languages as specified by LANGUAGES.
LANGUAGES must be a list, each element of which is of the form
(LANG . ACTIVE), where LANG is the identifier of a supported
language, and ACTIVE is either t, for loading LANG, or nil, for
unloading LANG. For a list of the supported languages and their
identifiers, see the Info node `(Org)Languages'."
(set-default org-babel-load-languages languages)
(dolist (pair org-babel-load-languages)
(let ((active (cdr pair)) (lang (symbol-name (car pair))))
(if active
(require (intern (concat "ob-" lang)))
(funcall 'fmakunbound
(intern (concat "org-babel-execute:" lang)))
(funcall 'fmakunbound
(intern (concat "org-babel-expand-body:" lang)))))))
------------------------------------------------------------

I also suggest a corresponding change in Org(Languages):

------------------------------------------------------------
By default, only ‘emacs-lisp’ is enabled for evaluation. To enable
or disable other languages, customize the ‘org-babel-load-languages’
variable either through the Emacs customization interface, or by adding
code to the init file as shown next:

In this example, evaluation is disabled for ‘emacs-lisp’, and enabled
for ‘R’.

(org-babel-do-load-languages
'((emacs-lisp . nil)
(R . t)))
------------------------------------------------------------

Raghu.

--
N. Raghavendra <***@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/
N. Raghavendra
2018-05-03 11:38:32 UTC
Permalink
Post by N. Raghavendra
(set-default org-babel-load-languages languages)
I meant `setq-default' there, not `set-default'.

Raghu.
--
N. Raghavendra <***@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/
Aaron Ecay
2018-05-03 13:07:37 UTC
Permalink
Hi Raghu,
Itʼs an unusual function indeed. Thatʼs because it is used as the :set
function for the defcustom org-babel-load-languages; see the info
documentation (info "(elisp) Variable Definitions").
--
Aaron Ecay
N. Raghavendra
2018-05-03 13:54:35 UTC
Permalink
Post by Aaron Ecay
Itʼs an unusual function indeed. Thatʼs because it is used as the :set
function for the defcustom org-babel-load-languages; see the info
documentation (info "(elisp) Variable Definitions").
Thank you for explaining. I still think it would be better to avoid
unexplained parameters in the user-level function
org-babel-do-load-languages. I wonder if something like

------------------------------------------------------------
(defun org-babel-do-load-languages (languages)
"Load languages as specified by LANGUAGES.
LANGUAGES must be a list, each element of which is of the form
(LANG . ACTIVE), where LANG is the identifier of a supported
language, and ACTIVE is either t, for loading LANG, or nil, for
unloading LANG. For a list of the supported languages and their
identifiers, see the Info node `(Org)Languages'."
(setq-default org-babel-load-languages languages)
(dolist (pair org-babel-load-languages)
(let ((active (cdr pair)) (lang (symbol-name (car pair))))
(if active
(require (intern (concat "ob-" lang)))
(funcall 'fmakunbound
(intern (concat "org-babel-execute:" lang)))
(funcall 'fmakunbound
(intern (concat "org-babel-expand-body:" lang)))))))

(defcustom org-babel-load-languages '((emacs-lisp . t))
...
:set #'(lambda (sym value)
(ignore sym)
(org-babel-do-load-languages value))
...)
------------------------------------------------------------

looks reasonable.

Raghu.

--
N. Raghavendra <***@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/
N. Raghavendra
2018-05-04 02:38:13 UTC
Permalink
Post by N. Raghavendra
I wonder if something like
------------------------------------------------------------
(defun org-babel-do-load-languages (languages)
If we change the arity of the function in this way, usersʼ
configurations will break. We could deprecate the old arity-2 calling
convention, but continue to support it (and give warnings when it is
used) long enough for users to change their configurations.
Is it worth it though? Why not just add a docstring to the existing
function that explains its calling convention and call it a day?
This is a good solution.
Post by N. Raghavendra
(defcustom org-babel-load-languages '((emacs-lisp . t))
...
:set #'(lambda (sym value)
(ignore sym)
You can achieve the same by naming the argument _sym without calling
ignore. Underscore-prefixed names are better (in general) than
ignore, since the byte compiler will warn if you try to access their
value (whereas, AFAIK, there is no warning if you access an ignore-d
variable, and thus ignore may be mistakenly misleading. Since the
function is so short in this case, the issue doesnʼt really arise).
Thanks for that explanation too, I didn't know that.

Regards,

Raghu.

--
N. Raghavendra <***@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

Nicolas Goaziou
2018-05-03 19:58:46 UTC
Permalink
Hello,
Post by N. Raghavendra
------------------------------------------------------------
By default, only ‘emacs-lisp’ is enabled for evaluation. To enable
or disable other languages, customize the ‘org-babel-load-languages’
variable either through the Emacs customization interface, or by adding
In this example, evaluation is disabled for ‘emacs-lisp’, and enabled
for ‘R’.
(org-babel-do-load-languages
'((emacs-lisp . nil)
(R . t)))
Language names are not symbols. It should be Emacs Lisp and R. See,
e.g., Emacs and ESS manuals.

Regards,
--
Nicolas Goaziou
N. Raghavendra
2018-05-04 02:31:11 UTC
Permalink
Post by Nicolas Goaziou
Post by N. Raghavendra
In this example, evaluation is disabled for ‘emacs-lisp’, and enabled
for ‘R’.
(org-babel-do-load-languages
'((emacs-lisp . nil)
(R . t)))
Language names are not symbols. It should be Emacs Lisp and R. See,
e.g., Emacs and ESS manuals.
I agree, but I just copied the text from the current Org manual.

Raghu.

--
N. Raghavendra <***@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/
Loading...