+2011-03-01 Glenn Morris <rgm@gnu.org>
+
+ * custom.texi (Directory Variables):
+ Give an example of excluding subdirectories.
+
2011-02-28 Eli Zaretskii <eliz@gnu.org>
* search.texi (Regexp Search): Move index entries about regexps to the
(tab-width . 4)
(fill-column . 80)))
(c-mode . ((c-file-style . "BSD")))
- (java-mode . ((c-file-style . "BSD")))
+ (java-mode . ((c-file-style . "BSD")
+ (subdirs . nil)))
("src/imported"
. ((nil . ((change-log-default-name . "ChangeLog.local"))))))
@end example
This example shows some settings for a hypothetical project. It sets
@samp{indent-tabs-mode}, @code{tab-width}, and @code{fill-column} for
any file in the project's directory tree, and it sets the indentation
-style for any C or Java source file. Finally, it specifies a different
-@file{ChangeLog} file name for any file in the @file{src/imported}
+style for any C or Java source file. The special @code{subdirs} element
+indicates that the Java mode settings are only to 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 of the directory where you put the @file{.dir-locals.el}
file.
+2011-03-01 Glenn Morris <rgm@gnu.org>
+
+ * variables.texi (Directory Local Variables):
+ Mention `(subdirs . nil)' alist element.
+
2011-02-28 Glenn Morris <rgm@gnu.org>
* variables.texi (Directory Local Variables): Mention the optional
The MS-DOS version of Emacs uses @file{_dir-locals.el} instead, due to
limitations of the DOS filesystems.
}. A file by that name in a directory causes Emacs to apply its
-settings to any file in that directory or any of its subdirectories.
+settings to any file in that directory or any of its subdirectories
+(optionally, you can exclude subdirectories; see below).
If some of the subdirectories have their own @file{.dir-locals.el}
files, Emacs uses the settings from the deepest file it finds starting
from the file's directory and moving up the directory tree. The file
then the all the variables in the associated @var{alist} are applied;
@var{alist} should be of the form @code{(@var{name} . @var{value})}.
A special value @code{nil} for @var{major-mode} means the settings are
-applicable to any mode.
+applicable to any mode. In @var{alist}, you can use a special
+@var{name}: @code{subdirs}. If the associated value is
+@code{nil}, the alist is only applied to files in the relevant
+directory, not to those in any subdirectories.
With the second form of @var{variables}, if @var{directory} is the
initial substring of the file's directory, then @var{list} is applied
will turn on `whitespace-mode' for *vc-diff* buffers. Modes should
call `hack-dir-local-variables-non-file-buffer' to support this.
++++
+** You can prevent directory local variables from applying to subdirectories.
+Add an element (subdirs . nil) to the alist portion of any variables
+settings to indicate said section should not be applied to subdirectories.
+
** ERC changes
*** New vars `erc-autojoin-timing' and `erc-autojoin-delay'.
+2011-03-01 Glenn Morris <rgm@gnu.org>
+
+ * files.el (dir-locals-collect-variables):
+ Add the ability to exclude subdirectories. (Bug#8100)
+
+ * dired-x.el (dired-omit-here-always): Add `(subdirs . nil)' to locals.
+
2011-02-28 Christoph Scholtes <cschol2112@googlemail.com>
* ido.el (ido-everywhere): Doc fix.
'hack-dir-local-variables-non-file-buffer "24.1")
;; Not sure this is worth having a dedicated command for...
+;; See the more general features in files-x.el.
(defun dired-omit-here-always ()
"Create `dir-locals-file' setting `dired-omit-mode' to t in `dired-mode'.
If in a Dired buffer, reverts it."
(if (file-exists-p dir-locals-file)
(message "File `./%s' already exists." dir-locals-file)
(with-temp-buffer
- (insert "((dired-mode . ((dired-omit-mode . t))))\n")
+ (insert "\
+\((dired-mode . ((subdirs . nil)
+ (dired-omit-mode . t))))\n")
(write-file dir-locals-file))
;; Run extra-hooks and revert directory.
(when (derived-mode-p 'dired-mode)
(cdr entry) root variables))))
((or (not key)
(derived-mode-p key))
- (setq variables (dir-locals-collect-mode-variables
- (cdr entry) variables))))))
+ (let* ((alist (cdr entry))
+ (subdirs (assq 'subdirs alist)))
+ (if (or (not subdirs)
+ (progn
+ (setq alist (delq subdirs alist))
+ (cdr-safe subdirs))
+ ;; TODO someone might want to extent this to allow
+ ;; integer values for subdir, where N means
+ ;; variables apply to this directory and N levels
+ ;; below it (0 == nil).
+ (equal root default-directory))
+ (setq variables (dir-locals-collect-mode-variables
+ alist variables))))))))
(error
;; The file's content might be invalid (e.g. have a merge conflict), but
;; that shouldn't prevent the user from opening the file.