changeset 59293:eacd4fd94e38

(hack-local-variables): Cleanup prefix/suffix matching.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 02 Jan 2005 01:20:33 +0000
parents c8adcd0d5e2e
children f40f6af0782a
files lisp/files.el
diffstat 1 files changed, 26 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Sun Jan 02 01:20:14 2005 +0000
+++ b/lisp/files.el	Sun Jan 02 01:20:33 2005 +0000
@@ -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 @@
 						   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 @@
 	      (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))