From unknown Sun Jun 22 22:42:39 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#29679 <29679@debbugs.gnu.org> To: bug#29679 <29679@debbugs.gnu.org> Subject: Status: 26.0.90; :after-hook not compiled Reply-To: bug#29679 <29679@debbugs.gnu.org> Date: Mon, 23 Jun 2025 05:42:39 +0000 retitle 29679 26.0.90; :after-hook not compiled reassign 29679 emacs submitter 29679 Stefan Monnier severity 29679 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Dec 12 15:07:39 2017 Received: (at submit) by debbugs.gnu.org; 12 Dec 2017 20:07:39 +0000 Received: from localhost ([127.0.0.1]:58937 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOqq3-0001SW-Cr for submit@debbugs.gnu.org; Tue, 12 Dec 2017 15:07:39 -0500 Received: from eggs.gnu.org ([208.118.235.92]:46201) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOqq1-0001SJ-2n for submit@debbugs.gnu.org; Tue, 12 Dec 2017 15:07:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOqpv-0006mh-6P for submit@debbugs.gnu.org; Tue, 12 Dec 2017 15:07:32 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:51514) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eOqpv-0006mb-2h for submit@debbugs.gnu.org; Tue, 12 Dec 2017 15:07:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOqpt-000088-Oh for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2017 15:07:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOqpq-0006iK-HP for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2017 15:07:29 -0500 Received: from pmta21.teksavvy.com ([76.10.157.36]:22931) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eOqpq-0006hV-CV for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2017 15:07:26 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2GeBgDbNTBa/zyu+M5dHgEGDIM+RoEUg?= =?us-ascii?q?16LYI4RAYIwAYJWlhsdhSIEhQtEFAEBAQEBAQEBAQNoKIYBXxMhARwNil+rJ4s?= =?us-ascii?q?Rg2OFSosgDIMUBYdsizmPcotsg2qRUYdmllSBSzYjgU4yGggwOoIqggEBgnAji?= =?us-ascii?q?wQBAQE?= X-IPAS-Result: =?us-ascii?q?A2GeBgDbNTBa/zyu+M5dHgEGDIM+RoEUg16LYI4RAYIwAYJ?= =?us-ascii?q?WlhsdhSIEhQtEFAEBAQEBAQEBAQNoKIYBXxMhARwNil+rJ4sRg2OFSosgDIMUB?= =?us-ascii?q?YdsizmPcotsg2qRUYdmllSBSzYjgU4yGggwOoIqggEBgnAjiwQBAQE?= X-IronPort-AV: E=Sophos;i="5.45,395,1508817600"; d="scan'208";a="13588810" Received: from 206-248-174-60.dsl.teksavvy.com (HELO pastel.home) ([206.248.174.60]) by smtp.teksavvy.com with ESMTP; 12 Dec 2017 15:07:24 -0500 Received: by pastel.home (Postfix, from userid 20848) id CB528603A7; Tue, 12 Dec 2017 15:07:24 -0500 (EST) From: Stefan Monnier To: bug-gnu-emacs@gnu.org Subject: 26.0.90; :after-hook not compiled X-Debbugs-Cc: Alan Mackenzie Date: Tue, 12 Dec 2017 15:07:24 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) 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'. From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 15 05:34:30 2017 Received: (at 29679) by debbugs.gnu.org; 15 Dec 2017 10:34:30 +0000 Received: from localhost ([127.0.0.1]:34698 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePnK1-0004ZC-TM for submit@debbugs.gnu.org; Fri, 15 Dec 2017 05:34:30 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47748) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePnK0-0004Z0-Po for 29679@debbugs.gnu.org; Fri, 15 Dec 2017 05:34:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePnJu-00068H-Ed for 29679@debbugs.gnu.org; Fri, 15 Dec 2017 05:34:23 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_20,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54628) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePnJk-00062m-Ga; Fri, 15 Dec 2017 05:34:12 -0500 Received: from [176.228.60.248] (port=4609 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ePnJj-00008s-Vg; Fri, 15 Dec 2017 05:34:12 -0500 Date: Fri, 15 Dec 2017 12:34:11 +0200 Message-Id: <837etoth3w.fsf@gnu.org> From: Eli Zaretskii To: Stefan Monnier In-reply-to: (message from Stefan Monnier on Tue, 12 Dec 2017 15:07:24 -0500) Subject: Re: bug#29679: 26.0.90; :after-hook not compiled References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 29679 Cc: acm@muc.de, 29679@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Eli Zaretskii Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) > From: Stefan Monnier > Date: Tue, 12 Dec 2017 15:07:24 -0500 > Cc: Alan Mackenzie > > 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? From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 18 11:37:43 2017 Received: (at 29679-done) by debbugs.gnu.org; 18 Dec 2017 16:37:43 +0000 Received: from localhost ([127.0.0.1]:40766 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eQyQA-0003lz-N1 for submit@debbugs.gnu.org; Mon, 18 Dec 2017 11:37:42 -0500 Received: from chene.dit.umontreal.ca ([132.204.246.20]:54333) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eQyQ8-0003lq-Fq for 29679-done@debbugs.gnu.org; Mon, 18 Dec 2017 11:37:41 -0500 Received: from lechazo.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id vBIGbbHa017663; Mon, 18 Dec 2017 11:37:38 -0500 Received: by lechazo.home (Postfix, from userid 20848) id 827FF603CA; Mon, 18 Dec 2017 11:40:21 -0500 (EST) From: Stefan Monnier To: Eli Zaretskii Subject: Re: bug#29679: 26.0.90; :after-hook not compiled Message-ID: References: <837etoth3w.fsf@gnu.org> Date: Mon, 18 Dec 2017 11:40:21 -0500 In-Reply-To: <837etoth3w.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 15 Dec 2017 12:34:11 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-NAI-Spam-Flag: NO X-NAI-Spam-Level: X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0.1 X-NAI-Spam-Rules: 3 Rules triggered GEN_SPAM_FEATRE=0.1, EDT_SA_DN_PASS=0, RV6182=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6182> : inlines <6257> : streams <1773487> : uri <2553335> X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: 29679-done Cc: acm@muc.de, 29679-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) Version: 26.1 Installed, with corresponding test into emacs-26. Stefan From unknown Sun Jun 22 22:42:39 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 16 Jan 2018 12:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator