unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: 49163@debbugs.gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#49163: 28.0.50; Dynbind add-function and lambdas as file vars
Date: Tue, 22 Jun 2021 01:16:50 +0200	[thread overview]
Message-ID: <87mtrivme5.fsf@web.de> (raw)


Hello,

this is the second time I have stumbled across this and it is annoying -
so here is the story:

The template of the code I was using is like this:

#+begin_src emacs-lisp
;; -*- lexical-binding: t -*-

(defun test ()
  (interactive)
  (funcall (or my-do-with-test-process-fun #'identity)
           (start-process "test-process" "foo" "xterm")))

(defvar my-do-with-test-process-fun nil)
#+end_src

I want to use `my-do-with-test-process-fun' as a file local variable.  I
try like this:

testfile.txt:
| File contents ...
| ...
|
| Local Variables:
| my-do-with-test-process-fun: (lambda (p) (add-function :before (process-sentinel p) (lambda (&rest _) (message "Test"))))
| End:

(I hope mailing stuff doesn't break the overlong line defining
`my-do-with-test-process-fun'.)

When I open that file and try M-x test I get this error:

| Debugger entered--Lisp error: (void-variable #:v)
|   (process-sentinel #:v)
|   (lambda nil (process-sentinel #:v))()
|   advice--add-function(:before ((lambda nil (process-sentinel #:v)) lambda (gv--val) (set-process-sentinel #:v gv--val)) (lambda (&rest _) (message "Test")) nil)
|   (add-function :before (process-sentinel p) (lambda (&rest _) (message "Test")))
|   (lambda (p) (add-function :before (process-sentinel p) (lambda (&rest _) (message "Test"))))(#<process test-process>)
|   funcall((lambda (p) (add-function :before (process-sentinel p) (lambda (&rest _) (message "Test")))) #<process test-process>)
|   test()


(1) I suspect that this happens because the lack of lexical binding
"somewhere".  Enabling lexical binding mode in `testfile.txt' alone
doesn't help.  OTOH, setting the file local variable like this:

| Local Variables:
| eval: (setq-local my-do-with-test-process-fun (eval (lambda (p) (add-function ...) t)))
| End:

makes `M-x test` work.  Is this all expected so far?


(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?


(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?


TIA,

Michael.



In GNU Emacs 28.0.50 (build 15, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
 of 2021-06-21 built on drachen
Repository revision: 50a59b9af1517f24fca60feab37140f2b35ea5ac
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12010000
System Description: Debian GNU/Linux bullseye/sid

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP
SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LC_ALL: de_DE.utf8
  value of $LC_COLLATE: C
  value of $LC_TIME: C
  value of $LANG: de_DE.utf8
  locale-coding-system: utf-8-unix






             reply	other threads:[~2021-06-21 23:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 23:16 Michael Heerdegen [this message]
2021-06-22  1:54 ` bug#49163: 28.0.50; Dynbind add-function and lambdas as file vars Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-06-22  2:26   ` Michael Heerdegen
2021-06-27 22:18     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-06-28  2:56       ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mtrivme5.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=49163@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).