From: Lars Ingebrigtsen <larsi@gnus.org>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: yary <not.com@gmail.com>, 15659@debbugs.gnu.org
Subject: bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode
Date: Sat, 04 Dec 2021 04:37:13 +0100 [thread overview]
Message-ID: <87y251qbva.fsf@gnus.org> (raw)
In-Reply-To: <jwv7gcibq83.fsf-monnier+emacsbugs@gnu.org> (Stefan Monnier's message of "Fri, 08 Nov 2013 15:29:20 -0500")
Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
>> A function could take a minor-mode to preserve, and then either set up
>> hooks needed to re-enable it after a major-mode change, or prevent
>> `kill-all-local-variables' from disabling it in the first place. Or
>> perhaps marking the minor-mode's function-symbol itself as
>> `permanent-local' could protect it, along with all its buffer-locals.
(I'm going through old bug reports that unfortunately weren't resolved
at the time.)
> We could start with something like the following (guaranteed 100% untested):
>
> (put 'after-change-major-mode-hook 'permanent-local-hook t)
>
> (defvar permanent-local--modes nil)
>
> (defun permanent-local--reenable ()
> (mapc #'funcall permanent-local--modes))
> (put 'permanent-local--reenable 'permanent-local-hook t)
>
> (defun permanent-local-mode (mode)
> "Enable MODE permanently in this buffer."
> (interactive
> (list
> (intern
> (completing-read "Minor mode: "
> obarray
> (lambda (sym)
> (or (memq mode minor-mode-list)
> (string-match "-mode\\'" (symbol-name sym))))
> t))))
> (funcall mode) ;Enable.
> (add-hook 'after-change-major-mode-hook #'permanent-local--reenable nil t))
I think this could work... but I don't really see it being used a lot.
Changing a major mode is a relatively rare thing to do, and I don't see
people using `permanent-local-mode' first -- because it'd be more work
than just re-enabling the minor modes.
And if you are in the habit of changing modes a lot (for instance,
between two modes like cperl-mode and perl-mode), then I think you'd be
more likely to want to put the minor modes into the major mode hooks.
So, while it would be possible to add something like this, I just don't
see the use case, so I don't think we should add this, and I'm closing
this bug report.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
prev parent reply other threads:[~2021-12-04 3:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-20 0:22 bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode yary
2013-10-20 1:33 ` Stefan Monnier
2013-10-20 13:26 ` yary
2013-11-08 20:29 ` Stefan Monnier
2021-12-04 3:37 ` Lars Ingebrigtsen [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y251qbva.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=15659@debbugs.gnu.org \
--cc=monnier@IRO.UMontreal.CA \
--cc=not.com@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).