From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Enable derived modes to run their own very-early 'change-major-mode-hook' code Date: Sun, 21 Apr 2019 09:23:18 +0300 Message-ID: <83ftqbanc9.fsf@gnu.org> References: <85237c18-768d-089b-221a-fe70b0ba4379@orcon.net.nz> Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="76166"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: Phil Sainty Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 21 08:37:24 2019 Return-path: Envelope-to: ged-emacs-devel@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 1hI66O-000Jgy-A9 for ged-emacs-devel@m.gmane.org; Sun, 21 Apr 2019 08:37:24 +0200 Original-Received: from localhost ([127.0.0.1]:49599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hI66N-0006q7-A2 for ged-emacs-devel@m.gmane.org; Sun, 21 Apr 2019 02:37:23 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:55733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hI66F-0006or-LR for emacs-devel@gnu.org; Sun, 21 Apr 2019 02:37:17 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:45879) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hI5sw-0003t3-Ne; Sun, 21 Apr 2019 02:23:30 -0400 Original-Received: from [176.228.60.248] (port=3026 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hI5sv-0003mY-W8; Sun, 21 Apr 2019 02:23:30 -0400 In-reply-to: <85237c18-768d-089b-221a-fe70b0ba4379@orcon.net.nz> (message from Phil Sainty on Sun, 21 Apr 2019 14:35:35 +1200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:235728 Archived-At: [I'm moving this to emacs-devel, as the bug tracker doesn't sound appropriate for such discussions. Please send any followups here.] > From: Phil Sainty > Date: Sun, 21 Apr 2019 14:35:35 +1200 > > The library I'm working on (so-long.el) defines a major mode > which needs to remember various buffer-local values as they were > in the original mode, *before* my major mode takes effect. > > 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). `change-major-mode-hook' > has no knowledge of the mode which has just been invoked, so it > must necessarily run for *every* mode change -- which isn't > relevant to my library in the vast majority of cases. > > I think `change-major-mode-hook' would more commonly be used by > modes to handle any subsequent 'unloading' needs of that same > mode in case it gets replaced later on (i.e. the mode body could > set a buffer-local hook value), so my scenario of the new mode > wanting to know things about the previous mode is doubtless a bit > of a niche case; but I thought I'd raise it for discussion. Did you consider using major-mode-suspend and major-mode-restore?