GNU bug report logs - #15659
24.1; (wishlist) Simple method for preserving minor-mode

Previous Next

Package: emacs;

Reported by: yary <not.com <at> gmail.com>

Date: Sun, 20 Oct 2013 00:24:02 UTC

Severity: wishlist

Tags: wontfix

Found in version 24.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15659 in the body.
You can then email your comments to 15659 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#15659; Package emacs. (Sun, 20 Oct 2013 00:24:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to yary <not.com <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 20 Oct 2013 00:24:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: yary <not.com <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.1; (wishlist) Simple method for preserving minor-mode
Date: Sat, 19 Oct 2013 20:22:33 -0400
There are times when I wish to set a minor-mode permanently for a
buffer, even through major-mode changes. They are display-related
minor-modes, such as buffer-face-mode or text-scale-mode.

Ideally I'd like a simple way to preserve a minor-mode between
major-mode changes. I started discussing this in Bug #15577, which is
about dir-locals, but am moving it here as this is a separate issue.

Also bug #15396 "permanent-local truncate-lines" is related, Stefan sets
a display-related local variable and would like it preserved across mode
changes (or in this case, revert-buffer). Yet setting `permanent-local'
on the `truncate-lines' variable does not protect it:
`toggle-truncate-lines' behaves like a minor mode.

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 have a personal workaround which works for modes I use posted at
http://stackoverflow.com/a/19439236/379333 - though it isn't fully
generalized and has other flaws. It checks if specified minor-modes
are active during `change-major-mode-hook', and if so, then tries to
figure out which variables they use, and then restores those variables
and minor modes in the `after-change-major-mode-hook'

Answering a question from bug #15577 about this issue:

>> a. Get all of that mode's customizable buffer-locals.
>
>Not sure what that is.

The modes I wanted to preserve have buffer-locals for the face, and
for the size adjustment. It's not enough to just re-enable the modes,
we have to know which buffer-locals the mode reads.

>> Ideally the minor-mode, or emacs core, would provide a function for
>> that purpose.
>
>It's probably not possible (not reliably at least) with the way minor
>modes are defined currently.  Tho depending on what you mean it might be
>a non-issue.

What I meant was, since any proposed minor-mode-preserving mechanism
needs to know what buffer-local variables also would need to be set
`permanent-local', then "Ideally the minor-mode, or emacs core, would
provide a function" listing those variables. So for example, the
`define-minor-mode' macro might get a `:local-variables' keyword
allowing the author to declare that mode's buffer-locals, along with
their documentation and defaults. Would not be required in general,
but would make it easier for anything that wants to manipulate minor
modes.

>> b. Mark those variables as permanent-local
>
>There's no such thing, currently (we instead have to use a hack with
>change-major-mode-hook, along the lines of what you did).

Must be a mis-communication here. The docs to `kill-all-local-variables' say:

  As a special exception, local variables whose names have
  a non-nil `permanent-local' property are not eliminated by this function.

I just tried (put 'foo 'permanent-local 't) and `foo' survived
`kill-all-local-variables' and several mode changes. So we do have the
`permanent-local' property for keeping local variables around.

>But there are some issues:
>- we have to find out which buffer-local minor-modes are enabled, which
>  presumes we have some kind of list of minor-modes.  We can probably
>  use minor-mode-list for that, tho.

Searching minor-mode-list would work, as would checking that the
symbol "name-of-minor-mide' is buffer-local and has a non-nil value.

>- some minor modes are mode-specific; e.g. it doesn't make much sense to
>  preserve reftex-mode when switching from latex-mode to haskell-mode.

This sounds like another mis-communication- proposal is to let a user
(or by extension a minor-mode-author) to easily mark a minor-mode as
"to-be-preserved." As another example, I do not want flymake still on
when switching into css-mode. It's not up to this method to decide
which minor-modes to preserve; it is up to the user.

-y




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15659; Package emacs. (Sun, 20 Oct 2013 01:34:01 GMT) Full text and rfc822 format available.

Message #8 received at 15659 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: yary <not.com <at> gmail.com>
Cc: 15659 <at> debbugs.gnu.org
Subject: Re: bug#15659: 24.1;
 (wishlist) Simple method for preserving minor-mode
Date: Sat, 19 Oct 2013 21:33:14 -0400
> There are times when I wish to set a minor-mode permanently for a
> buffer, even through major-mode changes. They are display-related
> minor-modes, such as buffer-face-mode or text-scale-mode.

Indeed, those two should probably be make "permanent local".


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15659; Package emacs. (Sun, 20 Oct 2013 13:28:02 GMT) Full text and rfc822 format available.

Message #11 received at 15659 <at> debbugs.gnu.org (full text, mbox):

From: yary <not.com <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 15659 <at> debbugs.gnu.org
Subject: Re: bug#15659: 24.1;
 (wishlist) Simple method for preserving minor-mode
Date: Sun, 20 Oct 2013 09:26:44 -0400
On Sat, Oct 19, 2013 at 9:33 PM, Stefan Monnier
<monnier <at> iro.umontreal.ca> wrote:
>> There are times when I wish to set a minor-mode permanently for a
>> buffer, even through major-mode changes. They are display-related
>> minor-modes, such as buffer-face-mode or text-scale-mode.
>
> Indeed, those two should probably be make "permanent local".

That's a better solution than prompting people to make permanent those
minor-modes themselves, via some new generic method for preserving any
minor mode.

I can still see a reason to have something like a `:local-variables'
keyword for any mode definition, minor or major- to help `desktop
save/recover' properly handle the buffer state. Doubtless there would
be yet more uses I haven't thought of.




Added tag(s) wontfix. Request was from Pádraig Brady <P <at> draigBrady.com> to control <at> debbugs.gnu.org. (Wed, 30 Oct 2013 10:55:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15659; Package emacs. (Fri, 08 Nov 2013 20:30:02 GMT) Full text and rfc822 format available.

Message #16 received at 15659 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: yary <not.com <at> gmail.com>
Cc: 15659 <at> debbugs.gnu.org
Subject: Re: bug#15659: 24.1;
 (wishlist) Simple method for preserving minor-mode
Date: Fri, 08 Nov 2013 15:29:20 -0500
> 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




Removed tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 01 Feb 2014 07:13:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15659; Package emacs. (Sat, 04 Dec 2021 03:38:01 GMT) Full text and rfc822 format available.

Message #21 received at 15659 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: yary <not.com <at> gmail.com>, 15659 <at> debbugs.gnu.org
Subject: Re: bug#15659: 24.1; (wishlist) Simple method for preserving
 minor-mode
Date: Sat, 04 Dec 2021 04:37:13 +0100
Stefan Monnier <monnier <at> 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




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 04 Dec 2021 03:38:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 15659 <at> debbugs.gnu.org and yary <not.com <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 04 Dec 2021 03:38:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 01 Jan 2022 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 116 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.