Allow ignoring local variable values permanently
* doc/lispref/variables.texi (File Local Variables): Document it. * lisp/files.el (ignored-local-variable-values): New user option (bug#5003). (hack-local-variables-confirm): Allow ignoring permanently. (hack-local-variables-filter): Ignore the permanently ignored variables.
This commit is contained in:
parent
7075ebbf5b
commit
da200ab049
3 changed files with 50 additions and 7 deletions
|
@ -1995,6 +1995,16 @@ Doing so adds those variable/value pairs to
|
|||
file.
|
||||
@end defopt
|
||||
|
||||
@defopt ignored-local-variable-values
|
||||
If there are some local variables that you always want to always
|
||||
ignore, this variable can be used. It uses the same syntax as
|
||||
@code{safe-local-variable-values}, but the variable/value pairs here
|
||||
will always be ignored when handling local variables. As with that
|
||||
variable, when Emacs queries the user about whether to obey a
|
||||
file-local variable, the user can choose to ignore them permanently,
|
||||
and that will alter this variable and save it to the user's custom file.
|
||||
@end defopt
|
||||
|
||||
@defun safe-local-variable-p sym val
|
||||
This function returns non-@code{nil} if it is safe to give @var{sym}
|
||||
the value @var{val}, based on the above criteria.
|
||||
|
|
6
etc/NEWS
6
etc/NEWS
|
@ -2222,6 +2222,12 @@ This command, called interactively, toggles the local value of
|
|||
|
||||
** Miscellaneous
|
||||
|
||||
+++
|
||||
*** New user option 'ignored-local-variable-values'.
|
||||
This is the opposite of 'safe-local-variable-values' -- it's an alist
|
||||
of local variables (and accompanying values) that are to be ignored
|
||||
when reading a local variable section from a file.
|
||||
|
||||
---
|
||||
*** 'indent-tabs-mode' is now a global minor mode instead of just a variable.
|
||||
|
||||
|
|
|
@ -3437,7 +3437,19 @@ in order to initialize other data structure based on them.")
|
|||
(defcustom safe-local-variable-values nil
|
||||
"List variable-value pairs that are considered safe.
|
||||
Each element is a cons cell (VAR . VAL), where VAR is a variable
|
||||
symbol and VAL is a value that is considered safe."
|
||||
symbol and VAL is a value that is considered safe.
|
||||
|
||||
Also see `ignored-local-variable-values'."
|
||||
:risky t
|
||||
:group 'find-file
|
||||
:type 'alist)
|
||||
|
||||
(defcustom ignored-local-variable-values nil
|
||||
"List variable-value pairs that will be ignored.
|
||||
Each element is a cons cell (VAR . VAL), where VAR is a variable
|
||||
symbol and VAL is a value that will be ignored.
|
||||
|
||||
Also see `safe-local-variable-values'."
|
||||
:risky t
|
||||
:group 'find-file
|
||||
:type 'alist)
|
||||
|
@ -3592,7 +3604,9 @@ 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.)\n\n")
|
||||
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)
|
||||
|
@ -3616,16 +3630,24 @@ n -- to ignore the local variables list.")
|
|||
(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 !" "y or n")
|
||||
(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)
|
||||
(if offer-save (push ?! exit-chars))
|
||||
(when offer-save
|
||||
(push ?i exit-chars)
|
||||
(push ?! exit-chars))
|
||||
(setq char (read-char-choice prompt exit-chars))
|
||||
(when (and offer-save (= char ?!) unsafe-vars)
|
||||
(customize-push-and-save 'safe-local-variable-values unsafe-vars))
|
||||
(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)))))))
|
||||
|
||||
|
@ -3718,13 +3740,18 @@ If these settings come from directory-local variables, then
|
|||
DIR-NAME is the name of the associated directory. Otherwise it is nil."
|
||||
;; Find those variables that we may want to save to
|
||||
;; `safe-local-variable-values'.
|
||||
(let (all-vars risky-vars unsafe-vars)
|
||||
(let (all-vars risky-vars unsafe-vars ignored)
|
||||
(dolist (elt variables)
|
||||
(let ((var (car elt))
|
||||
(val (cdr elt)))
|
||||
(cond ((memq var ignored-local-variables)
|
||||
;; Ignore any variable in `ignored-local-variables'.
|
||||
nil)
|
||||
((seq-some (lambda (elem)
|
||||
(and (eq (car elem) var)
|
||||
(eq (cdr elem) val)))
|
||||
ignored-local-variable-values)
|
||||
nil)
|
||||
;; Obey `enable-local-eval'.
|
||||
((eq var 'eval)
|
||||
(when enable-local-eval
|
||||
|
|
Loading…
Add table
Reference in a new issue