diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi index 9628c087e32..2af98997480 100644 --- a/doc/emacs/building.texi +++ b/doc/emacs/building.texi @@ -188,6 +188,22 @@ appears in the @file{*compilation*} buffer. (This variable can also have the values @code{if-location-known} and @code{first-known}, which modify the conditions for automatically visiting the error locus.) +@vindex compilation-search-path +@vindex compilation-search-extra-path + The actual locus of an error message is determined by +@code{compilation-search-path}, a list of directory names. By default, +Emacs visits the file indicated in the error message under the directory +where the compilation happens, represented by the special directory name +@code{nil} in the default value for @code{compilation-search-path} +(i.e. @code{(nil)}). To make Emacs try to find the file under a +different directory (e.g. when compiling a nested project), customize +@code{compilation-search-path} to include that directory. For +directory-local customization (@pxref{Directory Variables}), prefer +setting @code{compilation-search-extra-path} instead, which Emacs +considers in addition to @code{compilation-search-path}. Entries in +@code{compilation-search-extra-path} take precedence over entries in +@code{compilation-search-path}. + Compilation mode provides the following additional commands. These commands can also be used in @file{*grep*} buffers, where the hyperlinks are search matches rather than error messages (@pxref{Grep diff --git a/etc/NEWS b/etc/NEWS index 40151ef4425..43e858352ef 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -787,6 +787,14 @@ docstring for the new option. ** Emacs now comes with Org v9.8. See the file "etc/ORG-NEWS" for user-visible changes in Org. ++++ +** New user option 'compilation-search-extra-path' +compile.el will now use paths specified in both +'compilation-search-extra-path' and 'compilation-search-path', when +doing search. 'compilation-search-extra-path' is consulted first. +One possible use case of this option is to customize add new search +paths on a per-project basis with directory-local variables. + * Editing Changes in Emacs 31.1 diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 53aca7b0266..5222579592e 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -966,10 +966,23 @@ of `my-compilation-root' here." (defcustom compilation-search-path '(nil) "List of directories to search for source files named in error messages. Elements should be directory names, not file names of directories. -The value nil as an element means to try the default directory." +The value nil as an element means to try the default directory. + +For directory-local customizations, prefer +`compilation-search-extra-path' instead." :type '(repeat (choice (const :tag "Default" nil) (string :tag "Directory")))) +;;;###autoload +(defcustom compilation-search-extra-path nil + "List of extra directories to search for source files named in error messages. +Elements in this list will be searched before those in +`compilation-search-path'. + +The buffer-local value of this variable will be inherited by the +compilation buffer." + :type '(repeat (string :tag "Directory"))) + ;;;###autoload (defcustom compile-command ;; Divide by less than 2 and round up to avoid using all processors on @@ -2009,6 +2022,8 @@ Returns the compilation buffer created." (replace-regexp-in-string "-mode\\'" "" (symbol-name mode)))) (thisdir default-directory) (thisenv compilation-environment) + (thissearchpath (append compilation-search-extra-path + compilation-search-path)) (buffer-path (and (local-variable-p 'exec-path) exec-path)) (buffer-env (and (local-variable-p 'process-environment) process-environment)) @@ -2084,6 +2099,7 @@ Returns the compilation buffer created." ;; NB: must be done after (funcall mode) as that resets local variables (setq-local compilation-directory thisdir) (setq-local compilation-environment thisenv) + (setq-local compilation-search-path thissearchpath) (if buffer-path (setq-local exec-path buffer-path) (kill-local-variable 'exec-path))