From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#35351: 27.0.50; Enable derived modes to run their own very-early 'change-major-mode-hook' code Date: Sun, 21 Apr 2019 16:54:55 -0400 Message-ID: References: <85237c18-768d-089b-221a-fe70b0ba4379@orcon.net.nz> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="91537"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Phil Sainty To: 35351@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Apr 21 23:07:27 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIJgM-000NfS-JS for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 23:07:26 +0200 Original-Received: from localhost ([127.0.0.1]:57131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIJgL-0000rj-Dx for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Apr 2019 17:07:25 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:39823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIJg6-0000mg-JU for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 17:07:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hIJVK-0000Ll-4H for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:56:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35635) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hIJVK-0000L1-0Q for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hIJVJ-00073b-Un for bug-gnu-emacs@gnu.org; Sun, 21 Apr 2019 16:56:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Apr 2019 20:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35351 X-GNU-PR-Package: emacs Original-Received: via spool by 35351-submit@debbugs.gnu.org id=B35351.155588010227031 (code B ref 35351); Sun, 21 Apr 2019 20:56:01 +0000 Original-Received: (at 35351) by debbugs.gnu.org; 21 Apr 2019 20:55:02 +0000 Original-Received: from localhost ([127.0.0.1]:49178 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hIJUM-00071u-E9 for submit@debbugs.gnu.org; Sun, 21 Apr 2019 16:55:02 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:42422) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hIJUL-00071S-4m for 35351@debbugs.gnu.org; Sun, 21 Apr 2019 16:55:01 -0400 Original-Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id x3LKsurf004905; Sun, 21 Apr 2019 16:54:57 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 2EB1E66184; Sun, 21 Apr 2019 16:54:55 -0400 (EDT) Cancel-Lock: sha1:bpqvxISS+t8fl/8nB958SaPCFwo= In-Reply-To: <85237c18-768d-089b-221a-fe70b0ba4379@orcon.net.nz> (Phil Sainty's message of "Sun, 21 Apr 2019 14:35:35 +1200") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6529=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6529> : inlines <7058> : streams <1819336> : uri <2835456> 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: 209.51.188.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:157967 Archived-At: > I'm currently using `change-major-mode-hook' for this, but it has > occurred to me that it would be nicer if this hook code of mine > only ever ran in the case where it is useful (i.e. the major mode > being changed to is in fact my mode). There's no need for a "hook" for that. You just need to put the code to save the old values before calling kill-all-local-variables. > (A vaguely analogous facility currently in `define-derived-mode' > is the :after-hook keyword, for running code very *late* in the > proceedings.) Indeed what you're asking for is like a :before-hook symmetric (FWIW, I think the "-hook" part of the name was probably not the best choice). Usually this is done with something akin to: (define-derived-mode my-actual-mode ...) (defun my-mode () (my-save-local-vars) (my-actual-mode)) or something similar (or not using define-derived-mode). Of course, this comes with its own drawbacks. Stefan