Function: hack-local-variables
hack-local-variables is a byte-compiled function defined in
files.el.gz.
Signature
(hack-local-variables &optional HANDLE-MODE INHIBIT-LOCALS)
Documentation
Parse and put into effect this buffer's local variables spec.
For buffers visiting files, also puts into effect directory-local variables.
Uses hack-local-variables-apply to apply the variables.
See hack-local-variables--find-variables for the meaning of
HANDLE-MODE.
If enable-local-variables or local-enable-local-variables is
nil, or INHIBIT-LOCALS is non-nil, this function disregards all
normal local variables. If inhibit-local-variables-regexps
applies to the file in question, the file is not scanned for
local variables, but directory-local variables may still be
applied.
Variables present in permanently-enabled-local-variables will
still be evaluated, even if local variables are otherwise
inhibited.
Source Code
;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun hack-local-variables (&optional handle-mode inhibit-locals)
"Parse and put into effect this buffer's local variables spec.
For buffers visiting files, also puts into effect directory-local
variables.
Uses `hack-local-variables-apply' to apply the variables.
See `hack-local-variables--find-variables' for the meaning of
HANDLE-MODE.
If `enable-local-variables' or `local-enable-local-variables' is
nil, or INHIBIT-LOCALS is non-nil, this function disregards all
normal local variables. If `inhibit-local-variables-regexps'
applies to the file in question, the file is not scanned for
local variables, but directory-local variables may still be
applied.
Variables present in `permanently-enabled-local-variables' will
still be evaluated, even if local variables are otherwise
inhibited."
;; We don't let inhibit-local-variables-p influence the value of
;; enable-local-variables, because then it would affect dir-local
;; variables. We don't want to search eg tar files for file local
;; variable sections, but there is no reason dir-locals cannot apply
;; to them. The real meaning of inhibit-local-variables-p is "do
;; not scan this file for local variables".
(let ((enable-local-variables
(and (not inhibit-locals)
local-enable-local-variables enable-local-variables)))
(if (eq handle-mode t)
;; We're looking just for the major mode setting.
(and enable-local-variables
(not (inhibit-local-variables-p))
;; If HANDLE-MODE is t, and the prop line specifies a
;; mode, then we're done, and have no need to scan further.
(or (hack-local-variables-prop-line t)
;; Look for the mode elsewhere in the buffer.
(hack-local-variables--find-variables t)))
;; Normal handling of local variables.
(setq file-local-variables-alist nil)
(when (and (file-remote-p default-directory)
(fboundp 'hack-connection-local-variables)
(fboundp 'connection-local-criteria-for-default-directory))
(with-demoted-errors "Connection-local variables error: %s"
;; Note this is a no-op if enable-local-variables is nil.
(hack-connection-local-variables
(connection-local-criteria-for-default-directory))))
(with-demoted-errors "Directory-local variables error: %s"
;; Note this is a no-op if enable-local-variables is nil.
(hack-dir-local-variables))
(let ((result (append (hack-local-variables--find-variables handle-mode)
(hack-local-variables-prop-line handle-mode))))
(if (and enable-local-variables
(not (inhibit-local-variables-p)))
(progn
;; Set the variables.
(hack-local-variables-filter result nil)
(hack-local-variables-apply))
;; Handle `lexical-binding' and other special local
;; variables.
(dolist (variable permanently-enabled-local-variables)
(when-let ((elem (assq variable result)))
(push elem file-local-variables-alist)))
(hack-local-variables-apply))))))