bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#49163: 28.0.50; Dynbind add-function and lambdas as file vars


From: Stefan Monnier
Subject: bug#49163: 28.0.50; Dynbind add-function and lambdas as file vars
Date: Mon, 21 Jun 2021 21:54:19 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]