Function: hack-local-variables-confirm

hack-local-variables-confirm is a byte-compiled function defined in files.el.gz.

Signature

(hack-local-variables-confirm ALL-VARS UNSAFE-VARS RISKY-VARS DIR-NAME)

Documentation

Get confirmation before setting up local variable values.

ALL-VARS is the list of all variables to be set up. UNSAFE-VARS is the list of those that aren't marked as safe or risky. RISKY-VARS is the list of those that are marked as risky. If these settings come from directory-local variables, then DIR-NAME is the name of the associated directory. Otherwise it is nil.

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun hack-local-variables-confirm (all-vars unsafe-vars risky-vars dir-name)
  "Get confirmation before setting up local variable values.
ALL-VARS is the list of all variables to be set up.
UNSAFE-VARS is the list of those that aren't marked as safe or risky.
RISKY-VARS is the list of those that are marked as risky.
If these settings come from directory-local variables, then
DIR-NAME is the name of the associated directory.  Otherwise it is nil."
  (unless noninteractive
    (let ((name (cond (dir-name)
		      (buffer-file-name
		       (file-name-nondirectory buffer-file-name))
		      ((concat "buffer " (buffer-name)))))
	  (offer-save (and (eq enable-local-variables t)
			   unsafe-vars))
	  (buf (get-buffer-create "*Local Variables*")))
      ;; Set up the contents of the *Local Variables* buffer.
      (with-current-buffer buf
	(erase-buffer)
	(cond
	 (unsafe-vars
	  (insert "The local variables list in " name
		  "\ncontains values that may not be safe (*)"
		  (if risky-vars
		      ", and variables that are risky (**)."
		    ".")))
	 (risky-vars
	  (insert "The local variables list in " name
		  "\ncontains variables that are risky (**)."))
	 (t
	  (insert "A local variables list is specified in " name ".")))
	(insert "\n\nDo you want to apply it?  You can type
y  -- to apply the local variables list.
n  -- to ignore the local variables list.")
	(if offer-save
	    (insert "
!  -- to apply the local variables list, and permanently mark these
      values (*) as safe (in the future, they will be set automatically.)
i  -- to ignore the local variables list, and permanently mark these
      values (*) as ignored\n\n")
	  (insert "\n\n"))
	(dolist (elt all-vars)
	  (cond ((member elt unsafe-vars)
		 (insert "  * "))
		((member elt risky-vars)
		 (insert " ** "))
		(t
		 (insert "    ")))
	  (princ (car elt) buf)
	  (insert " : ")
	  ;; Make strings with embedded whitespace easier to read.
	  (let ((print-escape-newlines t))
	    (prin1 (cdr elt) buf))
	  (insert "\n"))
        (setq-local cursor-type nil)
	(set-buffer-modified-p nil)
	(goto-char (point-min)))

      ;; Display the buffer and read a choice.
      (save-window-excursion
	(pop-to-buffer buf '(display-buffer--maybe-at-bottom))
	(let* ((exit-chars '(?y ?n ?\s))
	       (prompt (format "Please type %s%s: "
			       (if offer-save "y, n, ! or i" "y or n")
			       (if (< (line-number-at-pos (point-max))
				      (window-body-height))
				   ""
				 ", or C-v/M-v to scroll")))
	       char)
	  (when offer-save
            (push ?i exit-chars)
            (push ?! exit-chars))
	  (setq char (read-char-choice prompt exit-chars))
	  (when (and offer-save
                     (or (= char ?!) (= char ?i))
                     unsafe-vars)
	    (customize-push-and-save
             (if (= char ?!)
                 'safe-local-variable-values
               'ignored-local-variable-values)
             unsafe-vars))
	  (prog1 (memq char '(?! ?\s ?y))
	    (quit-window t)))))))