diff options
| author | Alan Mackenzie | 2016-08-19 16:03:05 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2016-08-19 16:03:05 +0000 |
| commit | 4a80c8bb276de0fdb1f9ddb8f1c1cf7d57d30918 (patch) | |
| tree | 2f564d769d84ac932263e37a21c267f658fc5412 | |
| parent | 72ef0c8b2ffe13aa3f11534b23613c51f99bb64b (diff) | |
| download | emacs-4a80c8bb276de0fdb1f9ddb8f1c1cf7d57d30918.tar.gz emacs-4a80c8bb276de0fdb1f9ddb8f1c1cf7d57d30918.zip | |
Amend hack-local-variables-prop-line not always to return any mode on line 1.
This fixes bug #24266.
* lisp/files.el (hack-local-variables-prop-line): Change the name of the
parameter mode-only to handle-mode. Change its meaning, such that it being
set to a value non-nil and not t removes any mode parameter from the result
list. Leave its values nil and t with the same meanings they had.
(hack-local-variables): Call hack-local-variables-prop-line appropriately.
| -rw-r--r-- | lisp/files.el | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/lisp/files.el b/lisp/files.el index b93cc79648d..ff39008cdbf 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -3223,16 +3223,21 @@ n -- to ignore the local variables list.") | |||
| 3223 | (defconst hack-local-variable-regexp | 3223 | (defconst hack-local-variable-regexp |
| 3224 | "[ \t]*\\([^][;\"'?()\\ \t\n]+\\)[ \t]*:[ \t]*") | 3224 | "[ \t]*\\([^][;\"'?()\\ \t\n]+\\)[ \t]*:[ \t]*") |
| 3225 | 3225 | ||
| 3226 | (defun hack-local-variables-prop-line (&optional mode-only) | 3226 | (defun hack-local-variables-prop-line (&optional handle-mode) |
| 3227 | "Return local variables specified in the -*- line. | 3227 | "Return local variables specified in the -*- line. |
| 3228 | Returns an alist of elements (VAR . VAL), where VAR is a variable | 3228 | Usually returns an alist of elements (VAR . VAL), where VAR is a |
| 3229 | and VAL is the specified value. Ignores any specification for | 3229 | variable and VAL is the specified value. Ignores any |
| 3230 | `mode:' and `coding:' (which should have already been handled | 3230 | specification for `coding:', and sometimes for `mode' (which |
| 3231 | by `set-auto-mode' and `set-auto-coding', respectively). | 3231 | should have already been handled by `set-auto-coding' and |
| 3232 | Return nil if the -*- line is malformed. | 3232 | `set-auto-mode', respectively). Return nil if the -*- line is |
| 3233 | 3233 | malformed. | |
| 3234 | If MODE-ONLY is non-nil, just returns the symbol specifying the | 3234 | |
| 3235 | mode, if there is one, otherwise nil." | 3235 | If HANDLE-MODE is nil, we return the alist of all the local |
| 3236 | variables in the line except `coding' as described above. If it | ||
| 3237 | is neither nil nor t, we do the same, except that any settings of | ||
| 3238 | `mode' and `coding' are ignored. If HANDLE-MODE is t, we ignore | ||
| 3239 | all settings in the line except for `mode', which \(if present) we | ||
| 3240 | return as the symbol specifying the mode." | ||
| 3236 | (catch 'malformed-line | 3241 | (catch 'malformed-line |
| 3237 | (save-excursion | 3242 | (save-excursion |
| 3238 | (goto-char (point-min)) | 3243 | (goto-char (point-min)) |
| @@ -3242,14 +3247,14 @@ mode, if there is one, otherwise nil." | |||
| 3242 | nil) | 3247 | nil) |
| 3243 | ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") | 3248 | ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") |
| 3244 | ;; Simple form: "-*- MODENAME -*-". | 3249 | ;; Simple form: "-*- MODENAME -*-". |
| 3245 | (if mode-only | 3250 | (if (memq handle-mode '(nil t)) |
| 3246 | (intern (concat (match-string 1) "-mode")))) | 3251 | (intern (concat (match-string 1) "-mode")))) |
| 3247 | (t | 3252 | (t |
| 3248 | ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' | 3253 | ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' |
| 3249 | ;; (last ";" is optional). | 3254 | ;; (last ";" is optional). |
| 3250 | ;; If MODE-ONLY, just check for `mode'. | 3255 | ;; If HANDLE-MODE is t, just check for `mode'. |
| 3251 | ;; Otherwise, parse the -*- line into the RESULT alist. | 3256 | ;; Otherwise, parse the -*- line into the RESULT alist. |
| 3252 | (while (not (or (and mode-only result) | 3257 | (while (not (or (and (eq handle-mode t) result) |
| 3253 | (>= (point) end))) | 3258 | (>= (point) end))) |
| 3254 | (unless (looking-at hack-local-variable-regexp) | 3259 | (unless (looking-at hack-local-variable-regexp) |
| 3255 | (message "Malformed mode-line: %S" | 3260 | (message "Malformed mode-line: %S" |
| @@ -3270,19 +3275,24 @@ mode, if there is one, otherwise nil." | |||
| 3270 | ;; That is inconsistent, but we're stuck with it. | 3275 | ;; That is inconsistent, but we're stuck with it. |
| 3271 | ;; The same can be said for `coding' in set-auto-coding. | 3276 | ;; The same can be said for `coding' in set-auto-coding. |
| 3272 | (keyname (downcase (symbol-name key)))) | 3277 | (keyname (downcase (symbol-name key)))) |
| 3273 | (if mode-only | 3278 | (cond |
| 3274 | (and (equal keyname "mode") | 3279 | ((eq handle-mode t) |
| 3275 | (setq result | 3280 | (and (equal keyname "mode") |
| 3276 | (intern (concat (downcase (symbol-name val)) | 3281 | (setq result |
| 3277 | "-mode")))) | 3282 | (intern (concat (downcase (symbol-name val)) |
| 3278 | (or (equal keyname "coding") | 3283 | "-mode"))))) |
| 3279 | (condition-case nil | 3284 | ((equal keyname "coding")) |
| 3280 | (push (cons (cond ((eq key 'eval) 'eval) | 3285 | (t |
| 3281 | ;; Downcase "Mode:". | 3286 | (when (or (not handle-mode) |
| 3282 | ((equal keyname "mode") 'mode) | 3287 | (not (equal keyname "mode"))) |
| 3283 | (t (indirect-variable key))) | 3288 | (condition-case nil |
| 3284 | val) result) | 3289 | (push (cons (cond ((eq key 'eval) 'eval) |
| 3285 | (error nil)))) | 3290 | ;; Downcase "Mode:". |
| 3291 | ((equal keyname "mode") 'mode) | ||
| 3292 | (t (indirect-variable key))) | ||
| 3293 | val) | ||
| 3294 | result) | ||
| 3295 | (error nil))))) | ||
| 3286 | (skip-chars-forward " \t;"))) | 3296 | (skip-chars-forward " \t;"))) |
| 3287 | result)))))) | 3297 | result)))))) |
| 3288 | 3298 | ||
| @@ -3393,7 +3403,7 @@ local variables, but directory-local variables may still be applied." | |||
| 3393 | ;; If HANDLE-MODE is t, and the prop line specifies a | 3403 | ;; If HANDLE-MODE is t, and the prop line specifies a |
| 3394 | ;; mode, then we're done, and have no need to scan further. | 3404 | ;; mode, then we're done, and have no need to scan further. |
| 3395 | (and (setq result (hack-local-variables-prop-line | 3405 | (and (setq result (hack-local-variables-prop-line |
| 3396 | (eq handle-mode t))) | 3406 | handle-mode)) |
| 3397 | (eq handle-mode t))) | 3407 | (eq handle-mode t))) |
| 3398 | ;; Look for "Local variables:" line in last page. | 3408 | ;; Look for "Local variables:" line in last page. |
| 3399 | (save-excursion | 3409 | (save-excursion |