From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: 35351@debbugs.gnu.org
Cc: Phil Sainty <psainty@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 [thread overview]
Message-ID: <jwv4l6rrsw8.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <85237c18-768d-089b-221a-fe70b0ba4379@orcon.net.nz> (Phil Sainty's message of "Sun, 21 Apr 2019 14:35:35 +1200")
> 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
next prev parent reply other threads:[~2019-04-21 20:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-21 2:35 bug#35351: 27.0.50; Enable derived modes to run their own very-early 'change-major-mode-hook' code Phil Sainty
2019-04-21 2:45 ` Phil Sainty
2019-04-21 6:01 ` Richard Stallman
2019-04-21 6:23 ` Eli Zaretskii
2019-04-21 20:54 ` Stefan Monnier [this message]
2019-04-22 8:16 ` bug#35351: 27.0.50; " Phil Sainty
2019-04-22 14:39 ` Stefan Monnier
2019-04-22 23:18 ` Phil Sainty
2019-04-22 23:31 ` Phil Sainty
2019-04-23 2:08 ` Stefan Monnier
2019-04-23 3:52 ` Phil Sainty
2019-04-23 11:59 ` Stefan Monnier
2019-04-22 14:41 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv4l6rrsw8.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=35351@debbugs.gnu.org \
--cc=psainty@orcon.net.nz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.