all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Mode loaded twice with Local Variables
@ 2006-05-09  9:53 Michaël Cadilhac
  2006-05-09 13:22 ` Chong Yidong
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Michaël Cadilhac @ 2006-05-09  9:53 UTC (permalink / raw)



[-- Attachment #1.1.1: Type: text/plain, Size: 862 bytes --]


  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:


[-- Attachment #1.1.2: files.patch --]
[-- Type: text/x-patch, Size: 2380 bytes --]

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  <michael.cadilhac@lrde.org>
+ 
+ 	* files.el (normal-mode): Look at `Local Variables' before
+ 	`auto-mode-alist' to prevent double mode loading.
+ 
  2006-05-09  Michael Albinus  <michael.albinus@gmx.de>
  
  	* 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

[-- Attachment #1.1.3: Type: text/plain, Size: 325 bytes --]



-- 
 |      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: micha@amessage.be --'                                   -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2006-06-14 23:09 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-09  9:53 Mode loaded twice with Local Variables Michaël Cadilhac
2006-05-09 13:22 ` Chong Yidong
2006-05-09 13:53   ` Michaël Cadilhac
2006-05-09 16:08 ` Stuart D. Herring
2006-05-10 17:50   ` Richard Stallman
2006-05-10 18:20     ` Stuart D. Herring
2006-05-11 18:31       ` Richard Stallman
2006-05-10 18:29   ` Michaël Cadilhac
2006-05-10 19:59     ` Stuart D. Herring
2006-05-11 18:31       ` Richard Stallman
2006-05-11 19:00         ` Stuart D. Herring
2006-05-11 18:31     ` Richard Stallman
2006-06-14 23:09     ` Stuart D. Herring
2006-05-10  3:20 ` Richard Stallman

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.