From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#29679: 26.0.90; :after-hook not compiled Date: Tue, 12 Dec 2017 15:07:24 -0500 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1513109290 31150 195.159.176.226 (12 Dec 2017 20:08:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 12 Dec 2017 20:08:10 +0000 (UTC) Cc: Alan Mackenzie To: 29679@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Dec 12 21:08:07 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOqqU-0007sf-Fk for geb-bug-gnu-emacs@m.gmane.org; Tue, 12 Dec 2017 21:08:06 +0100 Original-Received: from localhost ([::1]:60303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOqqb-00012Q-Qb for geb-bug-gnu-emacs@m.gmane.org; Tue, 12 Dec 2017 15:08:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOqqU-0000uJ-Hy for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2017 15:08:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOqqQ-0007JW-Og for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2017 15:08:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50256) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eOqqQ-0007J5-HD for bug-gnu-emacs@gnu.org; Tue, 12 Dec 2017 15:08:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eOqqP-0001TF-PY; Tue, 12 Dec 2017 15:08:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: acm@muc.de, bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Dec 2017 20:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 29679 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Alan Mackenzie Original-Received: via spool by submit@debbugs.gnu.org id=B.15131092595616 (code B ref -1); Tue, 12 Dec 2017 20:08:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Dec 2017 20:07:39 +0000 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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: A2GeBgDbNTBa/zyu+M5dHgEGDIM+RoEUg16LYI4RAYIwAYJWlhsdhSIEhQtEFAEBAQEBAQEBAQNoKIYBXxMhARwNil+rJ4sRg2OFSosgDIMUBYdsizmPcotsg2qRUYdmllSBSzYjgU4yGggwOoIqggEBgnAjiwQBAQE X-IPAS-Result: A2GeBgDbNTBa/zyu+M5dHgEGDIM+RoEUg16LYI4RAYIwAYJWlhsdhSIEhQtEFAEBAQEBAQEBAQNoKIYBXxMhARwNil+rJ4sRg2OFSosgDIMUBYdsizmPcotsg2qRUYdmllSBSzYjgU4yGggwOoIqggEBgnAjiwQBAQE X-IronPort-AV: E=Sophos;i="5.45,395,1508817600"; d="scan'208";a="13588810" Original-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 Original-Received: by pastel.home (Postfix, from userid 20848) id CB528603A7; Tue, 12 Dec 2017 15:07:24 -0500 (EST) 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:141002 Archived-At: 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'.