From e5cb26a84c0385d2139b40ed7e8644f8f299e291 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 2 Jan 2005 01:20:33 +0000 Subject: [PATCH] (hack-local-variables): Cleanup prefix/suffix matching. --- lisp/files.el | 59 +++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index d1340235ea5..cfee975066d 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1,7 +1,7 @@ ;;; 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)) -- 2.39.5