From: John Kitchin <jkitchin@andrew.cmu.edu>
To: emacs-orgmode@gnu.org
Cc: John Kitchin <jkitchin@andrew.cmu.edu>
Subject: [PATCH] Make lexical eval default for elisp src blocks
Date: Mon, 18 Apr 2016 13:55:34 -0400 [thread overview]
Message-ID: <1461002134-49405-1-git-send-email-jkitchin@andrew.cmu.edu> (raw)
Set default in `org-babel-default-header-args:emacs-lisp'. Add an
optional argument to the eval function.
---
etc/ORG-NEWS | 11 +++++++++++
lisp/ob-emacs-lisp.el | 33 ++++++++++++++++++++++++---------
2 files changed, 35 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..051d2bb 100644
--- a/lisp/ob-emacs-lisp.el
+++ b/lisp/ob-emacs-lisp.el
@@ -28,8 +28,18 @@
;;; 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 . ((yes no t nil))))
+ "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'.")
(defun org-babel-expand-body:emacs-lisp (body params)
"Expand BODY according to PARAMS, return the expanded body."
@@ -51,13 +61,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))
--
2.4.4
next reply other threads:[~2016-04-18 17:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-18 17:55 John Kitchin [this message]
2016-04-20 8:19 ` [PATCH] Make lexical eval default for elisp src blocks Nicolas Goaziou
2016-04-20 12:34 ` John Kitchin
2016-04-20 21:47 ` Nicolas Goaziou
-- strict thread matches above, loose matches on Subject: below --
2016-04-17 1:05 John Kitchin
2016-04-17 23:47 ` Adam Porter
2016-04-18 15:44 ` John Kitchin
2016-04-18 16:38 ` Nicolas Goaziou
2016-04-18 17:09 ` John Kitchin
2016-04-18 17:41 ` Nicolas Goaziou
2016-04-18 17:56 ` John Kitchin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461002134-49405-1-git-send-email-jkitchin@andrew.cmu.edu \
--to=jkitchin@andrew.cmu.edu \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.