diff options
| author | Glenn Morris | 2012-01-20 16:41:05 -0800 |
|---|---|---|
| committer | Glenn Morris | 2012-01-20 16:41:05 -0800 |
| commit | 7b447e9bda80e5de478922771a62c2b3a8f9b2aa (patch) | |
| tree | a37394ac2c36ea1d6e31f1b2dc954c3e8bc7e9d3 | |
| parent | a2f0118ce5c18ea397c9571e401231b2fca7aa61 (diff) | |
| download | emacs-7b447e9bda80e5de478922771a62c2b3a8f9b2aa.tar.gz emacs-7b447e9bda80e5de478922771a62c2b3a8f9b2aa.zip | |
File-local variable fixes.
* lisp/files.el (local-enable-local-variables): Doc fix.
(inhibit-local-variables-regexps): Rename from inhibit-first-line-modes-regexps.
Keep old name as obsolete alias. Doc fix.
Add some extensions from auto-coding-alist.
(inhibit-local-variables-suffixes):
Rename from inhibit-first-line-modes-suffixes. Doc fix.
(inhibit-local-variables-p): New function, extracted from set-auto-mode-1.
(set-auto-mode): Doc fix. Respect inhibit-local-variables-regexps.
(set-auto-mode-1): Doc fix. Use inhibit-local-variables-p.
(hack-local-variables): Doc fix.
Make the mode-only case respect enable-local-variables and friends.
Respect inhibit-local-variables-regexps for file-locals,
but not for directory-locals.
(set-visited-file-name): Take account of inhibit-local-variables-regexps.
Whether it applies may change as the file name is changed.
* lisp/jka-cmpr-hook.el (jka-compr-install):
* lisp/jka-compr.el (jka-compr-uninstall):
Update for inhibit-first-line-modes-suffixes name change.
* etc/NEWS: Mention this change.
Fixes: debbugs:10506
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/ChangeLog | 23 | ||||
| -rw-r--r-- | lisp/files.el | 306 | ||||
| -rw-r--r-- | lisp/jka-cmpr-hook.el | 12 | ||||
| -rw-r--r-- | lisp/jka-compr.el | 9 |
5 files changed, 234 insertions, 124 deletions
| @@ -369,6 +369,14 @@ turn on `whitespace-mode' for *vc-diff* buffers. Modes should call | |||
| 369 | *** Using "mode: MINOR-MODE" to enable a minor mode is deprecated. | 369 | *** Using "mode: MINOR-MODE" to enable a minor mode is deprecated. |
| 370 | Instead, use "eval: (minor-mode 1)". | 370 | Instead, use "eval: (minor-mode 1)". |
| 371 | 371 | ||
| 372 | FIXME: inhibit-first-line-modes-regexps was not mentioned in lispref, | ||
| 373 | but this probably should be. | ||
| 374 | *** The variable `inhibit-first-line-modes-regexps' has been renamed | ||
| 375 | to `inhibit-local-variables-regexps'. As the name suggests, it now | ||
| 376 | applies to ALL file local variables, not just -*- mode ones. | ||
| 377 | The associated `inhibit-first-line-modes-suffixes' has been renamed | ||
| 378 | in the corresponding way. | ||
| 379 | |||
| 372 | +++ | 380 | +++ |
| 373 | ** The variable `focus-follows-mouse' now always defaults to nil. | 381 | ** The variable `focus-follows-mouse' now always defaults to nil. |
| 374 | 382 | ||
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 71211ca9af9..248de3429fa 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,26 @@ | |||
| 1 | 2012-01-21 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * files.el (local-enable-local-variables): Doc fix. | ||
| 4 | (inhibit-local-variables-regexps): Rename from | ||
| 5 | inhibit-first-line-modes-regexps. Keep old name as obsolete alias. | ||
| 6 | Doc fix. Add some extensions from auto-coding-alist. | ||
| 7 | (inhibit-local-variables-suffixes): | ||
| 8 | Rename from inhibit-first-line-modes-suffixes. Doc fix. | ||
| 9 | (inhibit-local-variables-p): | ||
| 10 | New function, extracted from set-auto-mode-1. | ||
| 11 | (set-auto-mode): Doc fix. Respect inhibit-local-variables-regexps. | ||
| 12 | (set-auto-mode-1): Doc fix. Use inhibit-local-variables-p. | ||
| 13 | (hack-local-variables): Doc fix. Make the mode-only case | ||
| 14 | respect enable-local-variables and friends. | ||
| 15 | Respect inhibit-local-variables-regexps for file-locals, but | ||
| 16 | not for directory-locals. | ||
| 17 | (set-visited-file-name): | ||
| 18 | Take account of inhibit-local-variables-regexps. | ||
| 19 | Whether it applies may change as the file name is changed. | ||
| 20 | * jka-cmpr-hook.el (jka-compr-install): | ||
| 21 | * jka-compr.el (jka-compr-uninstall): | ||
| 22 | Update for inhibit-first-line-modes-suffixes name change. | ||
| 23 | |||
| 1 | 2012-01-20 Martin Rudalics <rudalics@gmx.at> | 24 | 2012-01-20 Martin Rudalics <rudalics@gmx.at> |
| 2 | 25 | ||
| 3 | * help-macro.el (make-help-screen): Temporarily restore original | 26 | * help-macro.el (make-help-screen): Temporarily restore original |
diff --git a/lisp/files.el b/lisp/files.el index 6056a70d4a1..7a72775ac3f 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -510,14 +510,36 @@ and ignores this variable." | |||
| 510 | (other :tag "Query" other)) | 510 | (other :tag "Query" other)) |
| 511 | :group 'find-file) | 511 | :group 'find-file) |
| 512 | 512 | ||
| 513 | ;; This is an odd variable IMO. | ||
| 514 | ;; You might wonder why it is needed, when we could just do: | ||
| 515 | ;; (set (make-local-variable 'enable-local-variables) nil) | ||
| 516 | ;; These two are not precisely the same. | ||
| 517 | ;; Setting this variable does not cause -*- mode settings to be | ||
| 518 | ;; ignored, whereas setting enable-local-variables does. | ||
| 519 | ;; Only three places in Emacs use this variable: tar and arc modes, | ||
| 520 | ;; and rmail. The first two don't need it. They already use | ||
| 521 | ;; inhibit-local-variables-regexps, which is probably enough, and | ||
| 522 | ;; could also just set enable-local-variables locally to nil. | ||
| 523 | ;; Them setting it has the side-effect that dir-locals cannot apply to | ||
| 524 | ;; eg tar files (?). FIXME Is this appropriate? | ||
| 525 | ;; AFAICS, rmail is the only thing that needs this, and the only | ||
| 526 | ;; reason it uses it is for BABYL files (which are obsolete). | ||
| 527 | ;; These contain "-*- rmail -*-" in the first line, which rmail wants | ||
| 528 | ;; to respect, so that find-file on a BABYL file will switch to | ||
| 529 | ;; rmail-mode automatically (this is nice, but hardly essential, | ||
| 530 | ;; since most people are used to explicitly running a command to | ||
| 531 | ;; access their mail; M-x gnus etc). Rmail files may happen to | ||
| 532 | ;; contain Local Variables sections in messages, which Rmail wants to | ||
| 533 | ;; ignore. So AFAICS the only reason this variable exists is for a | ||
| 534 | ;; minor convenience feature for handling of an obsolete Rmail file format. | ||
| 513 | (defvar local-enable-local-variables t | 535 | (defvar local-enable-local-variables t |
| 514 | "Like `enable-local-variables' but meant for buffer-local bindings. | 536 | "Like `enable-local-variables' but meant for buffer-local bindings. |
| 515 | The meaningful values are nil and non-nil. The default is non-nil. | 537 | The meaningful values are nil and non-nil. The default is non-nil. |
| 516 | If a major mode sets this to nil, buffer-locally, then any local | 538 | If a major mode sets this to nil, buffer-locally, then any local |
| 517 | variables list in the file will be ignored. | 539 | variables list in a file visited in that mode will be ignored. |
| 518 | 540 | ||
| 519 | This variable does not affect the use of major modes | 541 | This variable does not affect the use of major modes specified |
| 520 | specified in a -*- line.") | 542 | in a -*- line.") |
| 521 | 543 | ||
| 522 | (defcustom enable-local-eval 'maybe | 544 | (defcustom enable-local-eval 'maybe |
| 523 | "Control processing of the \"variable\" `eval' in a file's local variables. | 545 | "Control processing of the \"variable\" `eval' in a file's local variables. |
| @@ -2475,17 +2497,55 @@ of a script, mode MODE is enabled. | |||
| 2475 | 2497 | ||
| 2476 | See also `auto-mode-alist'.") | 2498 | See also `auto-mode-alist'.") |
| 2477 | 2499 | ||
| 2478 | (defvar inhibit-first-line-modes-regexps | 2500 | (define-obsolete-variable-alias 'inhibit-first-line-modes-regexps |
| 2479 | (mapcar 'purecopy '("\\.tar\\'" "\\.tgz\\'" "\\.tiff?\\'" | 2501 | 'inhibit-file-local-variables-regexps "24.1") |
| 2480 | "\\.gif\\'" "\\.png\\'" "\\.jpe?g\\'")) | 2502 | |
| 2481 | "List of regexps; if one matches a file name, don't look for `-*-'. | 2503 | ;; TODO really this should be a list of modes (eg tar-mode), not regexps, |
| 2482 | See also `inhibit-first-line-modes-suffixes'.") | 2504 | ;; because we are duplicating info from auto-mode-alist. |
| 2483 | 2505 | ;; TODO many elements of this list are also in auto-coding-alist. | |
| 2484 | (defvar inhibit-first-line-modes-suffixes nil | 2506 | (defvar inhibit-local-variables-regexps |
| 2485 | "List of regexps for what to ignore, for `inhibit-first-line-modes-regexps'. | 2507 | (mapcar 'purecopy '("\\.tar\\'" "\\.t[bg]z\\'" |
| 2486 | When checking `inhibit-first-line-modes-regexps', we first discard | 2508 | "\\.arc\\'" "\\.zip\\'" "\\.lzh\\'" "\\.lha\\'" |
| 2509 | "\\.zoo\\'" "\\.[jew]ar\\'" "\\.xpi\\'" "\\.rar\\'" | ||
| 2510 | "\\.7z\\'" | ||
| 2511 | "\\.sx[dmicw]\\'" "\\.odt\\'" | ||
| 2512 | "\\.tiff?\\'" "\\.gif\\'" "\\.png\\'" "\\.jpe?g\\'")) | ||
| 2513 | "List of regexps matching file names in which to ignore local variables. | ||
| 2514 | This includes `-*-' lines as well as trailing \"Local Variables\" sections. | ||
| 2515 | Files matching this list are typically binary file formats. | ||
| 2516 | They may happen to contain sequences that look like local variable | ||
| 2517 | specifications, but are not really, or they may be containers for | ||
| 2518 | member files with their own local variable sections, which are | ||
| 2519 | not appropriate for the containing file. | ||
| 2520 | See also `inhibit-local-variables-suffixes'.") | ||
| 2521 | |||
| 2522 | (define-obsolete-variable-alias 'inhibit-first-line-modes-suffixes | ||
| 2523 | 'inhibit-local-variables-suffixes "24.1") | ||
| 2524 | |||
| 2525 | (defvar inhibit-local-variables-suffixes nil | ||
| 2526 | "List of regexps matching suffixes to remove from file names. | ||
| 2527 | When checking `inhibit-local-variables-regexps', we first discard | ||
| 2487 | from the end of the file name anything that matches one of these regexps.") | 2528 | from the end of the file name anything that matches one of these regexps.") |
| 2488 | 2529 | ||
| 2530 | ;; TODO explicitly add case-fold-search t? | ||
| 2531 | (defun inhibit-local-variables-p () | ||
| 2532 | "Return non-nil if file local variables should be ignored. | ||
| 2533 | This checks the file (or buffer) name against `inhibit-local-variables-regexps' | ||
| 2534 | and `inhibit-local-variables-suffixes'." | ||
| 2535 | (let ((temp inhibit-local-variables-regexps) | ||
| 2536 | (name (if buffer-file-name | ||
| 2537 | (file-name-sans-versions buffer-file-name) | ||
| 2538 | (buffer-name)))) | ||
| 2539 | (while (let ((sufs inhibit-local-variables-suffixes)) | ||
| 2540 | (while (and sufs (not (string-match (car sufs) name))) | ||
| 2541 | (setq sufs (cdr sufs))) | ||
| 2542 | sufs) | ||
| 2543 | (setq name (substring name 0 (match-beginning 0)))) | ||
| 2544 | (while (and temp | ||
| 2545 | (not (string-match (car temp) name))) | ||
| 2546 | (setq temp (cdr temp))) | ||
| 2547 | temp)) | ||
| 2548 | |||
| 2489 | (defvar auto-mode-interpreter-regexp | 2549 | (defvar auto-mode-interpreter-regexp |
| 2490 | (purecopy "#![ \t]?\\([^ \t\n]*\ | 2550 | (purecopy "#![ \t]?\\([^ \t\n]*\ |
| 2491 | /bin/env[ \t]\\)?\\([^ \t\n]+\\)") | 2551 | /bin/env[ \t]\\)?\\([^ \t\n]+\\)") |
| @@ -2549,21 +2609,23 @@ Also applies to `magic-fallback-mode-alist'.") | |||
| 2549 | "Select major mode appropriate for current buffer. | 2609 | "Select major mode appropriate for current buffer. |
| 2550 | 2610 | ||
| 2551 | To find the right major mode, this function checks for a -*- mode tag | 2611 | To find the right major mode, this function checks for a -*- mode tag |
| 2552 | \(unless `inhibit-first-line-modes-regexps' says not to), | ||
| 2553 | checks for a `mode:' entry in the Local Variables section of the file, | 2612 | checks for a `mode:' entry in the Local Variables section of the file, |
| 2554 | checks if it uses an interpreter listed in `interpreter-mode-alist', | 2613 | checks if it uses an interpreter listed in `interpreter-mode-alist', |
| 2555 | matches the buffer beginning against `magic-mode-alist', | 2614 | matches the buffer beginning against `magic-mode-alist', |
| 2556 | compares the filename against the entries in `auto-mode-alist', | 2615 | compares the filename against the entries in `auto-mode-alist', |
| 2557 | then matches the buffer beginning against `magic-fallback-mode-alist'. | 2616 | then matches the buffer beginning against `magic-fallback-mode-alist'. |
| 2558 | 2617 | ||
| 2559 | If `enable-local-variables' is nil, this function does not check for | 2618 | If `enable-local-variables' is nil, or if the file name matches |
| 2560 | any mode: tag anywhere in the file. | 2619 | `inhibit-local-variables-regexps', this function does not check |
| 2620 | for any mode: tag anywhere in the file. If `local-enable-local-variables' | ||
| 2621 | is nil, then the only mode: tag that can be relevant is a -*- one. | ||
| 2561 | 2622 | ||
| 2562 | If the optional argument KEEP-MODE-IF-SAME is non-nil, then we | 2623 | If the optional argument KEEP-MODE-IF-SAME is non-nil, then we |
| 2563 | set the major mode only if that would change it. In other words | 2624 | set the major mode only if that would change it. In other words |
| 2564 | we don't actually set it to the same mode the buffer already has." | 2625 | we don't actually set it to the same mode the buffer already has." |
| 2565 | ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- | 2626 | ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- |
| 2566 | (let (end done mode modes) | 2627 | (let ((try-locals (not (inhibit-local-variables-p))) |
| 2628 | end done mode modes) | ||
| 2567 | ;; Once we drop the deprecated feature where mode: is also allowed to | 2629 | ;; Once we drop the deprecated feature where mode: is also allowed to |
| 2568 | ;; specify minor-modes (ie, there can be more than one "mode:"), we can | 2630 | ;; specify minor-modes (ie, there can be more than one "mode:"), we can |
| 2569 | ;; remove this section and just let (hack-local-variables t) handle it. | 2631 | ;; remove this section and just let (hack-local-variables t) handle it. |
| @@ -2571,7 +2633,9 @@ we don't actually set it to the same mode the buffer already has." | |||
| 2571 | (save-excursion | 2633 | (save-excursion |
| 2572 | (goto-char (point-min)) | 2634 | (goto-char (point-min)) |
| 2573 | (skip-chars-forward " \t\n") | 2635 | (skip-chars-forward " \t\n") |
| 2636 | ;; Note by design local-enable-local-variables does not matter here. | ||
| 2574 | (and enable-local-variables | 2637 | (and enable-local-variables |
| 2638 | try-locals | ||
| 2575 | (setq end (set-auto-mode-1)) | 2639 | (setq end (set-auto-mode-1)) |
| 2576 | (if (save-excursion (search-forward ":" end t)) | 2640 | (if (save-excursion (search-forward ":" end t)) |
| 2577 | ;; Find all specifications for the `mode:' variable | 2641 | ;; Find all specifications for the `mode:' variable |
| @@ -2602,8 +2666,12 @@ we don't actually set it to the same mode the buffer already has." | |||
| 2602 | (or (set-auto-mode-0 mode keep-mode-if-same) | 2666 | (or (set-auto-mode-0 mode keep-mode-if-same) |
| 2603 | ;; continuing would call minor modes again, toggling them off | 2667 | ;; continuing would call minor modes again, toggling them off |
| 2604 | (throw 'nop nil)))))) | 2668 | (throw 'nop nil)))))) |
| 2669 | ;; hack-local-variables checks local-enable-local-variables etc, but | ||
| 2670 | ;; we might as well be explicit here for the sake of clarity. | ||
| 2605 | (and (not done) | 2671 | (and (not done) |
| 2606 | enable-local-variables | 2672 | enable-local-variables |
| 2673 | local-enable-local-variables | ||
| 2674 | try-locals | ||
| 2607 | (setq mode (hack-local-variables t)) | 2675 | (setq mode (hack-local-variables t)) |
| 2608 | (not (memq mode modes)) ; already tried and failed | 2676 | (not (memq mode modes)) ; already tried and failed |
| 2609 | (if (not (functionp mode)) | 2677 | (if (not (functionp mode)) |
| @@ -2713,38 +2781,24 @@ same, do nothing and return nil." | |||
| 2713 | (defun set-auto-mode-1 () | 2781 | (defun set-auto-mode-1 () |
| 2714 | "Find the -*- spec in the buffer. | 2782 | "Find the -*- spec in the buffer. |
| 2715 | Call with point at the place to start searching from. | 2783 | Call with point at the place to start searching from. |
| 2716 | If one is found, set point to the beginning | 2784 | If one is found, set point to the beginning and return the position |
| 2717 | and return the position of the end. | 2785 | of the end. Otherwise, return nil; may change point. |
| 2718 | Otherwise, return nil; point may be changed." | 2786 | The variable `inhibit-local-variables-regexps' can cause a -*- spec to |
| 2787 | be ignored; but `enable-local-variables' and `local-enable-local-variables' | ||
| 2788 | have no effect." | ||
| 2719 | (let (beg end) | 2789 | (let (beg end) |
| 2720 | (and | 2790 | (and |
| 2721 | ;; Don't look for -*- if this file name matches any | 2791 | ;; Don't look for -*- if this file name matches any |
| 2722 | ;; of the regexps in inhibit-first-line-modes-regexps. | 2792 | ;; of the regexps in inhibit-local-variables-regexps. |
| 2723 | (let ((temp inhibit-first-line-modes-regexps) | 2793 | (not (inhibit-local-variables-p)) |
| 2724 | (name (if buffer-file-name | ||
| 2725 | (file-name-sans-versions buffer-file-name) | ||
| 2726 | (buffer-name)))) | ||
| 2727 | (while (let ((sufs inhibit-first-line-modes-suffixes)) | ||
| 2728 | (while (and sufs (not (string-match (car sufs) name))) | ||
| 2729 | (setq sufs (cdr sufs))) | ||
| 2730 | sufs) | ||
| 2731 | (setq name (substring name 0 (match-beginning 0)))) | ||
| 2732 | (while (and temp | ||
| 2733 | (not (string-match (car temp) name))) | ||
| 2734 | (setq temp (cdr temp))) | ||
| 2735 | (not temp)) | ||
| 2736 | |||
| 2737 | (search-forward "-*-" (line-end-position | 2794 | (search-forward "-*-" (line-end-position |
| 2738 | ;; If the file begins with "#!" | 2795 | ;; If the file begins with "#!" (exec |
| 2739 | ;; (exec interpreter magic), look | 2796 | ;; interpreter magic), look for mode frobs |
| 2740 | ;; for mode frobs in the first two | 2797 | ;; in the first two lines. You cannot |
| 2741 | ;; lines. You cannot necessarily | 2798 | ;; necessarily put them in the first line |
| 2742 | ;; put them in the first line of | 2799 | ;; of such a file without screwing up the |
| 2743 | ;; such a file without screwing up | 2800 | ;; interpreter invocation. The same holds |
| 2744 | ;; the interpreter invocation. | 2801 | ;; for '\" in man pages (preprocessor |
| 2745 | ;; The same holds for | ||
| 2746 | ;; '\" | ||
| 2747 | ;; in man pages (preprocessor | ||
| 2748 | ;; magic for the `man' program). | 2802 | ;; magic for the `man' program). |
| 2749 | (and (looking-at "^\\(#!\\|'\\\\\"\\)") 2)) t) | 2803 | (and (looking-at "^\\(#!\\|'\\\\\"\\)") 2)) t) |
| 2750 | (progn | 2804 | (progn |
| @@ -3089,19 +3143,41 @@ Uses `hack-local-variables-apply' to apply the variables. | |||
| 3089 | If MODE-ONLY is non-nil, all we do is check whether a \"mode:\" | 3143 | If MODE-ONLY is non-nil, all we do is check whether a \"mode:\" |
| 3090 | is specified, and return the corresponding mode symbol, or nil. | 3144 | is specified, and return the corresponding mode symbol, or nil. |
| 3091 | In this case, we try to ignore minor-modes, and only return a | 3145 | In this case, we try to ignore minor-modes, and only return a |
| 3092 | major-mode." | 3146 | major-mode. |
| 3147 | |||
| 3148 | If `enable-local-variables' or `local-enable-local-variables' is nil, | ||
| 3149 | this function does nothing. If `inhibit-local-variables-regexps' | ||
| 3150 | applies to the file in question, the file is not scanned for | ||
| 3151 | local variables, but directory-local variables may still be applied." | ||
| 3152 | ;; We don't let inhibit-local-variables-p influence the value of | ||
| 3153 | ;; enable-local-variables, because then it would affect dir-local | ||
| 3154 | ;; variables. We don't want to search eg tar files for file local | ||
| 3155 | ;; variable sections, but there is no reason dir-locals cannot apply | ||
| 3156 | ;; to them. The real meaning of inhibit-local-variables-p is "do | ||
| 3157 | ;; not scan this file for local variables". | ||
| 3093 | (let ((enable-local-variables | 3158 | (let ((enable-local-variables |
| 3094 | (and local-enable-local-variables enable-local-variables)) | 3159 | (and local-enable-local-variables enable-local-variables)) |
| 3095 | result) | 3160 | result) |
| 3096 | (unless mode-only | 3161 | (unless mode-only |
| 3097 | (setq file-local-variables-alist nil) | 3162 | (setq file-local-variables-alist nil) |
| 3098 | (report-errors "Directory-local variables error: %s" | 3163 | (report-errors "Directory-local variables error: %s" |
| 3164 | ;; Note this is a no-op if enable-local-variables is nil. | ||
| 3099 | (hack-dir-local-variables))) | 3165 | (hack-dir-local-variables))) |
| 3100 | (when (or mode-only enable-local-variables) | 3166 | ;; This entire function is basically a no-op if enable-local-variables |
| 3101 | ;; If MODE-ONLY is non-nil, and the prop line specifies a mode, | 3167 | ;; is nil. All it does is set file-local-variables-alist to nil. |
| 3102 | ;; then we're done, and have no need to scan further. | 3168 | (when enable-local-variables |
| 3103 | (unless (and (setq result (hack-local-variables-prop-line mode-only)) | 3169 | ;; This part used to ignore enable-local-variables when mode-only |
| 3104 | mode-only) | 3170 | ;; was non-nil. That was inappropriate, eg consider the |
| 3171 | ;; (artificial) example of: | ||
| 3172 | ;; (setq local-enable-local-variables nil) | ||
| 3173 | ;; Open a file foo.txt that contains "mode: sh". | ||
| 3174 | ;; It correctly opens in text-mode. | ||
| 3175 | ;; M-x set-visited-file name foo.c, and it incorrectly stays in text-mode. | ||
| 3176 | (unless (or (inhibit-local-variables-p) | ||
| 3177 | ;; If MODE-ONLY is non-nil, and the prop line specifies a | ||
| 3178 | ;; mode, then we're done, and have no need to scan further. | ||
| 3179 | (and (setq result (hack-local-variables-prop-line mode-only)) | ||
| 3180 | mode-only)) | ||
| 3105 | ;; Look for "Local variables:" line in last page. | 3181 | ;; Look for "Local variables:" line in last page. |
| 3106 | (save-excursion | 3182 | (save-excursion |
| 3107 | (goto-char (point-max)) | 3183 | (goto-char (point-max)) |
| @@ -3191,14 +3267,13 @@ major-mode." | |||
| 3191 | (indirect-variable var)) | 3267 | (indirect-variable var)) |
| 3192 | val) result) | 3268 | val) result) |
| 3193 | (error nil))))) | 3269 | (error nil))))) |
| 3194 | (forward-line 1))))))))) | 3270 | (forward-line 1)))))))) |
| 3195 | ;; Now we've read all the local variables. | 3271 | ;; Now we've read all the local variables. |
| 3196 | ;; If MODE-ONLY is non-nil, return whether the mode was specified. | 3272 | ;; If MODE-ONLY is non-nil, return whether the mode was specified. |
| 3197 | (cond (mode-only result) | 3273 | (if mode-only result |
| 3198 | ;; Otherwise, set the variables. | 3274 | ;; Otherwise, set the variables. |
| 3199 | (enable-local-variables | 3275 | (hack-local-variables-filter result nil) |
| 3200 | (hack-local-variables-filter result nil) | 3276 | (hack-local-variables-apply))))) |
| 3201 | (hack-local-variables-apply))))) | ||
| 3202 | 3277 | ||
| 3203 | (defun hack-local-variables-apply () | 3278 | (defun hack-local-variables-apply () |
| 3204 | "Apply the elements of `file-local-variables-alist'. | 3279 | "Apply the elements of `file-local-variables-alist'. |
| @@ -3610,7 +3685,7 @@ the old visited file has been renamed to the new name FILENAME." | |||
| 3610 | (interactive "FSet visited file name: ") | 3685 | (interactive "FSet visited file name: ") |
| 3611 | (if (buffer-base-buffer) | 3686 | (if (buffer-base-buffer) |
| 3612 | (error "An indirect buffer cannot visit a file")) | 3687 | (error "An indirect buffer cannot visit a file")) |
| 3613 | (let (truename) | 3688 | (let (truename old-try-locals) |
| 3614 | (if filename | 3689 | (if filename |
| 3615 | (setq filename | 3690 | (setq filename |
| 3616 | (if (string-equal filename "") | 3691 | (if (string-equal filename "") |
| @@ -3635,7 +3710,8 @@ the old visited file has been renamed to the new name FILENAME." | |||
| 3635 | (progn | 3710 | (progn |
| 3636 | (and filename (lock-buffer filename)) | 3711 | (and filename (lock-buffer filename)) |
| 3637 | (unlock-buffer))) | 3712 | (unlock-buffer))) |
| 3638 | (setq buffer-file-name filename) | 3713 | (setq old-try-locals (not (inhibit-local-variables-p)) |
| 3714 | buffer-file-name filename) | ||
| 3639 | (if filename ; make buffer name reflect filename. | 3715 | (if filename ; make buffer name reflect filename. |
| 3640 | (let ((new-name (file-name-nondirectory buffer-file-name))) | 3716 | (let ((new-name (file-name-nondirectory buffer-file-name))) |
| 3641 | (setq default-directory (file-name-directory buffer-file-name)) | 3717 | (setq default-directory (file-name-directory buffer-file-name)) |
| @@ -3655,59 +3731,63 @@ the old visited file has been renamed to the new name FILENAME." | |||
| 3655 | (setq buffer-file-number | 3731 | (setq buffer-file-number |
| 3656 | (if filename | 3732 | (if filename |
| 3657 | (nthcdr 10 (file-attributes buffer-file-name)) | 3733 | (nthcdr 10 (file-attributes buffer-file-name)) |
| 3658 | nil))) | 3734 | nil)) |
| 3659 | ;; write-file-functions is normally used for things like ftp-find-file | 3735 | ;; write-file-functions is normally used for things like ftp-find-file |
| 3660 | ;; that visit things that are not local files as if they were files. | 3736 | ;; that visit things that are not local files as if they were files. |
| 3661 | ;; Changing to visit an ordinary local file instead should flush the hook. | 3737 | ;; Changing to visit an ordinary local file instead should flush the hook. |
| 3662 | (kill-local-variable 'write-file-functions) | 3738 | (kill-local-variable 'write-file-functions) |
| 3663 | (kill-local-variable 'local-write-file-hooks) | 3739 | (kill-local-variable 'local-write-file-hooks) |
| 3664 | (kill-local-variable 'revert-buffer-function) | 3740 | (kill-local-variable 'revert-buffer-function) |
| 3665 | (kill-local-variable 'backup-inhibited) | 3741 | (kill-local-variable 'backup-inhibited) |
| 3666 | ;; If buffer was read-only because of version control, | 3742 | ;; If buffer was read-only because of version control, |
| 3667 | ;; that reason is gone now, so make it writable. | 3743 | ;; that reason is gone now, so make it writable. |
| 3668 | (if vc-mode | 3744 | (if vc-mode |
| 3669 | (setq buffer-read-only nil)) | 3745 | (setq buffer-read-only nil)) |
| 3670 | (kill-local-variable 'vc-mode) | 3746 | (kill-local-variable 'vc-mode) |
| 3671 | ;; Turn off backup files for certain file names. | 3747 | ;; Turn off backup files for certain file names. |
| 3672 | ;; Since this is a permanent local, the major mode won't eliminate it. | 3748 | ;; Since this is a permanent local, the major mode won't eliminate it. |
| 3673 | (and buffer-file-name | 3749 | (and buffer-file-name |
| 3674 | backup-enable-predicate | 3750 | backup-enable-predicate |
| 3675 | (not (funcall backup-enable-predicate buffer-file-name)) | 3751 | (not (funcall backup-enable-predicate buffer-file-name)) |
| 3676 | (progn | 3752 | (progn |
| 3677 | (make-local-variable 'backup-inhibited) | 3753 | (make-local-variable 'backup-inhibited) |
| 3678 | (setq backup-inhibited t))) | 3754 | (setq backup-inhibited t))) |
| 3679 | (let ((oauto buffer-auto-save-file-name)) | 3755 | (let ((oauto buffer-auto-save-file-name)) |
| 3680 | ;; If auto-save was not already on, turn it on if appropriate. | 3756 | ;; If auto-save was not already on, turn it on if appropriate. |
| 3681 | (if (not buffer-auto-save-file-name) | 3757 | (if (not buffer-auto-save-file-name) |
| 3682 | (and buffer-file-name auto-save-default | 3758 | (and buffer-file-name auto-save-default |
| 3683 | (auto-save-mode t)) | 3759 | (auto-save-mode t)) |
| 3684 | ;; If auto save is on, start using a new name. | 3760 | ;; If auto save is on, start using a new name. |
| 3685 | ;; We deliberately don't rename or delete the old auto save | 3761 | ;; We deliberately don't rename or delete the old auto save |
| 3686 | ;; for the old visited file name. This is because perhaps | 3762 | ;; for the old visited file name. This is because perhaps |
| 3687 | ;; the user wants to save the new state and then compare with the | 3763 | ;; the user wants to save the new state and then compare with the |
| 3688 | ;; previous state from the auto save file. | 3764 | ;; previous state from the auto save file. |
| 3689 | (setq buffer-auto-save-file-name | 3765 | (setq buffer-auto-save-file-name |
| 3690 | (make-auto-save-file-name))) | 3766 | (make-auto-save-file-name))) |
| 3691 | ;; Rename the old auto save file if any. | 3767 | ;; Rename the old auto save file if any. |
| 3692 | (and oauto buffer-auto-save-file-name | 3768 | (and oauto buffer-auto-save-file-name |
| 3693 | (file-exists-p oauto) | 3769 | (file-exists-p oauto) |
| 3694 | (rename-file oauto buffer-auto-save-file-name t))) | 3770 | (rename-file oauto buffer-auto-save-file-name t))) |
| 3695 | (and buffer-file-name | 3771 | (and buffer-file-name |
| 3696 | (not along-with-file) | 3772 | (not along-with-file) |
| 3697 | (set-buffer-modified-p t)) | 3773 | (set-buffer-modified-p t)) |
| 3698 | ;; Update the major mode, if the file name determines it. | 3774 | ;; Update the major mode, if the file name determines it. |
| 3699 | (condition-case nil | 3775 | (condition-case nil |
| 3700 | ;; Don't change the mode if it is special. | 3776 | ;; Don't change the mode if it is special. |
| 3701 | (or (not change-major-mode-with-file-name) | 3777 | (or (not change-major-mode-with-file-name) |
| 3702 | (get major-mode 'mode-class) | 3778 | (get major-mode 'mode-class) |
| 3703 | ;; Don't change the mode if the local variable list specifies it. | 3779 | ;; Don't change the mode if the local variable list specifies it. |
| 3704 | (hack-local-variables t) | 3780 | ;; The file name can influence whether the local variables apply. |
| 3705 | ;; TODO consider making normal-mode handle this case. | 3781 | (and old-try-locals |
| 3706 | (let ((old major-mode)) | 3782 | ;; h-l-v also checks it, but might as well be explcit. |
| 3707 | (set-auto-mode t) | 3783 | (not (inhibit-local-variables-p)) |
| 3708 | (or (eq old major-mode) | 3784 | (hack-local-variables t)) |
| 3709 | (hack-local-variables)))) | 3785 | ;; TODO consider making normal-mode handle this case. |
| 3710 | (error nil))) | 3786 | (let ((old major-mode)) |
| 3787 | (set-auto-mode t) | ||
| 3788 | (or (eq old major-mode) | ||
| 3789 | (hack-local-variables)))) | ||
| 3790 | (error nil)))) | ||
| 3711 | 3791 | ||
| 3712 | (defun write-file (filename &optional confirm) | 3792 | (defun write-file (filename &optional confirm) |
| 3713 | "Write current buffer into file FILENAME. | 3793 | "Write current buffer into file FILENAME. |
diff --git a/lisp/jka-cmpr-hook.el b/lisp/jka-cmpr-hook.el index d09e64634c3..600ed549731 100644 --- a/lisp/jka-cmpr-hook.el +++ b/lisp/jka-cmpr-hook.el | |||
| @@ -119,7 +119,7 @@ based on the filename itself and `jka-compr-compression-info-list'." | |||
| 119 | (defun jka-compr-install () | 119 | (defun jka-compr-install () |
| 120 | "Install jka-compr. | 120 | "Install jka-compr. |
| 121 | This adds entries to `file-name-handler-alist' and `auto-mode-alist' | 121 | This adds entries to `file-name-handler-alist' and `auto-mode-alist' |
| 122 | and `inhibit-first-line-modes-suffixes'." | 122 | and `inhibit-local-variables-suffixes'." |
| 123 | 123 | ||
| 124 | (setq jka-compr-file-name-handler-entry | 124 | (setq jka-compr-file-name-handler-entry |
| 125 | (cons (jka-compr-build-file-regexp) 'jka-compr-handler)) | 125 | (cons (jka-compr-build-file-regexp) 'jka-compr-handler)) |
| @@ -145,12 +145,12 @@ and `inhibit-first-line-modes-suffixes'." | |||
| 145 | ;; are chosen right according to the file names | 145 | ;; are chosen right according to the file names |
| 146 | ;; sans `.gz'. | 146 | ;; sans `.gz'. |
| 147 | (push (list (jka-compr-info-regexp x) nil 'jka-compr) auto-mode-alist) | 147 | (push (list (jka-compr-info-regexp x) nil 'jka-compr) auto-mode-alist) |
| 148 | ;; Also add these regexps to | 148 | ;; Also add these regexps to inhibit-local-variables-suffixes, |
| 149 | ;; inhibit-first-line-modes-suffixes, so that a | 149 | ;; so that a -*- line in the first file of a compressed tar file, |
| 150 | ;; -*- line in the first file of a compressed tar | 150 | ;; or a Local Variables section in a member file at the end of |
| 151 | ;; file doesn't override tar-mode. | 151 | ;; the tar file don't override tar-mode. |
| 152 | (push (jka-compr-info-regexp x) | 152 | (push (jka-compr-info-regexp x) |
| 153 | inhibit-first-line-modes-suffixes))) | 153 | inhibit-local-variables-suffixes))) |
| 154 | (setq auto-mode-alist | 154 | (setq auto-mode-alist |
| 155 | (append auto-mode-alist jka-compr-mode-alist-additions)) | 155 | (append auto-mode-alist jka-compr-mode-alist-additions)) |
| 156 | 156 | ||
diff --git a/lisp/jka-compr.el b/lisp/jka-compr.el index 786e4292d5f..8a8d7cdbb52 100644 --- a/lisp/jka-compr.el +++ b/lisp/jka-compr.el | |||
| @@ -657,16 +657,15 @@ It is not recommended to set this variable permanently to anything but nil.") | |||
| 657 | (defun jka-compr-uninstall () | 657 | (defun jka-compr-uninstall () |
| 658 | "Uninstall jka-compr. | 658 | "Uninstall jka-compr. |
| 659 | This removes the entries in `file-name-handler-alist' and `auto-mode-alist' | 659 | This removes the entries in `file-name-handler-alist' and `auto-mode-alist' |
| 660 | and `inhibit-first-line-modes-suffixes' that were added | 660 | and `inhibit-local-variables-suffixes' that were added |
| 661 | by `jka-compr-installed'." | 661 | by `jka-compr-installed'." |
| 662 | ;; Delete from inhibit-first-line-modes-suffixes | 662 | ;; Delete from inhibit-local-variables-suffixes what jka-compr-install added. |
| 663 | ;; what jka-compr-install added. | ||
| 664 | (mapc | 663 | (mapc |
| 665 | (function (lambda (x) | 664 | (function (lambda (x) |
| 666 | (and (jka-compr-info-strip-extension x) | 665 | (and (jka-compr-info-strip-extension x) |
| 667 | (setq inhibit-first-line-modes-suffixes | 666 | (setq inhibit-local-variables-suffixes |
| 668 | (delete (jka-compr-info-regexp x) | 667 | (delete (jka-compr-info-regexp x) |
| 669 | inhibit-first-line-modes-suffixes))))) | 668 | inhibit-local-variables-suffixes))))) |
| 670 | jka-compr-compression-info-list--internal) | 669 | jka-compr-compression-info-list--internal) |
| 671 | 670 | ||
| 672 | (let* ((fnha (cons nil file-name-handler-alist)) | 671 | (let* ((fnha (cons nil file-name-handler-alist)) |