unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: yary <not.com@gmail.com>
Cc: 15659@debbugs.gnu.org
Subject: bug#15659: 24.1; (wishlist) Simple method for preserving minor-mode
Date: Fri, 08 Nov 2013 15:29:20 -0500	[thread overview]
Message-ID: <jwv7gcibq83.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <CAG2CFAavwPpLqwG2Yt-itZs5AzUN_5o-f+3084zxEaHA3_6EZA@mail.gmail.com> (yary's message of "Sat, 19 Oct 2013 20:22:33 -0400")

> 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





  parent reply	other threads:[~2013-11-08 20:29 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 [this message]
2021-12-04  3:37   ` Lars Ingebrigtsen

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=jwv7gcibq83.fsf-monnier+emacsbugs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=15659@debbugs.gnu.org \
    --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).