diff options
| author | Sean Whitton | 2025-03-12 10:09:45 +0800 |
|---|---|---|
| committer | Sean Whitton | 2025-03-12 10:09:45 +0800 |
| commit | 22db8a2c2aacc3c6e774c0338af3863ed668d087 (patch) | |
| tree | 489779413e41aa5a522471c9e2fdd6ab3f923bd9 | |
| parent | aa545fea2d10ac61c0628a5dee9a0953f4b21c58 (diff) | |
| parent | 202910460538401ec585e9be80c05adb55279573 (diff) | |
| download | emacs-22db8a2c2aacc3c6e774c0338af3863ed668d087.tar.gz emacs-22db8a2c2aacc3c6e774c0338af3863ed668d087.zip | |
Merge from origin/emacs-30
20291046053 Correct some outdated docs for hack-local-variables
| -rw-r--r-- | doc/lispref/variables.texi | 32 | ||||
| -rw-r--r-- | lisp/files.el | 8 |
2 files changed, 30 insertions, 10 deletions
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index f8a361aa7ce..39f3095bb9c 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi | |||
| @@ -2015,14 +2015,21 @@ function does not look for the @samp{mode:} local variable in the | |||
| 2015 | @w{@samp{-*-}} line. @code{set-auto-mode} does that, also taking | 2015 | @w{@samp{-*-}} line. @code{set-auto-mode} does that, also taking |
| 2016 | @code{enable-local-variables} into account (@pxref{Auto Major Mode}). | 2016 | @code{enable-local-variables} into account (@pxref{Auto Major Mode}). |
| 2017 | 2017 | ||
| 2018 | This function works by walking the alist stored in | 2018 | This function also puts into effect directory-local variables as |
| 2019 | @code{file-local-variables-alist} and applying each local variable in | 2019 | specified in @file{.dir-locals.el}. If the buffer is not visiting any |
| 2020 | turn. It calls @code{before-hack-local-variables-hook} and | 2020 | file, then the directory-local variables that apply are those which |
| 2021 | would be applicable to files in the @code{default-directory} | ||
| 2022 | (@pxref{Directory Local Variables}). | ||
| 2023 | |||
| 2024 | This function works by walking the alists stored in | ||
| 2025 | @code{file-local-variables-alist} and @code{dir-local-variables-alist} | ||
| 2026 | and applying each local variable in turn. It calls | ||
| 2027 | @code{before-hack-local-variables-hook} and | ||
| 2021 | @code{hack-local-variables-hook} before and after applying the | 2028 | @code{hack-local-variables-hook} before and after applying the |
| 2022 | variables, respectively. It only calls the before-hook if the alist | 2029 | variables, respectively. It only calls the before-hook if |
| 2023 | is non-@code{nil}; it always calls the other hook. This | 2030 | @code{file-local-variables-alist} is non-@code{nil}; it always calls the |
| 2024 | function ignores a @samp{mode} element if it specifies the same major | 2031 | other hook. This function ignores a @samp{mode} element if it specifies |
| 2025 | mode as the buffer already has. | 2032 | the same major mode as the buffer already has. |
| 2026 | 2033 | ||
| 2027 | If the optional argument @var{handle-mode} is @code{t}, then all this | 2034 | If the optional argument @var{handle-mode} is @code{t}, then all this |
| 2028 | function does is return a symbol specifying the major mode, if the | 2035 | function does is return a symbol specifying the major mode, if the |
| @@ -2295,6 +2302,17 @@ modification times of the associated directory local variables file | |||
| 2295 | updates this list. | 2302 | updates this list. |
| 2296 | @end defvar | 2303 | @end defvar |
| 2297 | 2304 | ||
| 2305 | @defvar dir-local-variables-alist | ||
| 2306 | This buffer-local variable holds the alist of directory-local variable | ||
| 2307 | settings. Each element of the alist is of the form @w{@code{(@var{var} | ||
| 2308 | . @var{value})}}, where @var{var} is a symbol of the local variable and | ||
| 2309 | @var{value} is its value (this is the same structure as that of | ||
| 2310 | @code{file-local-variables-alist}, @pxref{File Local Variables}). When | ||
| 2311 | Emacs visits a file, it collects all the directory-local variables into | ||
| 2312 | this alist, and then the @code{hack-local-variables} function applies | ||
| 2313 | them one by one (again, @pxref{File Local Variables}). | ||
| 2314 | @end defvar | ||
| 2315 | |||
| 2298 | @defvar hack-dir-local-get-variables-functions | 2316 | @defvar hack-dir-local-get-variables-functions |
| 2299 | This special hook holds the functions that gather the directory-local | 2317 | This special hook holds the functions that gather the directory-local |
| 2300 | variables to use for a given buffer. By default it contains just the | 2318 | variables to use for a given buffer. By default it contains just the |
diff --git a/lisp/files.el b/lisp/files.el index cc1efdf836c..6ae4d764f63 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -4205,10 +4205,12 @@ DIR-NAME is the name of the associated directory. Otherwise it is nil." | |||
| 4205 | 4205 | ||
| 4206 | (defun hack-local-variables (&optional handle-mode inhibit-locals) | 4206 | (defun hack-local-variables (&optional handle-mode inhibit-locals) |
| 4207 | "Parse and put into effect this buffer's local variables spec. | 4207 | "Parse and put into effect this buffer's local variables spec. |
| 4208 | For buffers visiting files, also puts into effect directory-local | 4208 | Also puts into effect directory-local variables. |
| 4209 | variables. | 4209 | For buffers not visiting files, apply the directory-local variables that |
| 4210 | would be applicable to files in `default-directory'. | ||
| 4210 | 4211 | ||
| 4211 | Uses `hack-local-variables-apply' to apply the variables. | 4212 | Uses `hack-local-variables-apply' and `hack-dir-local-variables' |
| 4213 | to apply the variables. | ||
| 4212 | 4214 | ||
| 4213 | If `enable-local-variables' or `local-enable-local-variables' is | 4215 | If `enable-local-variables' or `local-enable-local-variables' is |
| 4214 | nil, or INHIBIT-LOCALS is non-nil, this function disregards all | 4216 | nil, or INHIBIT-LOCALS is non-nil, this function disregards all |