comparison lisp/files.el @ 68973:934d759def37

* files.el: Rearrange functions and variables in the file local variables section.
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 17 Feb 2006 15:33:22 +0000
parents eacb238be92f
children c878e8baaab0 d08a7ef0cb8a
comparison
equal deleted inserted replaced
68972:394f3bc02021 68973:934d759def37
2216 (forward-char -3) 2216 (forward-char -3)
2217 (skip-chars-backward " \t") 2217 (skip-chars-backward " \t")
2218 (setq end (point)) 2218 (setq end (point))
2219 (goto-char beg) 2219 (goto-char beg)
2220 end)))) 2220 end))))
2221
2222 ;;; Handling file local variables
2223
2224 (defvar ignored-local-variables
2225 '(ignored-local-variables safe-local-variable-values)
2226 "Variables to be ignored in a file's local variable spec.")
2227
2228 (defvar hack-local-variables-hook nil
2229 "Normal hook run after processing a file's local variables specs.
2230 Major modes can use this to examine user-specified local variables
2231 in order to initialize other data structure based on them.")
2232
2233 (defcustom safe-local-variable-values nil
2234 "List variable-value pairs that are considered safe.
2235 Each element is a cons cell (VAR . VAL), where VAR is a variable
2236 symbol and VAL is a value that is considered safe."
2237 :group 'find-file
2238 :type 'alist)
2239
2240 (defcustom safe-local-eval-forms nil
2241 "*Expressions that are considered safe in an `eval:' local variable.
2242 Add expressions to this list if you want Emacs to evaluate them, when
2243 they appear in an `eval' local variable specification, without first
2244 asking you for confirmation."
2245 :group 'find-file
2246 :version "22.1"
2247 :type '(repeat sexp))
2248
2249 ;; Risky local variables:
2250 (mapc (lambda (var) (put var 'risky-local-variable t))
2251 '(after-load-alist
2252 auto-mode-alist
2253 buffer-auto-save-file-name
2254 buffer-file-name
2255 buffer-file-truename
2256 buffer-undo-list
2257 dabbrev-case-fold-search
2258 dabbrev-case-replace
2259 debugger
2260 default-text-properties
2261 display-time-string
2262 enable-local-eval
2263 eval
2264 exec-directory
2265 exec-path
2266 file-name-handler-alist
2267 font-lock-defaults
2268 format-alist
2269 frame-title-format
2270 global-mode-string
2271 header-line-format
2272 icon-title-format
2273 ignored-local-variables
2274 imenu--index-alist
2275 imenu-generic-expression
2276 inhibit-quit
2277 input-method-alist
2278 load-path
2279 max-lisp-eval-depth
2280 max-specpdl-size
2281 minor-mode-alist
2282 minor-mode-map-alist
2283 minor-mode-overriding-map-alist
2284 mode-line-buffer-identification
2285 mode-line-format
2286 mode-line-modes
2287 mode-line-modified
2288 mode-line-mule-info
2289 mode-line-position
2290 mode-line-process
2291 mode-name
2292 outline-level
2293 overriding-local-map
2294 overriding-terminal-local-map
2295 parse-time-rules
2296 process-environment
2297 rmail-output-file-alist
2298 save-some-buffers-action-alist
2299 special-display-buffer-names
2300 standard-input
2301 standard-output
2302 unread-command-events
2303 vc-mode))
2304
2305 ;; Safe local variables:
2306 ;;
2307 ;; For variables defined by minor modes, put the safety declarations
2308 ;; here, not in the file defining the minor mode (when Emacs visits a
2309 ;; file specifying that local variable, the minor mode file may not be
2310 ;; loaded yet). For variables defined by major modes, the safety
2311 ;; declarations can go into the major mode's file, since that will be
2312 ;; loaded before file variables are processed.
2313
2314 (let ((string-or-null (lambda (a) (or (stringp a) (null a)))))
2315 (eval
2316 `(mapc (lambda (pair)
2317 (put (car pair) 'safe-local-variable (cdr pair)))
2318 '((byte-compile-dynamic . t)
2319 (c-basic-offset . integerp)
2320 (c-file-style . stringp)
2321 (c-indent-level . integerp)
2322 (comment-column . integerp)
2323 (compile-command . ,string-or-null)
2324 (fill-column . integerp)
2325 (fill-prefix . ,string-or-null)
2326 (indent-tabs-mode . t)
2327 (ispell-check-comments . (lambda (a)
2328 (memq a '(nil t exclusive))))
2329 (ispell-local-dictionary . ,string-or-null)
2330 (kept-new-versions . integerp)
2331 (no-byte-compile . t)
2332 (no-update-autoloads . t)
2333 (outline-regexp . ,string-or-null)
2334 (page-delimiter . ,string-or-null)
2335 (paragraph-start . ,string-or-null)
2336 (paragraph-separate . ,string-or-null)
2337 (sentence-end . ,string-or-null)
2338 (sentence-end-double-space . t)
2339 (tab-width . integerp)
2340 (truncate-lines . t)
2341 (version-control . t)))))
2342
2343 (put 'c-set-style 'safe-local-eval-function t)
2221 2344
2222 (defun hack-local-variables-confirm (vars unsafe-vars risky-vars) 2345 (defun hack-local-variables-confirm (vars unsafe-vars risky-vars)
2223 (if noninteractive 2346 (if noninteractive
2224 nil 2347 nil
2225 (let ((name (if buffer-file-name 2348 (let ((name (if buffer-file-name
2344 2467
2345 (if mode-only 2468 (if mode-only
2346 mode-specified 2469 mode-specified
2347 result)))) 2470 result))))
2348 2471
2349 (defvar hack-local-variables-hook nil
2350 "Normal hook run after processing a file's local variables specs.
2351 Major modes can use this to examine user-specified local variables
2352 in order to initialize other data structure based on them.")
2353
2354 (defcustom safe-local-variable-values nil
2355 "List variable-value pairs that are considered safe.
2356 Each element is a cons cell (VAR . VAL), where VAR is a variable
2357 symbol and VAL is a value that is considered safe."
2358 :group 'find-file
2359 :type 'alist)
2360
2361 (defun hack-local-variables (&optional mode-only) 2472 (defun hack-local-variables (&optional mode-only)
2362 "Parse and put into effect this buffer's local variables spec. 2473 "Parse and put into effect this buffer's local variables spec.
2363 If MODE-ONLY is non-nil, all we do is check whether the major mode 2474 If MODE-ONLY is non-nil, all we do is check whether the major mode
2364 is specified, returning t if it is specified." 2475 is specified, returning t if it is specified."
2365 (let ((enable-local-variables 2476 (let ((enable-local-variables
2477 result unsafe-vars risky-vars)) 2588 result unsafe-vars risky-vars))
2478 (dolist (elt result) 2589 (dolist (elt result)
2479 (hack-one-local-variable (car elt) (cdr elt))))) 2590 (hack-one-local-variable (car elt) (cdr elt)))))
2480 (run-hooks 'hack-local-variables-hook)))))) 2591 (run-hooks 'hack-local-variables-hook))))))
2481 2592
2482 (defvar ignored-local-variables
2483 '(ignored-local-variables safe-local-variable-values)
2484 "Variables to be ignored in a file's local variable spec.")
2485
2486 ;; Get confirmation before setting these variables as locals in a file.
2487 (put 'debugger 'risky-local-variable t)
2488 (put 'enable-local-eval 'risky-local-variable t)
2489 (put 'ignored-local-variables 'risky-local-variable t)
2490 (put 'ignored-local-variables 'safe-local-variable-values t)
2491 (put 'eval 'risky-local-variable t)
2492 (put 'file-name-handler-alist 'risky-local-variable t)
2493 (put 'inhibit-quit 'risky-local-variable t)
2494 (put 'minor-mode-alist 'risky-local-variable t)
2495 (put 'minor-mode-map-alist 'risky-local-variable t)
2496 (put 'minor-mode-overriding-map-alist 'risky-local-variable t)
2497 (put 'overriding-local-map 'risky-local-variable t)
2498 (put 'overriding-terminal-local-map 'risky-local-variable t)
2499 (put 'auto-mode-alist 'risky-local-variable t)
2500 (put 'after-load-alist 'risky-local-variable t)
2501 (put 'buffer-file-name 'risky-local-variable t)
2502 (put 'buffer-undo-list 'risky-local-variable t)
2503 (put 'buffer-auto-save-file-name 'risky-local-variable t)
2504 (put 'buffer-file-truename 'risky-local-variable t)
2505 (put 'default-text-properties 'risky-local-variable t)
2506 (put 'exec-path 'risky-local-variable t)
2507 (put 'load-path 'risky-local-variable t)
2508 (put 'exec-directory 'risky-local-variable t)
2509 (put 'process-environment 'risky-local-variable t)
2510 (put 'dabbrev-case-fold-search 'risky-local-variable t)
2511 (put 'dabbrev-case-replace 'risky-local-variable t)
2512 ;; Don't wait for outline.el to be loaded, for the sake of outline-minor-mode.
2513 (put 'outline-level 'risky-local-variable t)
2514 (put 'rmail-output-file-alist 'risky-local-variable t)
2515 (put 'font-lock-defaults 'risky-local-variable t)
2516 (put 'special-display-buffer-names 'risky-local-variable t)
2517 (put 'frame-title-format 'risky-local-variable t)
2518 (put 'global-mode-string 'risky-local-variable t)
2519 (put 'header-line-format 'risky-local-variable t)
2520 (put 'icon-title-format 'risky-local-variable t)
2521 (put 'input-method-alist 'risky-local-variable t)
2522 (put 'format-alist 'risky-local-variable t)
2523 (put 'vc-mode 'risky-local-variable t)
2524 (put 'imenu-generic-expression 'risky-local-variable t)
2525 (put 'imenu--index-alist 'risky-local-variable t)
2526 (put 'standard-input 'risky-local-variable t)
2527 (put 'standard-output 'risky-local-variable t)
2528 (put 'unread-command-events 'risky-local-variable t)
2529 (put 'max-lisp-eval-depth 'risky-local-variable t)
2530 (put 'max-specpdl-size 'risky-local-variable t)
2531 (put 'mode-line-format 'risky-local-variable t)
2532 (put 'mode-line-modified 'risky-local-variable t)
2533 (put 'mode-line-mule-info 'risky-local-variable t)
2534 (put 'mode-line-buffer-identification 'risky-local-variable t)
2535 (put 'mode-line-modes 'risky-local-variable t)
2536 (put 'mode-line-position 'risky-local-variable t)
2537 (put 'mode-line-process 'risky-local-variable t)
2538 (put 'mode-name 'risky-local-variable t)
2539 (put 'display-time-string 'risky-local-variable t)
2540 (put 'parse-time-rules 'risky-local-variable t)
2541
2542 ;; Commonly-encountered local variables that are safe:
2543 (let ((string-or-null (lambda (a) (or (stringp a) (null a)))))
2544 (eval
2545 `(mapc (lambda (pair)
2546 (put (car pair) 'safe-local-variable (cdr pair)))
2547 '((byte-compile-dynamic . t)
2548 (c-basic-offset . integerp)
2549 (c-file-style . stringp)
2550 (c-indent-level . integerp)
2551 (comment-column . integerp)
2552 (compile-command . ,string-or-null)
2553 (fill-column . integerp)
2554 (fill-prefix . ,string-or-null)
2555 (indent-tabs-mode . t)
2556 (ispell-check-comments . (lambda (a)
2557 (or (null a)
2558 (eq t a)
2559 (eq 'exclusive a))))
2560 (ispell-local-dictionary . ,string-or-null)
2561 (kept-new-versions . integerp)
2562 (no-byte-compile . t)
2563 (no-update-autoloads . t)
2564 (outline-regexp . ,string-or-null)
2565 (page-delimiter . ,string-or-null)
2566 (paragraph-start . ,string-or-null)
2567 (paragraph-separate . ,string-or-null)
2568 (sentence-end . ,string-or-null)
2569 (sentence-end-double-space . t)
2570 (tab-width . integerp)
2571 (truncate-lines . t)
2572 (version-control . t)))))
2573
2574 (defun safe-local-variable-p (sym val) 2593 (defun safe-local-variable-p (sym val)
2575 "Non-nil if SYM is safe as a file-local variable with value VAL. 2594 "Non-nil if SYM is safe as a file-local variable with value VAL.
2576 It is safe if any of these conditions are met: 2595 It is safe if any of these conditions are met:
2577 2596
2578 * There is a matching entry (SYM . VAL) in the 2597 * There is a matching entry (SYM . VAL) in the
2605 (or (get sym 'risky-local-variable) 2624 (or (get sym 'risky-local-variable)
2606 (string-match "-hooks?$\\|-functions?$\\|-forms?$\\|-program$\\|\ 2625 (string-match "-hooks?$\\|-functions?$\\|-forms?$\\|-program$\\|\
2607 -commands?$\\|-predicates?$\\|font-lock-keywords$\\|font-lock-keywords\ 2626 -commands?$\\|-predicates?$\\|font-lock-keywords$\\|font-lock-keywords\
2608 -[0-9]+$\\|font-lock-syntactic-keywords$\\|-frame-alist$\\|-mode-alist$\\|\ 2627 -[0-9]+$\\|font-lock-syntactic-keywords$\\|-frame-alist$\\|-mode-alist$\\|\
2609 -map$\\|-map-alist$" (symbol-name sym)))) 2628 -map$\\|-map-alist$" (symbol-name sym))))
2610
2611 (defcustom safe-local-eval-forms nil
2612 "*Expressions that are considered \"safe\" in an `eval:' local variable.
2613 Add expressions to this list if you want Emacs to evaluate them, when
2614 they appear in an `eval' local variable specification, without first
2615 asking you for confirmation."
2616 :group 'find-file
2617 :version "22.1"
2618 :type '(repeat sexp))
2619
2620 (put 'c-set-style 'safe-local-eval-function t)
2621 2629
2622 (defun hack-one-local-variable-quotep (exp) 2630 (defun hack-one-local-variable-quotep (exp)
2623 (and (consp exp) (eq (car exp) 'quote) (consp (cdr exp)))) 2631 (and (consp exp) (eq (car exp) 'quote) (consp (cdr exp))))
2624 2632
2625 (defun hack-one-local-variable-constantp (exp) 2633 (defun hack-one-local-variable-constantp (exp)
3634 nil) 3642 nil)
3635 "view this file") 3643 "view this file")
3636 (?d diff-buffer-with-file 3644 (?d diff-buffer-with-file
3637 "view changes in file")) 3645 "view changes in file"))
3638 "ACTION-ALIST argument used in call to `map-y-or-n-p'.") 3646 "ACTION-ALIST argument used in call to `map-y-or-n-p'.")
3639 (put 'save-some-buffers-action-alist 'risky-local-variable t)
3640 3647
3641 (defvar buffer-save-without-query nil 3648 (defvar buffer-save-without-query nil
3642 "Non-nil means `save-some-buffers' should save this buffer without asking.") 3649 "Non-nil means `save-some-buffers' should save this buffer without asking.")
3643 (make-variable-buffer-local 'buffer-save-without-query) 3650 (make-variable-buffer-local 'buffer-save-without-query)
3644 3651