emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r104380: Make set-auto-mode respect m


From: Glenn Morris
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104380: Make set-auto-mode respect mode: entries at the end of the file (bug#8586)
Date: Thu, 26 May 2011 21:00:53 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104380
committer: Glenn Morris <address@hidden>
branch nick: trunk
timestamp: Thu 2011-05-26 21:00:53 -0400
message:
  Make set-auto-mode respect mode: entries at the end of the file (bug#8586)
  
  * lisp/files.el (set-auto-mode):
  Also respect mode: entries at the end of the file.
  
  * doc/lispref/modes.texi (Auto Major Mode):
  Update for set-auto-mode changes.
  
  * doc/emacs/custom.texi (Specifying File Variables):
  Major modes no longer need come first.
  
  * etc/NEWS: Mention this.
modified:
  doc/emacs/ChangeLog
  doc/emacs/custom.texi
  doc/lispref/ChangeLog
  doc/lispref/modes.texi
  etc/NEWS
  lisp/ChangeLog
  lisp/files.el
=== modified file 'doc/emacs/ChangeLog'
--- a/doc/emacs/ChangeLog       2011-05-22 19:05:14 +0000
+++ b/doc/emacs/ChangeLog       2011-05-27 01:00:53 +0000
@@ -1,3 +1,8 @@
+2011-05-27  Glenn Morris  <address@hidden>
+
+       * custom.texi (Specifying File Variables):
+       Major modes no longer need come first.
+
 2011-05-22  Chong Yidong  <address@hidden>
 
        * mule.texi (Specify Coding, Text Coding, Communication Coding):

=== modified file 'doc/emacs/custom.texi'
--- a/doc/emacs/custom.texi     2011-05-17 02:26:56 +0000
+++ b/doc/emacs/custom.texi     2011-05-27 01:00:53 +0000
@@ -1130,7 +1130,10 @@
 
   If a file has both a local variables list and a @samp{-*-} line,
 Emacs processes @emph{everything} in the @samp{-*-} line first, and
address@hidden in the local variables list afterward.
address@hidden in the local variables list afterward.  The exception
+to this is a major mode specification.  Emacs applies this first,
+wherever it appears, since most major modes kill all local variables as
+part of their initialization.
 
   A local variables list starts with a line containing the string
 @samp{Local Variables:}, and ends with a line containing the string
@@ -1205,11 +1208,6 @@
 These four ``variables'' are not really variables; setting them in any
 other context has no special meaning.
 
-  @emph{If @code{mode} is used to set a major mode, it should be the
-first ``variable'' in the list.}  Otherwise, the entries that precede
-it will usually have no effect, since most major modes kill all local
-variables as part of their initialization.
-
   You can use the @code{mode} ``variable'' to enable minor modes as
 well as the major modes; in fact, you can use it more than once, first
 to set the major mode and then to enable minor modes which are

=== modified file 'doc/lispref/ChangeLog'
--- a/doc/lispref/ChangeLog     2011-05-26 16:20:21 +0000
+++ b/doc/lispref/ChangeLog     2011-05-27 01:00:53 +0000
@@ -1,3 +1,7 @@
+2011-05-27  Glenn Morris  <address@hidden>
+
+       * modes.texi (Auto Major Mode): Update for set-auto-mode changes.
+
 2011-05-26  Glenn Morris  <address@hidden>
 
        * variables.texi (File Local Variables):

=== modified file 'doc/lispref/modes.texi'
--- a/doc/lispref/modes.texi    2011-05-19 06:54:27 +0000
+++ b/doc/lispref/modes.texi    2011-05-27 01:00:53 +0000
@@ -583,12 +583,9 @@
 @var{find-file} is normally @code{nil}.  In this case,
 @code{normal-mode} unconditionally processes any file local variables.
 
-If @code{normal-mode} processes the local variables list and this list
-specifies a major mode, that mode overrides any mode chosen by
address@hidden  If neither @code{set-auto-mode} nor
address@hidden specify a major mode, the buffer stays in
-the major mode determined by the default value of @code{major-mode}
-(see below).
+The function calls @code{set-auto-mode} to choose a major mode.  If it
+does not specify a mode, the buffer stays in the major mode determined
+by the default value of @code{major-mode} (see below).
 
 @cindex file mode specification error
 @code{normal-mode} uses @code{condition-case} around the call to the
@@ -600,15 +597,15 @@
 @cindex visited file mode
   This function selects the major mode that is appropriate for the
 current buffer.  It bases its decision (in order of precedence) on
-the @address@hidden line, on the @address@hidden line (using
+the @address@hidden line, on any @samp{mode:} local variable near the
+end of a file, on the @address@hidden line (using
 @code{interpreter-mode-alist}), on the text at the beginning of the
 buffer (using @code{magic-mode-alist}), and finally on the visited
 file name (using @code{auto-mode-alist}).  @xref{Choosing Modes, , How
-Major Modes are Chosen, emacs, The GNU Emacs Manual}.  However, this
-function does not look for the @samp{mode:} local variable near the
-end of a file; the @code{hack-local-variables} function does that.
+Major Modes are Chosen, emacs, The GNU Emacs Manual}. 
 If @code{enable-local-variables} is @code{nil}, @code{set-auto-mode}
-does not check the @address@hidden line for a mode tag either.
+does not check the @address@hidden line, or near the end of the file,
+for any mode tag.
 
 If @var{keep-mode-if-same} is address@hidden, this function does not
 call the mode command if the buffer is already in the proper major

=== modified file 'etc/NEWS'
--- a/etc/NEWS  2011-05-24 14:22:44 +0000
+++ b/etc/NEWS  2011-05-27 01:00:53 +0000
@@ -993,6 +993,10 @@
 ** New variables `delayed-warnings-list' and `delayed-warnings-hook' allow
 deferring warnings until the main command loop is executed.
 
++++
+** `set-auto-mode' now respects mode: local variables at the end of files,
+as well as those in the -*- line.
+
 
 * Changes in Emacs 24.1 on non-free operating systems
 

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-05-26 07:35:47 +0000
+++ b/lisp/ChangeLog    2011-05-27 01:00:53 +0000
@@ -1,3 +1,8 @@
+2011-05-27  Glenn Morris  <address@hidden>
+
+       * files.el (set-auto-mode):
+       Also respect mode: entries at the end of the file.  (Bug#8586)
+
 2011-05-26  Glenn Morris  <address@hidden>
 
        * files.el (hack-local-variables-prop-line, hack-local-variables):

=== modified file 'lisp/files.el'
--- a/lisp/files.el     2011-05-26 07:35:47 +0000
+++ b/lisp/files.el     2011-05-27 01:00:53 +0000
@@ -2241,6 +2241,8 @@
   (interactive)
   (funcall (or (default-value 'major-mode) 'fundamental-mode))
   (let ((enable-local-variables (or (not find-file) enable-local-variables)))
+    ;; FIXME this is less efficient than it could be, since both
+    ;; s-a-m and h-l-v may parse the same regions, looking for "mode:".
     (report-errors "File mode specification error: %s"
       (set-auto-mode))
     (report-errors "File local-variables error: %s"
@@ -2616,23 +2618,24 @@
   "Select major mode appropriate for current buffer.
 
 To find the right major mode, this function checks for a -*- mode tag,
+checks for a `mode:' entry in the Local Variables section of the file,
 checks if it uses an interpreter listed in `interpreter-mode-alist',
 matches the buffer beginning against `magic-mode-alist',
 compares the filename against the entries in `auto-mode-alist',
 then matches the buffer beginning against `magic-fallback-mode-alist'.
 
-It does not check for the `mode:' local variable in the
-Local Variables section of the file; for that, use `hack-local-variables'.
-
-If `enable-local-variables' is nil, this function does not check for a
--*- mode tag.
+If `enable-local-variables' is nil, this function does not check for
+any mode: tag anywhere in the file.
 
 If the optional argument KEEP-MODE-IF-SAME is non-nil, then we
 set the major mode only if that would change it.  In other words
 we don't actually set it to the same mode the buffer already has."
   ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
   (let (end done mode modes)
-    ;; Find a -*- mode tag
+    ;; Once we drop the deprecated feature where mode: is also allowed to
+    ;; specify minor-modes (ie, there can be more than one "mode:), we can
+    ;; remove this section and just let (hack-local-variables t) handle it.
+    ;; Find a -*- mode tag.
     (save-excursion
       (goto-char (point-min))
       (skip-chars-forward " \t\n")
@@ -2667,6 +2670,14 @@
              (or (set-auto-mode-0 mode keep-mode-if-same)
                  ;; continuing would call minor modes again, toggling them off
                  (throw 'nop nil))))))
+    (and (not done)
+        enable-local-variables
+        (setq mode (hack-local-variables t))
+        (not (memq mode modes))        ; already tried and failed
+        (if (not (functionp mode))
+            (message "Ignoring unknown mode `%s'" mode)
+          (setq done t)
+          (set-auto-mode-0 mode keep-mode-if-same)))
     ;; If we didn't, look for an interpreter specified in the first line.
     ;; As a special case, allow for things like "#!/bin/env perl", which
     ;; finds the interpreter anywhere in $PATH.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]