* define-minor-mode, auto-mode-alist & change-major-mode-with-file-name
@ 2012-02-05 13:57 Sebastian Tennant
2012-02-05 14:33 ` Lennart Borgman
0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Tennant @ 2012-02-05 13:57 UTC (permalink / raw
To: emacs-devel
Hi list,
Test sequence #1
================
(define-minor-mode test-me-mode "Test Me"
:lighter " TM" (message "I have been Tested."))
(add-to-list 'auto-mode-alist '("\\.test-me\\'" . test-me-mode))
Commands *Messages*
-------- ----------
C-x b foo.test-me RET y No buffer matching `foo.test-me', create one? (y or n)
M-x test-me-mode I have been Tested.
C-x C-w RET Toggling test-me-mode off; better pass an explicit argument.
I have been Tested.
Saving file ~/foo.test-me...
Wrote ~/foo.test-me
RESULT: buffer foo.test-me is no longer in test-me mode.
Test sequence #2
================
Kill buffer foo.test-me and delete file.
(define-minor-mode test-me-mode "Test Me"
(set (make-local-variable 'change-major-mode-with-file-name) nil)
:lighter " TM" (message "I have been Tested."))
;; unchanged - no need to re-evaluate
(add-to-list 'auto-mode-alist '("\\.test-me\\'" . test-me-mode))
Commands *Messages*
-------- ----------
C-x b foo.test-me RET y No buffer matching `foo.test-me', create one? (y or n)
M-x test-me-mode I have been Tested.
C-x C-w RET Saving file ~/foo.test-me...
Wrote ~/foo.test-me
RESULT: buffer foo.test-me remains in test-me mode.
Analysis
========
Macro define-minor-mode creates a toggle-able minor mode function (as it
should). However, when a non-file visiting buffer is 'manually' put into a minor
mode defined using said macro and then written to disk using a file name which
triggers that minor mode (via auto-mode-alist), the effect of this
toggle-ability is to turn the minor mode off. Test sequence #1.
One way of preventing this is to set change-major-mode-with-file-name to nil in
your minor mode function definition. Test sequence #2.
Questions
=========
1. Is there a better way of preventing the minor mode from being turned off,
(short of not using define-minor-mode) when this precise sequence of
commands is performed?
2. Given that change-major-mode-with-file-name works with minor modes too (as
demonstrated), shouldn't it be called change-mode-with-file-name instead?
3. Generally speaking, auto-mode-alist only kicks in when visiting a file.
When a non-file visiting buffer is written to disk, it (the buffer) is
immediately replaced by a file-visiting buffer, hence the apparent
effectiveness of auto-mode-alist when writing a file (rather than visiting
one). Is this explanation more or less correct?
Sebastian
(emacs-version)
=> "GNU Emacs 23.2.1 (i486-pc-linux-gnu) of 2010-12-11 on raven, modified by Debian"
--
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: define-minor-mode, auto-mode-alist & change-major-mode-with-file-name
2012-02-05 13:57 define-minor-mode, auto-mode-alist & change-major-mode-with-file-name Sebastian Tennant
@ 2012-02-05 14:33 ` Lennart Borgman
2012-02-05 17:52 ` Sebastian Tennant
0 siblings, 1 reply; 3+ messages in thread
From: Lennart Borgman @ 2012-02-05 14:33 UTC (permalink / raw
To: Sebastian Tennant; +Cc: emacs-devel
On Sun, Feb 5, 2012 at 14:57, Sebastian Tennant <sebyte@smolny.plus.com> wrote:
> Hi list,
>
> Test sequence #1
> ================
> (define-minor-mode test-me-mode "Test Me"
> :lighter " TM" (message "I have been Tested."))
>
> (add-to-list 'auto-mode-alist '("\\.test-me\\'" . test-me-mode))
auto-mode-alist is for major modes, not minor modes.
If you want to turn on a minor mode a way to do it is to use the major
modes mode hook.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: define-minor-mode, auto-mode-alist & change-major-mode-with-file-name
2012-02-05 14:33 ` Lennart Borgman
@ 2012-02-05 17:52 ` Sebastian Tennant
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Tennant @ 2012-02-05 17:52 UTC (permalink / raw
To: emacs-devel
Quoth Lennart Borgman <lennart.borgman@gmail.com>:
> On Sun, Feb 5, 2012 at 14:57, Sebastian Tennant <sebyte@smolny.plus.com> wrote:
>> (define-minor-mode test-me-mode "Test Me"
>> :lighter " TM" (message "I have been Tested."))
>>
>> (add-to-list 'auto-mode-alist '("\\.test-me\\'" . test-me-mode))
>
> auto-mode-alist is for major modes, not minor modes.
Ah.
> If you want to turn on a minor mode a way to do it is to use the major
> modes mode hook.
It doesn't say that in elisp.info! But it does beg the question why am I using
a minor mode? Thanks.
--
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-02-05 17:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-05 13:57 define-minor-mode, auto-mode-alist & change-major-mode-with-file-name Sebastian Tennant
2012-02-05 14:33 ` Lennart Borgman
2012-02-05 17:52 ` Sebastian Tennant
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.