# HG changeset patch # User Stefan Monnier # Date 1104689292 0 # Node ID 8a9e4a779eb81f569991aea7310c96034c04b679 # Parent aca1aaa26a779eba4100c5a51cf14204c2807da0 (hack-local-variables): Fix last change. diff -r aca1aaa26a77 -r 8a9e4a779eb8 lisp/ChangeLog --- a/lisp/ChangeLog Sun Jan 02 17:22:06 2005 +0000 +++ b/lisp/ChangeLog Sun Jan 02 18:08:12 2005 +0000 @@ -1,3 +1,7 @@ +2005-01-02 Stefan + + * files.el (hack-local-variables): Fix last change. + 2005-01-02 Jay Belanger * calc/calc-yank.el (calc-edit-top): New variable. diff -r aca1aaa26a77 -r 8a9e4a779eb8 lisp/files.el --- a/lisp/files.el Sun Jan 02 17:22:06 2005 +0000 +++ b/lisp/files.el Sun Jan 02 18:08:12 2005 +0000 @@ -2202,86 +2202,86 @@ (save-excursion (goto-char (point-max)) (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) - (if (let ((case-fold-search t)) - (and (search-forward "Local Variables:" nil t) - (or (eq enable-local-variables t) - mode-only - (and enable-local-variables - (save-window-excursion - (switch-to-buffer (current-buffer)) - (save-excursion - (beginning-of-line) - (set-window-start (selected-window) (point))) - (y-or-n-p (format "Set local variables as specified at end of %s? " - (if buffer-file-name - (file-name-nondirectory - buffer-file-name) - (concat "buffer " - (buffer-name)))))))))) - (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 prefix "[ \t]*End:[ \t]*" suffix) - nil t)) - (error "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)) - - (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 (read str)) - val) - ;; Read the variable value. - (skip-chars-forward "^:") - (forward-char 1) - (setq val (read (current-buffer))) - (if mode-only - (if (eq var 'mode) - (setq mode-specified t)) - ;; Set the variable. "Variables" mode and eval are funny. - (with-current-buffer thisbuf - (hack-one-local-variable var val)))) - (forward-line 1))))))) + (when (let ((case-fold-search t)) + (and (search-forward "Local Variables:" nil t) + (or (eq enable-local-variables t) + mode-only + (and enable-local-variables + (save-window-excursion + (switch-to-buffer (current-buffer)) + (save-excursion + (beginning-of-line) + (set-window-start (selected-window) (point))) + (y-or-n-p (format "Set local variables as specified at end of %s? " + (if buffer-file-name + (file-name-nondirectory + buffer-file-name) + (concat "buffer " + (buffer-name)))))))))) + (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 prefix "[ \t]*End:[ \t]*" suffix) + nil t)) + (error "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)) + + (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 (read str)) + val) + ;; Read the variable value. + (skip-chars-forward "^:") + (forward-char 1) + (setq val (read (current-buffer))) + (if mode-only + (if (eq var 'mode) + (setq mode-specified t)) + ;; Set the variable. "Variables" mode and eval are funny. + (with-current-buffer thisbuf + (hack-one-local-variable var val)))) + (forward-line 1))))))) (unless mode-only (run-hooks 'hack-local-variables-hook)) mode-specified))