From: Glenn Morris Date: Tue, 1 Mar 2011 03:05:28 +0000 (-0800) Subject: Add the ability to exclude dir-locals from subdirs. (Bug#8100) X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~695 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6640b281f372aebe09d0e323b79a9aa7c311fcc2;p=emacs.git Add the ability to exclude dir-locals from subdirs. (Bug#8100) * lisp/files.el (dir-locals-collect-variables): Add the ability to exclude subdirectories. * doc/emacs/custom.texi (Directory Variables): Give an example of excluding subdirectories. * doc/lispref/variables.texi (Directory Local Variables): Mention `(subdirs . nil)' alist element. * etc/NEWS: Mention this addition. * lisp/dired-x.el (dired-omit-here-always): Add `(subdirs . nil)' to locals. --- diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index 7a9c3ae3a47..8b94bf8f6dd 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog @@ -1,3 +1,8 @@ +2011-03-01 Glenn Morris + + * custom.texi (Directory Variables): + Give an example of excluding subdirectories. + 2011-02-28 Eli Zaretskii * search.texi (Regexp Search): Move index entries about regexps to the diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index dfd55b13f18..9304e8bef08 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -1331,7 +1331,8 @@ corresponding alist applies to all the files in that subdirectory. (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 @@ -1340,8 +1341,10 @@ corresponding alist applies to all the files in that subdirectory. 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. diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index c8925715f74..1a980f14f3d 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,8 @@ +2011-03-01 Glenn Morris + + * variables.texi (Directory Local Variables): + Mention `(subdirs . nil)' alist element. + 2011-02-28 Glenn Morris * variables.texi (Directory Local Variables): Mention the optional diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index c6af304416c..a68b2b6dd4e 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -1718,7 +1718,8 @@ directory-local variables. The name of the file is 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 @@ -1749,7 +1750,10 @@ file's buffer turns on a mode that is derived from @var{major-mode}, 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 diff --git a/etc/NEWS b/etc/NEWS index cfb788940d0..0777dcc3d2a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -353,6 +353,11 @@ Just set shell-dir-cookie-re to an appropriate regexp. 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'. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e5abd0b93d7..5b8a5be8280 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2011-03-01 Glenn Morris + + * 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 * ido.el (ido-everywhere): Doc fix. diff --git a/lisp/dired-x.el b/lisp/dired-x.el index 816beb0034c..9941c7a0db5 100644 --- a/lisp/dired-x.el +++ b/lisp/dired-x.el @@ -786,6 +786,7 @@ See also `dired-enable-local-variables'." '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." @@ -798,7 +799,9 @@ replace it with a dir-locals-file `./%s'" (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) diff --git a/lisp/files.el b/lisp/files.el index 5890bf9b8c9..bafae814756 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3394,8 +3394,19 @@ Return the new variables list." (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.