* How do I find out what minor modes are in effect?
@ 2012-04-11 13:49 Doug Lewan
2012-04-11 13:58 ` Jambunathan K
0 siblings, 1 reply; 7+ messages in thread
From: Doug Lewan @ 2012-04-11 13:49 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
I'm writing a function that needs to change the major mode to do its stuff properly.
That can turn off minor modes too.
The obvious polite thing to do is turn them all back on when I'm done.
Resetting the major mode is easy:
(defun vertical-text (text)
(let ((mode-to-restore major-mode)
(picture-mode)
...
(funcall mode-to-restore)))
How do I find out what minor modes are in effect?
And in what order they were invoked?
(They can stomp on each other and
I'd rather not introduce bugs
that are different from what the user already expects.
(Ultimately, I think this might be generally useful,
so a function like (save-mode) might emerge.)
,Douglas
Douglas Lewan
Shubert Ticketing
(201) 489-8600 ext 224
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I find out what minor modes are in effect?
2012-04-11 13:49 Doug Lewan
@ 2012-04-11 13:58 ` Jambunathan K
2012-04-11 14:28 ` Doug Lewan
0 siblings, 1 reply; 7+ messages in thread
From: Jambunathan K @ 2012-04-11 13:58 UTC (permalink / raw)
To: Doug Lewan; +Cc: help-gnu-emacs@gnu.org
Doug Lewan <dougl@shubertticketing.com> writes:
> I'm writing a function that needs to change the major mode to do its stuff properly.
> That can turn off minor modes too.
> The obvious polite thing to do is turn them all back on when I'm done.
>
> Resetting the major mode is easy:
> (defun vertical-text (text)
> (let ((mode-to-restore major-mode)
> (picture-mode)
> ...
> (funcall mode-to-restore)))
>
> How do I find out what minor modes are in effect?
> And in what order they were invoked?
> (They can stomp on each other and
> I'd rather not introduce bugs
> that are different from what the user already expects.
>
> (Ultimately, I think this might be generally useful,
> so a function like (save-mode) might emerge.)
When in "message-mode" (the buffer I am composing this message in) and I
do C-h m I see the following at the top of the resulting "Help" buffer.
,---- C-h m
| Enabled minor modes: Auto-Composition Auto-Compression Auto-Encryption
| Auto-Fill Column-Number File-Name-Shadow Font-Lock Footnote
| Global-Font-Lock Gnus-Message-Citation Ido-Everywhere Iswitchb
| Line-Number Mml Mouse-Wheel Shell-Dirtrack Tooltip Transient-Mark
| Which-Function
`----
This suggests that you can steal some code from the C-h k C-h m .
M-x find-function RET describe-mode RET
> ,Douglas
> Douglas Lewan
> Shubert Ticketing
> (201) 489-8600 ext 224
>
>
>
>
--
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: How do I find out what minor modes are in effect?
2012-04-11 13:58 ` Jambunathan K
@ 2012-04-11 14:28 ` Doug Lewan
0 siblings, 0 replies; 7+ messages in thread
From: Doug Lewan @ 2012-04-11 14:28 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
>
> Doug Lewan <dougl@shubertticketing.com> writes:
>
> >
> > How do I find out what minor modes are in effect?
>
> Jambunathan K [kjambunathan@gmail.com] responded:
>
> This suggests that you can steal some code from the C-h k C-h m .
>
> M-x find-function RET describe-mode RET
>
A quick peek revealed this comment:
;; Document a minor mode if it is listed in minor-mode-alist,
;; non-nil, and has a function definition.
And about two minutes of reading and adapting got this code:
(let ((mode)
(result))
(dolist (mode minor-mode-list result)
(let ((fmode (or (get mode :minor-mode-function) mode)))
(if (and (boundp mode) (symbol-value mode) (fboundp fmode))
(push mode result))))
result)
I guess you should trust code more than documentation, said the embarassed programmer.
Thanks.
,Doug
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I find out what minor modes are in effect?
[not found] <mailman.1053.1334152093.20052.help-gnu-emacs@gnu.org>
@ 2012-04-11 15:54 ` Pascal J. Bourguignon
2012-04-11 18:09 ` Stefan Monnier
1 sibling, 0 replies; 7+ messages in thread
From: Pascal J. Bourguignon @ 2012-04-11 15:54 UTC (permalink / raw)
To: help-gnu-emacs
Doug Lewan <dougl@shubertticketing.com> writes:
> I'm writing a function that needs to change the major mode to do its stuff properly.
> That can turn off minor modes too.
> The obvious polite thing to do is turn them all back on when I'm done.
>
> Resetting the major mode is easy:
> (defun vertical-text (text)
> (let ((mode-to-restore major-mode)
> (picture-mode)
> ...
> (funcall mode-to-restore)))
>
> How do I find out what minor modes are in effect?
(defun current-minor-modes (&optional buffer)
"The list of the minor modes currently active in the buffer (or current buffer)."
(let ((result '()))
(with-current-buffer (or buffer (current-buffer))
(dolist (mode minor-mode-list result)
(when (and (boundp mode) (symbol-value mode))
(push mode result))))))
> And in what order they were invoked?
Depending on where they're called, in the various hooks and init files.
> (They can stomp on each other and
Indeed.
Have a look at with-mode-local too.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I find out what minor modes are in effect?
[not found] <mailman.1053.1334152093.20052.help-gnu-emacs@gnu.org>
2012-04-11 15:54 ` Pascal J. Bourguignon
@ 2012-04-11 18:09 ` Stefan Monnier
1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2012-04-11 18:09 UTC (permalink / raw)
To: help-gnu-emacs
> I'm writing a function that needs to change the major mode to do its
> stuff properly. That can turn off minor modes too. The obvious
> polite thing to do is turn them all back on when I'm done.
FWIW, you might want to M-x report-emacs-bug and request such
a functionality or provide a patch that implements such a thing.
There are several major modes which need to do that (picture-mode and
image-mode come to mind, I'm sure there are more).
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I find out what minor modes are in effect?
@ 2012-04-12 11:49 Doug Lewan
0 siblings, 0 replies; 7+ messages in thread
From: Doug Lewan @ 2012-04-12 11:49 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
Yesterday I asked:
> How do I find out what minor modes are in effect?
> And in what order they were invoked?
And I got a lot of good help. Thank you, everyone.
The practical, first-time implementation is in place and works.
Now it's time to write the (save-mode) macro.
(Which means I suddenly have to get better at writing macros. Darn!)
,Douglas
Douglas Lewan
Shubert Ticketing
(201) 489-8600 ext 224
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I find out what minor modes are in effect?
[not found] <mailman.1140.1334231241.20052.help-gnu-emacs@gnu.org>
@ 2012-04-12 13:33 ` Stefan Monnier
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2012-04-12 13:33 UTC (permalink / raw)
To: help-gnu-emacs
> The practical, first-time implementation is in place and works.
> Now it's time to write the (save-mode) macro.
> (Which means I suddenly have to get better at writing macros. Darn!)
BTW, an alternative approach can rely on `buffer-local-variables': just
stash away the value of all variables that are buffer-local, so you can
re-set them later.
The downside is that it won't enable the major/minor modes explicitly
upon restore, so the mode hooks won't be run, and some other state may
be missing (e.g. if a minor mode relies on a timer, the restore may
fail to re-start the timer).
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-04-12 13:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-12 11:49 How do I find out what minor modes are in effect? Doug Lewan
[not found] <mailman.1140.1334231241.20052.help-gnu-emacs@gnu.org>
2012-04-12 13:33 ` Stefan Monnier
[not found] <mailman.1053.1334152093.20052.help-gnu-emacs@gnu.org>
2012-04-11 15:54 ` Pascal J. Bourguignon
2012-04-11 18:09 ` Stefan Monnier
-- strict thread matches above, loose matches on Subject: below --
2012-04-11 13:49 Doug Lewan
2012-04-11 13:58 ` Jambunathan K
2012-04-11 14:28 ` Doug Lewan
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).