comparison lisp/files.el @ 69361:b15334da7435

* files.el (hack-local-variables-confirm): Don't prompt for ! if enable-local-variables is set to always query, or there is no savable variable.
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 10 Mar 2006 23:22:30 +0000
parents e1685cc1a657
children 91f21b9dbb76
comparison
equal deleted inserted replaced
69360:e5e4303f8050 69361:b15334da7435
2347 (if noninteractive 2347 (if noninteractive
2348 nil 2348 nil
2349 (let ((name (if buffer-file-name 2349 (let ((name (if buffer-file-name
2350 (file-name-nondirectory buffer-file-name) 2350 (file-name-nondirectory buffer-file-name)
2351 (concat "buffer " (buffer-name)))) 2351 (concat "buffer " (buffer-name))))
2352 (offer-save (and (eq enable-local-variables t) unsafe-vars))
2352 prompt char) 2353 prompt char)
2353 (save-window-excursion 2354 (save-window-excursion
2354 (let ((buf (get-buffer-create "*Local Variables*"))) 2355 (let ((buf (get-buffer-create "*Local Variables*")))
2355 (pop-to-buffer buf) 2356 (pop-to-buffer buf)
2356 (set (make-local-variable 'cursor-type) nil) 2357 (set (make-local-variable 'cursor-type) nil)
2365 (insert "The local variables list in " name 2366 (insert "The local variables list in " name
2366 "\ncontains variables that are risky (**).") 2367 "\ncontains variables that are risky (**).")
2367 (insert "A local variables list is specified in " name "."))) 2368 (insert "A local variables list is specified in " name ".")))
2368 (insert "\n\nDo you want to apply it? You can type 2369 (insert "\n\nDo you want to apply it? You can type
2369 y -- to apply the local variables list. 2370 y -- to apply the local variables list.
2370 n -- to ignore the local variables list. 2371 n -- to ignore the local variables list.")
2372 (if offer-save
2373 (insert "
2371 ! -- to apply the local variables list, and mark these values (*) as 2374 ! -- to apply the local variables list, and mark these values (*) as
2372 safe (in the future, they can be set automatically.)\n\n") 2375 safe (in the future, they can be set automatically.)\n\n")
2376 (insert "\n\n"))
2373 (dolist (elt vars) 2377 (dolist (elt vars)
2374 (cond ((member elt unsafe-vars) 2378 (cond ((member elt unsafe-vars)
2375 (insert " * ")) 2379 (insert " * "))
2376 ((member elt risky-vars) 2380 ((member elt risky-vars)
2377 (insert " ** ")) 2381 (insert " ** "))
2379 (insert " "))) 2383 (insert " ")))
2380 (princ (car elt) buf) 2384 (princ (car elt) buf)
2381 (insert " : ") 2385 (insert " : ")
2382 (princ (cdr elt) buf) 2386 (princ (cdr elt) buf)
2383 (insert "\n")) 2387 (insert "\n"))
2384 (if (< (line-number-at-pos) (window-body-height)) 2388 (setq prompt
2385 (setq prompt "Please type y, n, or !: ") 2389 (format "Please type %s%s: "
2386 (goto-char (point-min)) 2390 (if offer-save "y, n, or !" "y or n")
2387 (setq prompt "Please type y, n, or !, or C-v to scroll: ")) 2391 (if (< (line-number-at-pos) (window-body-height))
2392 ""
2393 ", or C-v to scroll")))
2394 (goto-char (point-min))
2388 (let ((inhibit-quit t) 2395 (let ((inhibit-quit t)
2389 (cursor-in-echo-area t) 2396 (cursor-in-echo-area t)
2397 (exit-chars
2398 (if offer-save '(?! ?y ?n ?\s ?\C-g) '(?y ?n ?\s ?\C-g)))
2390 done) 2399 done)
2391 (while (not done) 2400 (while (not done)
2392 (message prompt) 2401 (message prompt)
2393 (setq char (read-event)) 2402 (setq char (read-event))
2394 (if (numberp char) 2403 (if (numberp char)
2395 (if (eq char ?\C-v) 2404 (if (eq char ?\C-v)
2396 (condition-case nil 2405 (condition-case nil
2397 (scroll-up) 2406 (scroll-up)
2398 (error (goto-char (point-min)))) 2407 (error (goto-char (point-min))))
2399 (setq done (memq (downcase char) 2408 (setq done (memq (downcase char) exit-chars)))))
2400 '(?! ?y ?n ?\s ?\C-g))))))
2401 (if (= char ?\C-g) 2409 (if (= char ?\C-g)
2402 (setq quit-flag nil))) 2410 (setq quit-flag nil)))
2403 (setq char (downcase char)) 2411 (setq char (downcase char))
2404 (when (and (= char ?!) unsafe-vars) 2412 (when (and offer-save (= char ?!) unsafe-vars)
2405 (dolist (elt unsafe-vars) 2413 (dolist (elt unsafe-vars)
2406 (add-to-list 'safe-local-variable-values elt)) 2414 (add-to-list 'safe-local-variable-values elt))
2407 ;; When this is called from desktop-restore-file-buffer, 2415 ;; When this is called from desktop-restore-file-buffer,
2408 ;; coding-system-for-read may be non-nil. Reset it before 2416 ;; coding-system-for-read may be non-nil. Reset it before
2409 ;; writing to .emacs. 2417 ;; writing to .emacs.
2410 (let ((coding-system-for-read nil)) 2418 (if (or custom-file user-init-file)
2411 (customize-save-variable 2419 (let ((coding-system-for-read nil))
2412 'safe-local-variable-values 2420 (customize-save-variable
2413 safe-local-variable-values))) 2421 'safe-local-variable-values
2422 safe-local-variable-values))))
2414 (kill-buffer buf) 2423 (kill-buffer buf)
2415 (or (= char ?!) 2424 (or (= char ?!)
2416 (= char ?\s) 2425 (= char ?\s)
2417 (= char ?y))))))) 2426 (= char ?y)))))))
2418 2427