summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorNeil Roberts <bpeeluk@yahoo.co.uk>2019-05-10 12:57:28 +0200
committerNoam Postavsky <npostavs@gmail.com>2019-05-12 09:59:55 -0400
commit02bee7860f7e650ef13e00fe1a7f9a362e3eb001 (patch)
tree33546f9e230f8906a26c8af65d692e9f701d9d16 /doc
parentb1235f9abd0f255ff65e13b18ef3ee4e19278484 (diff)
downloademacs-02bee7860f7e650ef13e00fe1a7f9a362e3eb001.tar.gz
Let dir locals for more specific modes override those from less
The list of dir local variables to apply is now sorted by the number of parent modes of the mode used as the key in the association list. That way when the variables are applied in order the variables from more specific modes will override those from less specific modes. If there are directory entries in the list then they are sorted in order of name length. The list of modes for that dir is then recursively sorted with the same mechanism. That way variables tied to a particular subdirectory override those in in a parent directory. Previously the behaviour didn’t seem to be well defined anyway and was dependent on the order they appeared in the file. However this order was changed in version 26.1 and it probably also depended on the number of dir-local files that are merged. Bug#33400 * lisp/files.el (dir-locals-get-sort-score, dir-locals-sort-variables) (dir-locals-read-from-dir): Sort the dir locals so that more precise modes and directory-specific entries have override lesser ones. * doc/emacs/custom.texi (Directory Variables): Document the priority.
Diffstat (limited to 'doc')
-rw-r--r--doc/emacs/custom.texi22
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index b07362f3cea..3fd655048b4 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -1375,6 +1375,28 @@ be applied in the current directory, not in any subdirectories.
Finally, it specifies a different @file{ChangeLog} file name for any
file in the @file{src/imported} subdirectory.
+If the @file{.dir-locals.el} file contains multiple different values
+for a variable using different mode names or directories, the values
+will be applied in an order such that the values for more specific
+modes take priority over more generic modes. Values specified under a
+directory have even more priority. For example:
+
+@example
+((nil . ((fill-column . 40)))
+ (c-mode . ((fill-column . 50)))
+ (prog-mode . ((fill-column . 60)))
+ ("narrow-files" . ((nil . ((fill-column . 20))))))
+@end example
+
+Files that use @code{c-mode} also match @code{prog-mode} because the
+former inherits from the latter. The value used for
+@code{fill-column} in C files will however be @code{50} because the
+mode name is more specific than @code{prog-mode}. Files using other
+modes inheriting from @code{prog-mode} will use @code{60}. Any file
+under the directory @file{narrow-files} will use the value @code{20}
+even if they use @code{c-mode} because directory entries have priority
+over mode entries.
+
You can specify the variables @code{mode}, @code{eval}, and
@code{unibyte} in your @file{.dir-locals.el}, and they have the same
meanings as they would have in file local variables. @code{coding}