mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-26 18:00:53 +00:00
ob-emacs-lisp: Make lexical eval default for elisp src blocks
* lisp/ob-emacs-lisp.el (org-babel-header-args:emacs-lisp): (org-babel-default-header-args:emacs-lisp): New variables. (org-babel-execute:emacs-lisp): Add an optional argument to the eval function.
This commit is contained in:
parent
b2411769cf
commit
516bbf417c
11
etc/ORG-NEWS
11
etc/ORG-NEWS
|
@ -467,6 +467,17 @@ docstring for more information.
|
||||||
- ~org-latex-format-inlinetask-function~
|
- ~org-latex-format-inlinetask-function~
|
||||||
- ~org-link-search~
|
- ~org-link-search~
|
||||||
** New features
|
** New features
|
||||||
|
*** Default lexical evaluation of emacs-lisp src blocks
|
||||||
|
Emacs-lisp src blocks in babel are now evaluated using lexical scoping. There is a new header to control this behavior.
|
||||||
|
|
||||||
|
The default results in an eval with lexical scoping.
|
||||||
|
:lexical yes
|
||||||
|
|
||||||
|
This turns lexical scoping off in the eval (the former behavior).
|
||||||
|
:lexical no
|
||||||
|
|
||||||
|
This uses the lexical environment with x=42 in the eval.
|
||||||
|
:lexical '((x . 42))
|
||||||
|
|
||||||
*** Behavior of ~org-return~ changed
|
*** Behavior of ~org-return~ changed
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,16 @@
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'ob)
|
(require 'ob)
|
||||||
|
|
||||||
(defvar org-babel-default-header-args:emacs-lisp nil
|
(defconst org-babel-header-args:emacs-lisp '((lexical . :any))
|
||||||
"Default arguments for evaluating an emacs-lisp source block.")
|
"Emacs-lisp specific header arguments.")
|
||||||
|
|
||||||
|
(defvar org-babel-default-header-args:emacs-lisp '((:lexical . "yes"))
|
||||||
|
"Default arguments for evaluating an emacs-lisp source block.
|
||||||
|
|
||||||
|
:lexical is \"yes\" by default and causes src blocks to be eval'd
|
||||||
|
using lexical scoping. It can also be an alist mapping symbols to
|
||||||
|
their value. It is used as the optional LEXICAL argument to
|
||||||
|
`eval', which see.")
|
||||||
|
|
||||||
(defun org-babel-expand-body:emacs-lisp (body params)
|
(defun org-babel-expand-body:emacs-lisp (body params)
|
||||||
"Expand BODY according to PARAMS, return the expanded body."
|
"Expand BODY according to PARAMS, return the expanded body."
|
||||||
|
@ -51,13 +59,18 @@
|
||||||
(defun org-babel-execute:emacs-lisp (body params)
|
(defun org-babel-execute:emacs-lisp (body params)
|
||||||
"Execute a block of emacs-lisp code with Babel."
|
"Execute a block of emacs-lisp code with Babel."
|
||||||
(save-window-excursion
|
(save-window-excursion
|
||||||
(let ((result
|
(let* ((lexical (cdr (assq :lexical params)))
|
||||||
(eval (read (format (if (member "output"
|
(result
|
||||||
(cdr (assoc :result-params params)))
|
(eval (read (format (if (member "output"
|
||||||
"(with-output-to-string %s)"
|
(cdr (assq :result-params params)))
|
||||||
"(progn %s)")
|
"(with-output-to-string %s)"
|
||||||
(org-babel-expand-body:emacs-lisp
|
"(progn %s)")
|
||||||
body params))))))
|
(org-babel-expand-body:emacs-lisp
|
||||||
|
body params)))
|
||||||
|
|
||||||
|
(if (listp lexical)
|
||||||
|
lexical
|
||||||
|
(member lexical '("yes" "t"))))))
|
||||||
(org-babel-result-cond (cdr (assoc :result-params params))
|
(org-babel-result-cond (cdr (assoc :result-params params))
|
||||||
(let ((print-level nil)
|
(let ((print-level nil)
|
||||||
(print-length nil))
|
(print-length nil))
|
||||||
|
|
Loading…
Reference in a new issue