[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode
From: |
Lars Ingebrigtsen |
Subject: |
bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode |
Date: |
Sat, 04 Dec 2021 04:37:13 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
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 in Thread] |
Current Thread |
[Next in Thread] |
- bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode,
Lars Ingebrigtsen <=