GNU bug report logs - #49163
28.0.50; Dynbind add-function and lambdas as file vars

Previous Next

Package: emacs;

Reported by: Michael Heerdegen <michael_heerdegen <at> web.de>

Date: Mon, 21 Jun 2021 23:18:02 UTC

Severity: normal

Found in version 28.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: bug-gnu-emacs <at> gnu.org
Subject: Re: 28.0.50; Dynbind add-function and lambdas as file vars
Date: Mon, 21 Jun 2021 21:54:19 -0400
> | my-do-with-test-process-fun: (lambda (p) (add-function :before
> | (process-sentinel p) (lambda (&rest _) (message "Test"))))

Remember, file-local vars set a var to a value, there's no evaluation
going on, so this sets `my-do-with-test-process-fun` to a list whose car
is the symbol `lambda`.

> (2) If lack of lexical binding is the culprit: I see that `add-function'
> uses `gv-ref' and that warns about uses in dynamically binding Elisp.
> Should `add-function' warn about such a restriction as well?

It might (when you do the `M-x test`); have you checked *Messages*?

> (3) And I wonder: now that lexical binding Elisp gets more common,
> should file local variables be set using a lexically binding environment
> -- or at least when the file itself specifies lexical binding mode?

I think the patch below would be in order, yes, but it won't help
your example unless you change it to something like:

    eval: (setq-local my-do-with-test-process-fun: (lambda (p) (add-function :before (process-sentinel p) (lambda (&rest _) (message "Test")))))


        Stefan


diff --git a/lisp/files.el b/lisp/files.el
index 5d2fe0a77b..04db0faffd 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -4041,7 +4041,7 @@ hack-one-local-variable
     ('eval
      (pcase val
        (`(add-hook ',hook . ,_) (hack-one-local-variable--obsolete hook)))
-     (save-excursion (eval val)))
+     (save-excursion (eval val t)))
     (_
      (hack-one-local-variable--obsolete var)
      ;; Make sure the string has no text properties.





This bug report was last modified 4 years and 48 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.