[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
define-minor-mode, auto-mode-alist & change-major-mode-with-file-name
From: |
Sebastian Tennant |
Subject: |
define-minor-mode, auto-mode-alist & change-major-mode-with-file-name |
Date: |
Sun, 05 Feb 2012 13:57:39 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
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
- define-minor-mode, auto-mode-alist & change-major-mode-with-file-name,
Sebastian Tennant <=