emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-babel-do-load-languages
@ 2018-05-03 11:19 N. Raghavendra
  2018-05-03 11:38 ` org-babel-do-load-languages N. Raghavendra
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: N. Raghavendra @ 2018-05-03 11:19 UTC (permalink / raw)
  To: emacs-orgmode

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 <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-babel-do-load-languages
  2018-05-03 11:19 org-babel-do-load-languages N. Raghavendra
@ 2018-05-03 11:38 ` N. Raghavendra
  2018-05-03 13:07 ` org-babel-do-load-languages Aaron Ecay
  2018-05-03 19:58 ` org-babel-do-load-languages Nicolas Goaziou
  2 siblings, 0 replies; 7+ messages in thread
From: N. Raghavendra @ 2018-05-03 11:38 UTC (permalink / raw)
  To: emacs-orgmode

At 2018-05-03T16:49:01+05:30, N. Raghavendra wrote:

>   (set-default org-babel-load-languages languages)

I meant `setq-default' there, not `set-default'.

Raghu.

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-babel-do-load-languages
  2018-05-03 11:19 org-babel-do-load-languages N. Raghavendra
  2018-05-03 11:38 ` org-babel-do-load-languages N. Raghavendra
@ 2018-05-03 13:07 ` Aaron Ecay
  2018-05-03 13:54   ` org-babel-do-load-languages N. Raghavendra
  2018-05-03 19:58 ` org-babel-do-load-languages Nicolas Goaziou
  2 siblings, 1 reply; 7+ messages in thread
From: Aaron Ecay @ 2018-05-03 13:07 UTC (permalink / raw)
  To: N. Raghavendra, emacs-orgmode

Hi Raghu,

2018ko maiatzak 3an, "N. Raghavendra"-ek idatzi zuen:
> 
> I am puzzled with this definition:

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-babel-do-load-languages
  2018-05-03 13:07 ` org-babel-do-load-languages Aaron Ecay
@ 2018-05-03 13:54   ` N. Raghavendra
       [not found]     ` <87in84rfim.fsf@gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: N. Raghavendra @ 2018-05-03 13:54 UTC (permalink / raw)
  To: emacs-orgmode

At 2018-05-03T14:07:37+01:00, Aaron Ecay wrote:

> 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 <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-babel-do-load-languages
  2018-05-03 11:19 org-babel-do-load-languages N. Raghavendra
  2018-05-03 11:38 ` org-babel-do-load-languages N. Raghavendra
  2018-05-03 13:07 ` org-babel-do-load-languages Aaron Ecay
@ 2018-05-03 19:58 ` Nicolas Goaziou
  2018-05-04  2:31   ` org-babel-do-load-languages N. Raghavendra
  2 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2018-05-03 19:58 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

"N. Raghavendra" <nyraghu27132@gmail.com> writes:
> 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)))

Language names are not symbols. It should be Emacs Lisp and R. See,
e.g., Emacs and ESS manuals.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-babel-do-load-languages
  2018-05-03 19:58 ` org-babel-do-load-languages Nicolas Goaziou
@ 2018-05-04  2:31   ` N. Raghavendra
  0 siblings, 0 replies; 7+ messages in thread
From: N. Raghavendra @ 2018-05-04  2:31 UTC (permalink / raw)
  To: emacs-orgmode

At 2018-05-03T21:58:46+02:00, Nicolas Goaziou wrote:

>>    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 <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-babel-do-load-languages
       [not found]     ` <87in84rfim.fsf@gmail.com>
@ 2018-05-04  2:38       ` N. Raghavendra
  0 siblings, 0 replies; 7+ messages in thread
From: N. Raghavendra @ 2018-05-04  2:38 UTC (permalink / raw)
  To: emacs-orgmode

At 2018-05-03T15:16:17+01:00, Aaron Ecay wrote:

> In principle, you are correct.  However:
>
>> 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.

>> (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 <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-05-04  2:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-03 11:19 org-babel-do-load-languages N. Raghavendra
2018-05-03 11:38 ` org-babel-do-load-languages N. Raghavendra
2018-05-03 13:07 ` org-babel-do-load-languages Aaron Ecay
2018-05-03 13:54   ` org-babel-do-load-languages N. Raghavendra
     [not found]     ` <87in84rfim.fsf@gmail.com>
2018-05-04  2:38       ` org-babel-do-load-languages N. Raghavendra
2018-05-03 19:58 ` org-babel-do-load-languages Nicolas Goaziou
2018-05-04  2:31   ` org-babel-do-load-languages N. Raghavendra

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).