[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Mode loaded twice with Local Variables
From: |
Michaël Cadilhac |
Subject: |
Mode loaded twice with Local Variables |
Date: |
Tue, 09 May 2006 11:53:33 +0200 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux) |
I hope this issue hasn't already been discussed.
Create a file that contains the following:
Local Variables:
mode: foo
eval: (message "aoeu")
End:
named `test.foo'.
Then M-x eval-region RET the following:
(define-derived-mode foo-mode text-mode "foo mode")
(add-hook 'foo-mode-hook (lambda () (message "File opened at %s\n"
(current-time-string))))
(add-to-list 'auto-mode-alist '("\\.foo$" . foo-mode))
Then open `test.foo'. The (message "File opened") will be displayed
twice:
- When set-auto-mode will be called (calling foo-mode),
- When local variables are evaluated (again calling foo-mode).
I don't expect that, in particular, I have some LaTeX file that
contains mode: LaTeX, but some questions are asked in my
LaTeX-mode-hook, so they're asked twice.
I propose this, maybe naive, change:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.9511
diff -c -r1.9511 ChangeLog
*** ChangeLog 9 May 2006 04:26:22 -0000 1.9511
--- ChangeLog 9 May 2006 09:50:07 -0000
***************
*** 1,3 ****
--- 1,8 ----
+ 2006-05-09 Michaël Cadilhac <address@hidden>
+
+ * files.el (normal-mode): Look at `Local Variables' before
+ `auto-mode-alist' to prevent double mode loading.
+
2006-05-09 Michael Albinus <address@hidden>
* net/tramp.el (tramp-register-file-name-handlers): Enable Tramp
Index: files.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/files.el,v
retrieving revision 1.830
diff -c -r1.830 files.el
*** files.el 6 May 2006 14:37:04 -0000 1.830
--- files.el 9 May 2006 09:50:07 -0000
***************
*** 1797,1807 ****
in that case, this function acts as if `enable-local-variables' were t."
(interactive)
(funcall (or default-major-mode 'fundamental-mode))
! (let ((enable-local-variables (or (not find-file) enable-local-variables)))
! (report-errors "File mode specification error: %s"
! (set-auto-mode))
(report-errors "File local-variables error: %s"
! (hack-local-variables)))
;; Turn font lock off and on, to make sure it takes account of
;; whatever file local variables are relevant to it.
(when (and font-lock-mode
--- 1797,1814 ----
in that case, this function acts as if `enable-local-variables' were t."
(interactive)
(funcall (or default-major-mode 'fundamental-mode))
! (let ((enable-local-variables (or (not find-file) enable-local-variables))
! (current-major-mode major-mode))
! (setq major-mode nil)
(report-errors "File local-variables error: %s"
! (hack-local-variables))
! ;; If no major mode was specified by local variables, use auto mode.
! (unless major-mode
! (report-errors "File mode specification error: %s"
! (set-auto-mode))
! ;; No auto mode, restore default one.
! (unless major-mode
! (setq major-mode current-major-mode))))
;; Turn font lock off and on, to make sure it takes account of
;; whatever file local variables are relevant to it.
(when (and font-lock-mode
--
| Michaël `Micha' Cadilhac | Mieux vaut se taire |
| Epita/LRDE Promo 2007 | Que de parler trop fort. |
| http://www.lrde.org/~cadilh_m | -- As de trèfle |
`-- - JID: address@hidden --' - --'
pgpmjHzP_fgND.pgp
Description: PGP signature
- Mode loaded twice with Local Variables,
Michaël Cadilhac <=