emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-emacs-lisp: Set `lexical-binding' in source editing buffers
@ 2019-02-10 12:57 Sebastian Miele
  2019-02-12  8:41 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Miele @ 2019-02-10 12:57 UTC (permalink / raw)
  To: emacs-orgmode

* 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.

TINYCHANGE
---
 lisp/ob-emacs-lisp.el | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/lisp/ob-emacs-lisp.el b/lisp/ob-emacs-lisp.el
index cd86f4a20..17952069e 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,22 @@ 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)
+  "Convert :lexical source block argument 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' according to :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.20.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ob-emacs-lisp: Set `lexical-binding' in source editing buffers
  2019-02-10 12:57 [PATCH] ob-emacs-lisp: Set `lexical-binding' in source editing buffers Sebastian Miele
@ 2019-02-12  8:41 ` Nicolas Goaziou
  2019-02-23  7:11   ` Sebastian Miele
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2019-02-12  8:41 UTC (permalink / raw)
  To: Sebastian Miele; +Cc: emacs-orgmode

Hello,

Sebastian Miele <sebastian.miele@gmail.com> writes:

> * 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.

Thank you! Some comments follow.

> -`eval', which see.")
> +`eval', which see. And it is used as the value for
> +`lexical-binding' in buffers created by `org-edit-src-code'.")

You need to add two spaces after full stops.

> +(defun org-babel-emacs-lisp-lexical (lexical)
> +  "Convert :lexical source block argument LEXICAL into the form
> +appropriate for `lexical-binding' and the LEXICAL argument to
> +`eval'."

The first sentence in a docstring needs to fit on a single line.

Could you add a test or two for that feature? Could you also add an
ORG-NEWS entry?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ob-emacs-lisp: Set `lexical-binding' in source editing buffers
  2019-02-12  8:41 ` Nicolas Goaziou
@ 2019-02-23  7:11   ` Sebastian Miele
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Miele @ 2019-02-23  7:11 UTC (permalink / raw)
  To: mail; +Cc: emacs-orgmode

On Tue, Feb 12, 2019 at 9:41 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>
> [...]
>
> Thank you! Some comments follow.
>
> > -`eval', which see.")
> > +`eval', which see. And it is used as the value for
> > +`lexical-binding' in buffers created by `org-edit-src-code'.")
>
> You need to add two spaces after full stops.
>
> > +(defun org-babel-emacs-lisp-lexical (lexical)
> > +  "Convert :lexical source block argument LEXICAL into the form
> > +appropriate for `lexical-binding' and the LEXICAL argument to
> > +`eval'."
>
> The first sentence in a docstring needs to fit on a single line.
>
> Could you add a test or two for that feature? Could you also add an
> ORG-NEWS entry?

I did all the changes you suggested. I will send the new patch after I
managed to setup and get acquainted with mail in Emacs (mu4e).

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-23  7:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-10 12:57 [PATCH] ob-emacs-lisp: Set `lexical-binding' in source editing buffers Sebastian Miele
2019-02-12  8:41 ` Nicolas Goaziou
2019-02-23  7:11   ` Sebastian Miele

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).