mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-04 22:50:59 -08:00
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.
This commit is contained in:
parent
2a35386df4
commit
7e4ccca345
2 changed files with 91 additions and 80 deletions
|
|
@ -1,5 +1,8 @@
|
|||
2011-05-21 Glenn Morris <rgm@gnu.org>
|
||||
|
||||
* 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)
|
||||
|
||||
|
|
|
|||
168
lisp/files.el
168
lisp/files.el
|
|
@ -3055,7 +3055,9 @@ and VAL is the specified value."
|
|||
(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 @@ 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)
|
||||
;; 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)))
|
||||
(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))
|
||||
(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))))))))
|
||||
(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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue