diff options
| author | Glenn Morris | 2011-05-21 15:33:12 -0700 |
|---|---|---|
| committer | Glenn Morris | 2011-05-21 15:33:12 -0700 |
| commit | 7e4ccca3454e6ef6ccaf14827f274647b2bf56e1 (patch) | |
| tree | 9d0d19f7a61e2d74b166e38b879bebdce4bf9032 | |
| parent | 2a35386df43842ade192a4f5fea5a412cf0d8d29 (diff) | |
| download | emacs-7e4ccca3454e6ef6ccaf14827f274647b2bf56e1.tar.gz emacs-7e4ccca3454e6ef6ccaf14827f274647b2bf56e1.zip | |
Small files.el hack-local changes for mode-only case.
* lisp/files.el (hack-local-variables-prop-line, hack-local-variables):
If only interested in the mode, don't bother doing the other stuff.
| -rw-r--r-- | lisp/ChangeLog | 3 | ||||
| -rw-r--r-- | lisp/files.el | 174 |
2 files changed, 94 insertions, 83 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3ea95bda944..a5af20b109b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | 2011-05-21 Glenn Morris <rgm@gnu.org> | 1 | 2011-05-21 Glenn Morris <rgm@gnu.org> |
| 2 | 2 | ||
| 3 | * files.el (hack-local-variables-prop-line, hack-local-variables): | ||
| 4 | If only interested in the mode, don't bother doing the other stuff. | ||
| 5 | |||
| 3 | * image-mode.el (image-after-revert-hook): | 6 | * image-mode.el (image-after-revert-hook): |
| 4 | Redraw all frames on which the image is visible. (Bug#8567) | 7 | Redraw all frames on which the image is visible. (Bug#8567) |
| 5 | 8 | ||
diff --git a/lisp/files.el b/lisp/files.el index 200b9b1d303..e6f0d93299c 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -3055,7 +3055,9 @@ and VAL is the specified value." | |||
| 3055 | (t | 3055 | (t |
| 3056 | ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' | 3056 | ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' |
| 3057 | ;; (last ";" is optional). | 3057 | ;; (last ";" is optional). |
| 3058 | (while (< (point) end) | 3058 | (while (and (< (point) end) |
| 3059 | (or (not mode-only) | ||
| 3060 | (not mode-specified))) | ||
| 3059 | (or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*") | 3061 | (or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*") |
| 3060 | (error "Malformed -*- line")) | 3062 | (error "Malformed -*- line")) |
| 3061 | (goto-char (match-end 0)) | 3063 | (goto-char (match-end 0)) |
| @@ -3074,6 +3076,7 @@ and VAL is the specified value." | |||
| 3074 | ;; The same can be said for `coding' in set-auto-coding. | 3076 | ;; The same can be said for `coding' in set-auto-coding. |
| 3075 | (or (and (equal (downcase (symbol-name key)) "mode") | 3077 | (or (and (equal (downcase (symbol-name key)) "mode") |
| 3076 | (setq mode-specified t)) | 3078 | (setq mode-specified t)) |
| 3079 | mode-only | ||
| 3077 | (equal (downcase (symbol-name key)) "coding") | 3080 | (equal (downcase (symbol-name key)) "coding") |
| 3078 | (condition-case nil | 3081 | (condition-case nil |
| 3079 | (push (cons (if (eq key 'eval) | 3082 | (push (cons (if (eq key 'eval) |
| @@ -3154,88 +3157,93 @@ is specified, returning t if it is specified." | |||
| 3154 | (report-errors "Directory-local variables error: %s" | 3157 | (report-errors "Directory-local variables error: %s" |
| 3155 | (hack-dir-local-variables))) | 3158 | (hack-dir-local-variables))) |
| 3156 | (when (or mode-only enable-local-variables) | 3159 | (when (or mode-only enable-local-variables) |
| 3157 | (setq result (hack-local-variables-prop-line mode-only)) | 3160 | ;; If MODE-ONLY is non-nil, and the prop line specifies a mode, |
| 3158 | ;; Look for "Local variables:" line in last page. | 3161 | ;; then we're done, and have no need to scan further. |
| 3159 | (save-excursion | 3162 | (unless (and (setq result (hack-local-variables-prop-line mode-only)) |
| 3160 | (goto-char (point-max)) | 3163 | mode-only) |
| 3161 | (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) | 3164 | ;; Look for "Local variables:" line in last page. |
| 3162 | 'move) | 3165 | (save-excursion |
| 3163 | (when (let ((case-fold-search t)) | 3166 | (goto-char (point-max)) |
| 3164 | (search-forward "Local Variables:" nil t)) | 3167 | (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) |
| 3165 | (skip-chars-forward " \t") | 3168 | 'move) |
| 3166 | ;; suffix is what comes after "local variables:" in its line. | 3169 | (when (let ((case-fold-search t)) |
| 3167 | ;; prefix is what comes before "local variables:" in its line. | 3170 | (search-forward "Local Variables:" nil t)) |
| 3168 | (let ((suffix | 3171 | (skip-chars-forward " \t") |
| 3169 | (concat | 3172 | ;; suffix is what comes after "local variables:" in its line. |
| 3170 | (regexp-quote (buffer-substring (point) | 3173 | ;; prefix is what comes before "local variables:" in its line. |
| 3171 | (line-end-position))) | 3174 | (let ((suffix |
| 3172 | "$")) | 3175 | (concat |
| 3173 | (prefix | 3176 | (regexp-quote (buffer-substring (point) |
| 3174 | (concat "^" (regexp-quote | 3177 | (line-end-position))) |
| 3175 | (buffer-substring (line-beginning-position) | 3178 | "$")) |
| 3176 | (match-beginning 0))))) | 3179 | (prefix |
| 3177 | beg) | 3180 | (concat "^" (regexp-quote |
| 3178 | 3181 | (buffer-substring (line-beginning-position) | |
| 3179 | (forward-line 1) | 3182 | (match-beginning 0))))) |
| 3180 | (let ((startpos (point)) | 3183 | beg) |
| 3181 | endpos | 3184 | |
| 3182 | (thisbuf (current-buffer))) | 3185 | (forward-line 1) |
| 3183 | (save-excursion | 3186 | (let ((startpos (point)) |
| 3184 | (unless (let ((case-fold-search t)) | 3187 | endpos |
| 3185 | (re-search-forward | 3188 | (thisbuf (current-buffer))) |
| 3186 | (concat prefix "[ \t]*End:[ \t]*" suffix) | 3189 | (save-excursion |
| 3187 | nil t)) | 3190 | (unless (let ((case-fold-search t)) |
| 3188 | ;; This used to be an error, but really all it means is | 3191 | (re-search-forward |
| 3189 | ;; that this may simply not be a local-variables section, | 3192 | (concat prefix "[ \t]*End:[ \t]*" suffix) |
| 3190 | ;; so just ignore it. | 3193 | nil t)) |
| 3191 | (message "Local variables list is not properly terminated")) | 3194 | ;; This used to be an error, but really all it means is |
| 3192 | (beginning-of-line) | 3195 | ;; that this may simply not be a local-variables section, |
| 3193 | (setq endpos (point))) | 3196 | ;; so just ignore it. |
| 3194 | 3197 | (message "Local variables list is not properly terminated")) | |
| 3195 | (with-temp-buffer | 3198 | (beginning-of-line) |
| 3196 | (insert-buffer-substring thisbuf startpos endpos) | 3199 | (setq endpos (point))) |
| 3197 | (goto-char (point-min)) | 3200 | |
| 3198 | (subst-char-in-region (point) (point-max) ?\^m ?\n) | 3201 | (with-temp-buffer |
| 3199 | (while (not (eobp)) | 3202 | (insert-buffer-substring thisbuf startpos endpos) |
| 3200 | ;; Discard the prefix. | 3203 | (goto-char (point-min)) |
| 3201 | (if (looking-at prefix) | 3204 | (subst-char-in-region (point) (point-max) ?\^m ?\n) |
| 3202 | (delete-region (point) (match-end 0)) | 3205 | (while (not (eobp)) |
| 3203 | (error "Local variables entry is missing the prefix")) | 3206 | ;; Discard the prefix. |
| 3204 | (end-of-line) | 3207 | (if (looking-at prefix) |
| 3205 | ;; Discard the suffix. | 3208 | (delete-region (point) (match-end 0)) |
| 3206 | (if (looking-back suffix) | 3209 | (error "Local variables entry is missing the prefix")) |
| 3207 | (delete-region (match-beginning 0) (point)) | 3210 | (end-of-line) |
| 3208 | (error "Local variables entry is missing the suffix")) | 3211 | ;; Discard the suffix. |
| 3209 | (forward-line 1)) | 3212 | (if (looking-back suffix) |
| 3210 | (goto-char (point-min)) | 3213 | (delete-region (match-beginning 0) (point)) |
| 3211 | 3214 | (error "Local variables entry is missing the suffix")) | |
| 3212 | (while (not (eobp)) | 3215 | (forward-line 1)) |
| 3213 | ;; Find the variable name; strip whitespace. | 3216 | (goto-char (point-min)) |
| 3214 | (skip-chars-forward " \t") | 3217 | |
| 3215 | (setq beg (point)) | 3218 | (while (and (not (eobp)) |
| 3216 | (skip-chars-forward "^:\n") | 3219 | (or (not mode-only) |
| 3217 | (if (eolp) (error "Missing colon in local variables entry")) | 3220 | (not result))) |
| 3218 | (skip-chars-backward " \t") | 3221 | ;; Find the variable name; strip whitespace. |
| 3219 | (let* ((str (buffer-substring beg (point))) | 3222 | (skip-chars-forward " \t") |
| 3220 | (var (let ((read-circle nil)) | 3223 | (setq beg (point)) |
| 3221 | (read str))) | 3224 | (skip-chars-forward "^:\n") |
| 3222 | val) | 3225 | (if (eolp) (error "Missing colon in local variables entry")) |
| 3223 | ;; Read the variable value. | 3226 | (skip-chars-backward " \t") |
| 3224 | (skip-chars-forward "^:") | 3227 | (let* ((str (buffer-substring beg (point))) |
| 3225 | (forward-char 1) | 3228 | (var (let ((read-circle nil)) |
| 3226 | (let ((read-circle nil)) | 3229 | (read str))) |
| 3227 | (setq val (read (current-buffer)))) | 3230 | val) |
| 3228 | (if mode-only | 3231 | ;; Read the variable value. |
| 3229 | (if (eq var 'mode) | 3232 | (skip-chars-forward "^:") |
| 3230 | (setq result t)) | 3233 | (forward-char 1) |
| 3231 | (unless (eq var 'coding) | 3234 | (let ((read-circle nil)) |
| 3232 | (condition-case nil | 3235 | (setq val (read (current-buffer)))) |
| 3233 | (push (cons (if (eq var 'eval) | 3236 | (if mode-only |
| 3234 | 'eval | 3237 | (if (eq var 'mode) |
| 3235 | (indirect-variable var)) | 3238 | (setq result t)) |
| 3236 | val) result) | 3239 | (unless (eq var 'coding) |
| 3237 | (error nil))))) | 3240 | (condition-case nil |
| 3238 | (forward-line 1)))))))) | 3241 | (push (cons (if (eq var 'eval) |
| 3242 | 'eval | ||
| 3243 | (indirect-variable var)) | ||
| 3244 | val) result) | ||
| 3245 | (error nil))))) | ||
| 3246 | (forward-line 1))))))))) | ||
| 3239 | ;; Now we've read all the local variables. | 3247 | ;; Now we've read all the local variables. |
| 3240 | ;; If MODE-ONLY is non-nil, return whether the mode was specified. | 3248 | ;; If MODE-ONLY is non-nil, return whether the mode was specified. |
| 3241 | (cond (mode-only result) | 3249 | (cond (mode-only result) |