emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r104309: Small files.el hack-local ch


From: Glenn Morris
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104309: Small files.el hack-local changes for mode-only case.
Date: Sat, 21 May 2011 15:33:12 -0700
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104309
committer: Glenn Morris <address@hidden>
branch nick: trunk
timestamp: Sat 2011-05-21 15:33:12 -0700
message:
  Small files.el hack-local changes for mode-only case.
  
  * lisp/files.el (hack-local-variables-prop-line, hack-local-variables):
  If only interested in the mode, don't bother doing the other stuff.
modified:
  lisp/ChangeLog
  lisp/files.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-05-21 02:09:49 +0000
+++ b/lisp/ChangeLog    2011-05-21 22:33:12 +0000
@@ -1,5 +1,8 @@
 2011-05-21  Glenn Morris  <address@hidden>
 
+       * files.el (hack-local-variables-prop-line, hack-local-variables):
+       If only interested in the mode, don't bother doing the other stuff.
+
        * image-mode.el (image-after-revert-hook):
        Redraw all frames on which the image is visible.  (Bug#8567)
 

=== modified file 'lisp/files.el'
--- a/lisp/files.el     2011-05-20 00:51:46 +0000
+++ b/lisp/files.el     2011-05-21 22:33:12 +0000
@@ -3055,7 +3055,9 @@
            (t
             ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
             ;; (last ";" is optional).
-            (while (< (point) end)
+            (while (and (< (point) end)
+                        (or (not mode-only)
+                            (not mode-specified)))
               (or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
                   (error "Malformed -*- line"))
               (goto-char (match-end 0))
@@ -3074,6 +3076,7 @@
                 ;; The same can be said for `coding' in set-auto-coding.
                 (or (and (equal (downcase (symbol-name key)) "mode")
                          (setq mode-specified t))
+                    mode-only
                     (equal (downcase (symbol-name key)) "coding")
                     (condition-case nil
                         (push (cons (if (eq key 'eval)
@@ -3154,88 +3157,93 @@
       (report-errors "Directory-local variables error: %s"
        (hack-dir-local-variables)))
     (when (or mode-only enable-local-variables)
-      (setq result (hack-local-variables-prop-line mode-only))
-      ;; Look for "Local variables:" line in last page.
-      (save-excursion
-       (goto-char (point-max))
-       (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
-                        'move)
-       (when (let ((case-fold-search t))
-               (search-forward "Local Variables:" nil t))
-         (skip-chars-forward " \t")
-         ;; suffix is what comes after "local variables:" in its line.
-         ;; prefix is what comes before "local variables:" in its line.
-         (let ((suffix
-                (concat
-                 (regexp-quote (buffer-substring (point)
-                                                 (line-end-position)))
-                 "$"))
-               (prefix
-                (concat "^" (regexp-quote
-                             (buffer-substring (line-beginning-position)
-                                               (match-beginning 0)))))
-               beg)
-
-           (forward-line 1)
-           (let ((startpos (point))
-                 endpos
-                 (thisbuf (current-buffer)))
-             (save-excursion
-               (unless (let ((case-fold-search t))
-                         (re-search-forward
-                          (concat prefix "[ \t]*End:[ \t]*" suffix)
-                          nil t))
-                  ;; This used to be an error, but really all it means is
-                  ;; that this may simply not be a local-variables section,
-                  ;; so just ignore it.
-                 (message "Local variables list is not properly terminated"))
-               (beginning-of-line)
-               (setq endpos (point)))
-
-             (with-temp-buffer
-               (insert-buffer-substring thisbuf startpos endpos)
-               (goto-char (point-min))
-               (subst-char-in-region (point) (point-max) ?\^m ?\n)
-               (while (not (eobp))
-                 ;; Discard the prefix.
-                 (if (looking-at prefix)
-                     (delete-region (point) (match-end 0))
-                   (error "Local variables entry is missing the prefix"))
-                 (end-of-line)
-                 ;; Discard the suffix.
-                 (if (looking-back suffix)
-                     (delete-region (match-beginning 0) (point))
-                   (error "Local variables entry is missing the suffix"))
-                 (forward-line 1))
-               (goto-char (point-min))
-
-               (while (not (eobp))
-                 ;; Find the variable name; strip whitespace.
-                 (skip-chars-forward " \t")
-                 (setq beg (point))
-                 (skip-chars-forward "^:\n")
-                 (if (eolp) (error "Missing colon in local variables entry"))
-                 (skip-chars-backward " \t")
-                 (let* ((str (buffer-substring beg (point)))
-                        (var (let ((read-circle nil))
-                               (read str)))
-                        val)
-                   ;; Read the variable value.
-                   (skip-chars-forward "^:")
-                   (forward-char 1)
-                   (let ((read-circle nil))
-                     (setq val (read (current-buffer))))
-                   (if mode-only
-                       (if (eq var 'mode)
-                           (setq result t))
-                     (unless (eq var 'coding)
-                       (condition-case nil
-                           (push (cons (if (eq var 'eval)
-                                           'eval
-                                         (indirect-variable var))
-                                       val) result)
-                         (error nil)))))
-                 (forward-line 1))))))))
+      ;; If MODE-ONLY is non-nil, and the prop line specifies a mode,
+      ;; then we're done, and have no need to scan further.
+      (unless (and (setq result (hack-local-variables-prop-line mode-only))
+                  mode-only)
+       ;; Look for "Local variables:" line in last page.
+       (save-excursion
+         (goto-char (point-max))
+         (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
+                          'move)
+         (when (let ((case-fold-search t))
+                 (search-forward "Local Variables:" nil t))
+           (skip-chars-forward " \t")
+           ;; suffix is what comes after "local variables:" in its line.
+           ;; prefix is what comes before "local variables:" in its line.
+           (let ((suffix
+                  (concat
+                   (regexp-quote (buffer-substring (point)
+                                                   (line-end-position)))
+                   "$"))
+                 (prefix
+                  (concat "^" (regexp-quote
+                               (buffer-substring (line-beginning-position)
+                                                 (match-beginning 0)))))
+                 beg)
+
+             (forward-line 1)
+             (let ((startpos (point))
+                   endpos
+                   (thisbuf (current-buffer)))
+               (save-excursion
+                 (unless (let ((case-fold-search t))
+                           (re-search-forward
+                            (concat prefix "[ \t]*End:[ \t]*" suffix)
+                            nil t))
+                   ;; This used to be an error, but really all it means is
+                   ;; that this may simply not be a local-variables section,
+                   ;; so just ignore it.
+                   (message "Local variables list is not properly terminated"))
+                 (beginning-of-line)
+                 (setq endpos (point)))
+
+               (with-temp-buffer
+                 (insert-buffer-substring thisbuf startpos endpos)
+                 (goto-char (point-min))
+                 (subst-char-in-region (point) (point-max) ?\^m ?\n)
+                 (while (not (eobp))
+                   ;; Discard the prefix.
+                   (if (looking-at prefix)
+                       (delete-region (point) (match-end 0))
+                     (error "Local variables entry is missing the prefix"))
+                   (end-of-line)
+                   ;; Discard the suffix.
+                   (if (looking-back suffix)
+                       (delete-region (match-beginning 0) (point))
+                     (error "Local variables entry is missing the suffix"))
+                   (forward-line 1))
+                 (goto-char (point-min))
+
+                 (while (and (not (eobp))
+                             (or (not mode-only)
+                                 (not result)))
+                   ;; Find the variable name; strip whitespace.
+                   (skip-chars-forward " \t")
+                   (setq beg (point))
+                   (skip-chars-forward "^:\n")
+                   (if (eolp) (error "Missing colon in local variables entry"))
+                   (skip-chars-backward " \t")
+                   (let* ((str (buffer-substring beg (point)))
+                          (var (let ((read-circle nil))
+                                 (read str)))
+                          val)
+                     ;; Read the variable value.
+                     (skip-chars-forward "^:")
+                     (forward-char 1)
+                     (let ((read-circle nil))
+                       (setq val (read (current-buffer))))
+                     (if mode-only
+                         (if (eq var 'mode)
+                             (setq result t))
+                       (unless (eq var 'coding)
+                         (condition-case nil
+                             (push (cons (if (eq var 'eval)
+                                             'eval
+                                           (indirect-variable var))
+                                         val) result)
+                           (error nil)))))
+                   (forward-line 1)))))))))
     ;; Now we've read all the local variables.
     ;; If MODE-ONLY is non-nil, return whether the mode was specified.
     (cond (mode-only result)


reply via email to

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