From 7e4ccca3454e6ef6ccaf14827f274647b2bf56e1 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Sat, 21 May 2011 15:33:12 -0700 Subject: [PATCH] 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. --- lisp/ChangeLog | 3 + lisp/files.el | 174 ++++++++++++++++++++++++++----------------------- 2 files changed, 94 insertions(+), 83 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3ea95bda944..a5af20b109b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2011-05-21 Glenn Morris + * 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) diff --git a/lisp/files.el b/lisp/files.el index 200b9b1d303..e6f0d93299c 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3055,7 +3055,9 @@ and VAL is the specified value." (t ;; Hairy form: '-*-' [ ':' ';' ]* '-*-' ;; (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 @@ and VAL is the specified value." ;; 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 @@ is specified, returning t if it is specified." (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) -- 2.39.2