summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Kitchin <jkitchin@andrew.cmu.edu>2016-04-18 13:55:34 -0400
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-04-19 21:40:21 +0200
commit516bbf417c5cdc3fcf701ae3a8e4fa610761264b (patch)
treea93e9ea20079cf7d8263a6240368e5fc9ac22e57
parentb2411769cfa3bd5267b08bb266ac502ec58a786e (diff)
downloadorg-mode-516bbf417c5cdc3fcf701ae3a8e4fa610761264b.tar.gz
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.
-rw-r--r--etc/ORG-NEWS11
-rw-r--r--lisp/ob-emacs-lisp.el31
2 files changed, 33 insertions, 9 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 6b1d9d5..99241e2 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -467,6 +467,17 @@ docstring for more information.
- ~org-latex-format-inlinetask-function~
- ~org-link-search~
** 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
diff --git a/lisp/ob-emacs-lisp.el b/lisp/ob-emacs-lisp.el
index 2eb2721..c53435a 100644
--- a/lisp/ob-emacs-lisp.el
+++ b/lisp/ob-emacs-lisp.el
@@ -28,8 +28,16 @@
;;; Code:
(require 'ob)
-(defvar org-babel-default-header-args:emacs-lisp nil
- "Default arguments for evaluating an emacs-lisp source block.")
+(defconst org-babel-header-args:emacs-lisp '((lexical . :any))
+ "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)
"Expand BODY according to PARAMS, return the expanded body."
@@ -51,13 +59,18 @@
(defun org-babel-execute:emacs-lisp (body params)
"Execute a block of emacs-lisp code with Babel."
(save-window-excursion
- (let ((result
- (eval (read (format (if (member "output"
- (cdr (assoc :result-params params)))
- "(with-output-to-string %s)"
- "(progn %s)")
- (org-babel-expand-body:emacs-lisp
- body params))))))
+ (let* ((lexical (cdr (assq :lexical params)))
+ (result
+ (eval (read (format (if (member "output"
+ (cdr (assq :result-params params)))
+ "(with-output-to-string %s)"
+ "(progn %s)")
+ (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))
(let ((print-level nil)
(print-length nil))