From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Miele Subject: [PATCH 1/2] ob-emacs-lisp: Set `lexical-binding' in edit buffers Date: Thu, 14 Mar 2019 10:24:33 +0000 Message-ID: <87tvg5g3dq.fsf@gmail.com> Reply-To: sebastian.miele@gmail.com Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([209.51.188.92]:47189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4Njw-00010G-VG for emacs-orgmode@gnu.org; Thu, 14 Mar 2019 06:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4NXR-0002L7-Lg for emacs-orgmode@gnu.org; Thu, 14 Mar 2019 06:24:38 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:44025) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4NXR-0002KP-63 for emacs-orgmode@gnu.org; Thu, 14 Mar 2019 06:24:37 -0400 Received: by mail-wr1-x444.google.com with SMTP id d17so5189702wre.10 for ; Thu, 14 Mar 2019 03:24:36 -0700 (PDT) Received: from tisch ([2a02:908:1794:9440:7e75:7051:75d8:5a6f]) by smtp.gmail.com with ESMTPSA id d5sm7274631wrx.12.2019.03.14.03.24.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 03:24:34 -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 * lisp/ob-emacs-lisp.el (org-babel-execute:emacs-lisp, org-babel-emacs-lisp-lexical): Factor out the conversion of the :lexical source block argument to a form that is appropriate for `lexical-binding' and the LEXICAL argument to `eval'. * lisp/ob-emacs-lisp.el (org-babel-edit-prep:emacs-lisp): Set `lexical-binding'. * lisp/ob-emacs-lisp.el (org-babel-default-header-args:emacs-lisp): Update docstring. * etc/ORG-NEWS: Create entry about this under Miscellaneous. --- etc/ORG-NEWS | 6 ++++++ lisp/ob-emacs-lisp.el | 24 ++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 039ad4c69..15af28bfd 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -160,6 +160,8 @@ dynamic block in ~org-dynamic-block-alist~. *** ~org-table-cell-down~ *** ~org-table-cell-left~ *** ~org-table-cell-right~ +*** ~org-babel-emacs-lisp-lexical~ +*** ~org-babel-edit-prep:emacs-lisp~ ** Removed functions *** ~org-babel-set-current-result-hash~ @@ -193,6 +195,10 @@ The ~:mkdirp~ header argument used to only work for ~:tangle~ tangle files. Now ~:mkdirp~ works for ~:dir~ too. This is more convenient for specify default directory and with ~:file~ header argument. +*** ob-emacs-lisp sets ~lexical-binding~ in Org edit buffers +When editing an Elisp src block, the editing buffer's +~lexical-binding~ is set according to the src block's =:lexical= +parameter. * Version 9.2 ** Incompatible changes *** Removal of OrgStruct mode mode and radio lists diff --git a/lisp/ob-emacs-lisp.el b/lisp/ob-emacs-lisp.el index cd86f4a20..ab7dac879 100644 --- a/lisp/ob-emacs-lisp.el +++ b/lisp/ob-emacs-lisp.el @@ -43,7 +43,8 @@ A value of \"yes\" or t causes source 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.") +`eval', which see. And it is used as the value for +`lexical-binding' in buffers created by `org-edit-src-code'.") (defun org-babel-expand-body:emacs-lisp (body params) "Expand BODY according to PARAMS, return the expanded body." @@ -71,9 +72,7 @@ their value. It is used as the optional LEXICAL argument to (member "pp" result-params)) (concat "(pp " body ")") body)) - (if (listp lexical) - lexical - (member lexical '("yes" "t")))))) + (org-babel-emacs-lisp-lexical lexical)))) (org-babel-result-cond result-params (let ((print-level nil) (print-length nil)) @@ -88,6 +87,23 @@ their value. It is used as the optional LEXICAL argument to (org-babel-pick-name (cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))))) +(defun org-babel-emacs-lisp-lexical (lexical) + "Interpret :lexical source block argument. +Convert LEXICAL into the form appropriate for `lexical-binding' +and the LEXICAL argument to `eval'." + (if (listp lexical) + lexical + (not (null (member lexical '("yes" "t")))))) + +(defun org-babel-edit-prep:emacs-lisp (info) + "Set `lexical-binding' in Org edit buffer. +Set `lexical-binding' in Org edit buffer according to the +corresponding :lexical source block argument." + (setq lexical-binding + (org-babel-emacs-lisp-lexical + (org-babel-read + (cdr (assq :lexical (nth 2 info))))))) + (org-babel-make-language-alias "elisp" "emacs-lisp") (provide 'ob-emacs-lisp) -- 2.21.0