GNU bug report logs -
#29679
26.0.90; :after-hook not compiled
Previous Next
Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>
Date: Tue, 12 Dec 2017 20:08:01 UTC
Severity: normal
Found in version 26.0.90
Fixed in version 26.1
Done: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 29679 in the body.
You can then email your comments to 29679 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
acm <at> muc.de, bug-gnu-emacs <at> gnu.org
:
bug#29679
; Package
emacs
.
(Tue, 12 Dec 2017 20:08:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
New bug report received and forwarded. Copy sent to
acm <at> muc.de, bug-gnu-emacs <at> gnu.org
.
(Tue, 12 Dec 2017 20:08:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Package: Emacs
Version: 26.0.90
I just realized that the :after-hook option of define-derived-mode (new
in Emacs-26) is expanded in a way that introduces some problems.
More specifically a
:after-hook (foo bar)
gets turned into something like
(push '(foo bar) 'delayed-after-hook-forms)
which means that the code (foo bar) is not byte-compiled, hence is not
macro-expanded, and will be evaluated later via `eval` without paying
attention to the setting of `lexical-binding`.
It's not a very serious problem in practice, but if we keep the code as
we have it, it means that code byte-compiled with Emacs-26 will use the
above
(push '(foo bar) 'delayed-after-hook-forms)
in its .elc and we'll have to preserve backward compatibility with it.
So it'd be better to fix it before Emacs-26 is released.
Here's a minimal patch for it, which I hope is safe enough for emacs-26.
OK to push to emacs-26?
Stefan
diff --git a/lisp/emacs-lisp/derived.el b/lisp/emacs-lisp/derived.el
index 751291afa8..c0ef199424 100644
--- a/lisp/emacs-lisp/derived.el
+++ b/lisp/emacs-lisp/derived.el
@@ -285,7 +285,7 @@ define-derived-mode
(run-mode-hooks ',hook)
,@(when after-hook
`((if delay-mode-hooks
- (push ',after-hook delayed-after-hook-forms)
+ (push (lambda () ,after-hook) delayed-after-hook-functions)
,after-hook)))))))
;; PUBLIC: find the ultimate class of a derived mode.
diff --git a/lisp/subr.el b/lisp/subr.el
index 6db3b614d6..64521711b7 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1844,10 +1844,10 @@ delayed-mode-hooks
(make-variable-buffer-local 'delayed-mode-hooks)
(put 'delay-mode-hooks 'permanent-local t)
-(defvar delayed-after-hook-forms nil
+(defvar delayed-after-hook-functions nil
"List of delayed :after-hook forms waiting to be run.
These forms come from `define-derived-mode'.")
-(make-variable-buffer-local 'delayed-after-hook-forms)
+(make-variable-buffer-local 'delayed-after-hook-functions)
(defvar change-major-mode-after-body-hook nil
"Normal hook run in major mode functions, before the mode hooks.")
@@ -1865,7 +1865,7 @@ run-mode-hooks
Otherwise, runs hooks in the sequence: `change-major-mode-after-body-hook',
`delayed-mode-hooks' (in reverse order), HOOKS, then runs
`hack-local-variables', runs the hook `after-change-major-mode-hook', and
-finally evaluates the forms in `delayed-after-hook-forms' (see
+finally evaluates the functions in `delayed-after-hook-functions' (see
`define-derived-mode').
Major mode functions should use this instead of `run-hooks' when
@@ -1882,9 +1882,9 @@ run-mode-hooks
(with-demoted-errors "File local-variables error: %s"
(hack-local-variables 'no-mode)))
(run-hooks 'after-change-major-mode-hook)
- (dolist (form (nreverse delayed-after-hook-forms))
- (eval form))
- (setq delayed-after-hook-forms nil)))
+ (dolist (fun (nreverse delayed-after-hook-functions))
+ (funcall fun))
+ (setq delayed-after-hook-functions nil)))
(defmacro delay-mode-hooks (&rest body)
"Execute BODY, but delay any `run-mode-hooks'.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#29679
; Package
emacs
.
(Fri, 15 Dec 2017 10:35:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 29679 <at> debbugs.gnu.org (full text, mbox):
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Date: Tue, 12 Dec 2017 15:07:24 -0500
> Cc: Alan Mackenzie <acm <at> muc.de>
>
> I just realized that the :after-hook option of define-derived-mode (new
> in Emacs-26) is expanded in a way that introduces some problems.
> More specifically a
>
> :after-hook (foo bar)
>
> gets turned into something like
>
> (push '(foo bar) 'delayed-after-hook-forms)
>
> which means that the code (foo bar) is not byte-compiled, hence is not
> macro-expanded, and will be evaluated later via `eval` without paying
> attention to the setting of `lexical-binding`.
>
> It's not a very serious problem in practice, but if we keep the code as
> we have it, it means that code byte-compiled with Emacs-26 will use the
> above
>
> (push '(foo bar) 'delayed-after-hook-forms)
>
> in its .elc and we'll have to preserve backward compatibility with it.
> So it'd be better to fix it before Emacs-26 is released.
> Here's a minimal patch for it, which I hope is safe enough for emacs-26.
>
> OK to push to emacs-26?
LGTM, thanks. Alan, do you agree?
Reply sent
to
Stefan Monnier <monnier <at> IRO.UMontreal.CA>
:
You have taken responsibility.
(Mon, 18 Dec 2017 16:38:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
bug acknowledged by developer.
(Mon, 18 Dec 2017 16:38:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 29679-done <at> debbugs.gnu.org (full text, mbox):
Version: 26.1
Installed, with corresponding test into emacs-26.
Stefan
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 16 Jan 2018 12:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 7 years and 159 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.