From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: [PATCH] Make lexical eval default for elisp src blocks Date: Mon, 18 Apr 2016 13:55:34 -0400 Message-ID: <1461002134-49405-1-git-send-email-jkitchin@andrew.cmu.edu> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asDOn-00032N-8j for emacs-orgmode@gnu.org; Mon, 18 Apr 2016 13:55:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asDOj-0007mw-Ah for emacs-orgmode@gnu.org; Mon, 18 Apr 2016 13:55:49 -0400 Received: from mail-qg0-x22e.google.com ([2607:f8b0:400d:c04::22e]:34229) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asDOj-0007ms-6P for emacs-orgmode@gnu.org; Mon, 18 Apr 2016 13:55:45 -0400 Received: by mail-qg0-x22e.google.com with SMTP id c6so121500394qga.1 for ; Mon, 18 Apr 2016 10:55:45 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Cc: John Kitchin 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