[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode
From: |
Stefan Monnier |
Subject: |
bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode |
Date: |
Fri, 08 Nov 2013 15:29:20 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
> 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.
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))
-- Stefan
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode,
Stefan Monnier <=