Mercurial > emacs
comparison lisp/files.el @ 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 | e4a2eb7b1ae5 |
children | 8a9e4a779eb8 f6b4d0ebf147 |
comparison
equal
deleted
inserted
replaced
59292:c8adcd0d5e2e | 59293:eacd4fd94e38 |
---|---|
1 ;;; files.el --- file input and output commands for Emacs | 1 ;;; files.el --- file input and output commands for Emacs |
2 | 2 |
3 ;; Copyright (C) 1985,86,87,92,93,94,95,96,97,98,99,2000,01,02,03,2004 | 3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
4 ;;; Free Software Foundation, Inc. | 4 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
5 | 5 |
6 ;; Maintainer: FSF | 6 ;; Maintainer: FSF |
7 | 7 |
8 ;; This file is part of GNU Emacs. | 8 ;; This file is part of GNU Emacs. |
9 | 9 |
2216 (if buffer-file-name | 2216 (if buffer-file-name |
2217 (file-name-nondirectory | 2217 (file-name-nondirectory |
2218 buffer-file-name) | 2218 buffer-file-name) |
2219 (concat "buffer " | 2219 (concat "buffer " |
2220 (buffer-name)))))))))) | 2220 (buffer-name)))))))))) |
2221 (let (prefix suffix beg | 2221 (skip-chars-forward " \t") |
2222 (enable-local-eval enable-local-eval)) | 2222 (let ((enable-local-eval enable-local-eval) |
2223 ;; The prefix is what comes before "local variables:" in its line. | 2223 ;; suffix is what comes after "local variables:" in its line. |
2224 ;; The suffix is what comes after "local variables:" in its line. | 2224 (suffix |
2225 (skip-chars-forward " \t") | 2225 (concat |
2226 (or (eolp) | 2226 (regexp-quote (buffer-substring (point) (line-end-position))) |
2227 (setq suffix (buffer-substring (point) | 2227 "$")) |
2228 (progn (end-of-line) (point))))) | 2228 ;; prefix is what comes before "local variables:" in its line. |
2229 (goto-char (match-beginning 0)) | 2229 (prefix |
2230 (or (bolp) | 2230 (concat "^" (regexp-quote |
2231 (setq prefix | 2231 (buffer-substring (line-beginning-position) |
2232 (buffer-substring (point) | 2232 (match-beginning 0))))) |
2233 (progn (beginning-of-line) (point))))) | 2233 beg) |
2234 | 2234 |
2235 (setq prefix (if prefix (regexp-quote prefix) "^")) | |
2236 (if suffix (setq suffix (concat (regexp-quote suffix) "$"))) | |
2237 (forward-line 1) | 2235 (forward-line 1) |
2238 (let ((startpos (point)) | 2236 (let ((startpos (point)) |
2239 endpos | 2237 endpos |
2240 (thisbuf (current-buffer))) | 2238 (thisbuf (current-buffer))) |
2241 (save-excursion | 2239 (save-excursion |
2242 (if (not (re-search-forward | 2240 (if (not (re-search-forward |
2243 (concat (or prefix "") | 2241 (concat prefix "[ \t]*End:[ \t]*" suffix) |
2244 "[ \t]*End:[ \t]*" | |
2245 (or suffix "")) | |
2246 nil t)) | 2242 nil t)) |
2247 (error "Local variables list is not properly terminated")) | 2243 (error "Local variables list is not properly terminated")) |
2248 (beginning-of-line) | 2244 (beginning-of-line) |
2249 (setq endpos (point))) | 2245 (setq endpos (point))) |
2250 | 2246 |
2251 (with-temp-buffer | 2247 (with-temp-buffer |
2252 (insert-buffer-substring thisbuf startpos endpos) | 2248 (insert-buffer-substring thisbuf startpos endpos) |
2253 (goto-char (point-min)) | 2249 (goto-char (point-min)) |
2254 (subst-char-in-region (point) (point-max) | 2250 (subst-char-in-region (point) (point-max) ?\^m ?\n) |
2255 ?\^m ?\n) | |
2256 (while (not (eobp)) | 2251 (while (not (eobp)) |
2257 ;; Discard the prefix, if any. | 2252 ;; Discard the prefix. |
2258 (if prefix | 2253 (if (looking-at prefix) |
2259 (if (looking-at prefix) | 2254 (delete-region (point) (match-end 0)) |
2260 (delete-region (point) (match-end 0)) | 2255 (error "Local variables entry is missing the prefix")) |
2261 (error "Local variables entry is missing the prefix"))) | |
2262 (end-of-line) | 2256 (end-of-line) |
2263 ;; Discard the suffix, if any. | 2257 ;; Discard the suffix. |
2264 (if suffix | 2258 (if (looking-back suffix) |
2265 (if (looking-back suffix) | 2259 (delete-region (match-beginning 0) (point)) |
2266 (delete-region (match-beginning 0) (point)) | 2260 (error "Local variables entry is missing the suffix")) |
2267 (error "Local variables entry is missing the suffix"))) | |
2268 (forward-line 1)) | 2261 (forward-line 1)) |
2269 (goto-char (point-min)) | 2262 (goto-char (point-min)) |
2270 | 2263 |
2271 (while (not (eobp)) | 2264 (while (not (eobp)) |
2272 ;; Find the variable name; strip whitespace. | 2265 ;; Find the variable name; strip whitespace. |