GNU bug report logs - #35351
27.0.50; Enable derived modes to run their own very-early 'change-major-mode-hook' code

Previous Next

Package: emacs;

Reported by: Phil Sainty <psainty <at> orcon.net.nz>

Date: Sun, 21 Apr 2019 02:41:01 UTC

Severity: wishlist

Found in version 27.0.50

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: 35351 <at> debbugs.gnu.org
Cc: Phil Sainty <psainty <at> orcon.net.nz>
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
> 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




This bug report was last modified 6 years and 53 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.