Commit e5cb26a8 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(hack-local-variables): Cleanup prefix/suffix matching.

parent 4c759a32
;;; files.el --- file input and output commands for Emacs
;; Copyright (C) 1985,86,87,92,93,94,95,96,97,98,99,2000,01,02,03,2004
;;; Free Software Foundation, Inc.
;; Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
;; 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
;; Maintainer: FSF
......@@ -2218,31 +2218,27 @@ is specified, returning t if it is specified."
buffer-file-name)
(concat "buffer "
(buffer-name))))))))))
(let (prefix suffix beg
(enable-local-eval enable-local-eval))
;; The prefix is what comes before "local variables:" in its line.
;; The suffix is what comes after "local variables:" in its line.
(skip-chars-forward " \t")
(or (eolp)
(setq suffix (buffer-substring (point)
(progn (end-of-line) (point)))))
(goto-char (match-beginning 0))
(or (bolp)
(setq prefix
(buffer-substring (point)
(progn (beginning-of-line) (point)))))
(setq prefix (if prefix (regexp-quote prefix) "^"))
(if suffix (setq suffix (concat (regexp-quote suffix) "$")))
(skip-chars-forward " \t")
(let ((enable-local-eval enable-local-eval)
;; suffix is what comes after "local variables:" in its line.
(suffix
(concat
(regexp-quote (buffer-substring (point) (line-end-position)))
"$"))
;; prefix is what comes before "local variables:" in its line.
(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
(if (not (re-search-forward
(concat (or prefix "")
"[ \t]*End:[ \t]*"
(or suffix ""))
(concat prefix "[ \t]*End:[ \t]*" suffix)
nil t))
(error "Local variables list is not properly terminated"))
(beginning-of-line)
......@@ -2251,20 +2247,17 @@ is specified, returning t if it is specified."
(with-temp-buffer
(insert-buffer-substring thisbuf startpos endpos)
(goto-char (point-min))
(subst-char-in-region (point) (point-max)
?\^m ?\n)
(subst-char-in-region (point) (point-max) ?\^m ?\n)
(while (not (eobp))
;; Discard the prefix, if any.
(if prefix
(if (looking-at prefix)
(delete-region (point) (match-end 0))
(error "Local variables entry is missing the prefix")))
;; 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 any.
(if suffix
(if (looking-back suffix)
(delete-region (match-beginning 0) (point))
(error "Local variables entry is missing the suffix")))
;; 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))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment