ada-mode-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ada-mode-users] Usage of compilation-search-path considered harmful


From: Stephen Leake
Subject: Re: [Ada-mode-users] Usage of compilation-search-path considered harmful
Date: Mon, 30 Jan 2017 12:16:00 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.91 (windows-nt)

Ludovic Brenta <address@hidden> writes:

> compile.el contains:
>
> (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."
>   :type '(repeat (choice (const :tag "Default" nil)
>                        (string :tag "Directory")))
>   :group 'compilation)
>
> As can be seen, the intention is to navigate from a compilation buffer
> to a source file, not between source files. Therefore, it is my
> opinion that this variable should always be buffer-local to a
> compilation buffer. Also, the fact that this variable is defined by
> "defcustom" implies that it is intended to be under the sole control
> of the human user, by means of customize-variables.
>
> ada-mode 5.2.1 sets this variable when parsing a project file (either
> .gpr or .adp). 

Yes. This is a consequence of introducing the notion of "project" to
Emacs, but not fully implmenting it. There is more support for
"projects" in Emacs 25.

> This has the following effects:
>
> * when a user does M-x compile, whatever compilation results in the
> buffer will use compilation-search-path, even if the compilation has
> nothing to do with the ada-prj-current-file. The user may start an
> arbitrary compilation command, e.g. to compile some COBOL files :)

Some people always set compiler options to output absolute paths in
error messages, eliminating the need for 'compilation-search-path'.
IMNSHO, this is a workaround for not using projects.

Without absolute paths in error message, the user has to set
'compilation-search-path' appropriately. For Ada code, there is an easy
way to do that.

If the user switches from compiling Ada code to compiling COBOL, they
should reset 'compilation-search-path'; cobol-mode should provide an
easy way to do that.

> * when a user does M-x grep, this opens a *grep* buffer which inherits
> from compilation-mode and therefore uses compilation-search-path. This
> is harmful because the user controls where grep runs and certainly
> does not want files in the compilation-search-path to hide ones in the
> grep results.

Similar comments. If you are doing grep within an Ada project,
'compilation-search-path' set by the Ada project file is correct. If
not, reset compilation-search-path appropriately.

> * when a user does M-x occur, this also opens a *occur* buffer which
> inherits from compilation-mode, so the same remark applies.

"occur" only searches in the current buffer, so no file names are
involved; 'compilation-search-path' is irrelevant.

> After lengthy discussions with my colleagues and some more lengthy
> meditation on this, I have reached the conclusion that is is best that
> ada-mode *not* use, mention or change compilation-search-path at all.
> Navigation from one source buffer to another (e.g.
> ada-goto-declaration) uses other means, namely a gnatfind buffer; and
> navigation from a compilation buffer to source should use a
> buffer-local value in the compilation buffer. If compilation-search-
> path is nil, emacs has a reasonable default for this.

I'm not clear how to get the source path from a .gpr file to a
buffer-local compilation-search-path when the compilation buffer is
created, but there's probably some hook that would help.

ada-mode also uses 'compilation-search-path' for the 'find-file' path
(see ada-ff-*, ada-find-other-file). It could set ff-search-directories
directly instead.

> A first glance at the usage of compilation-search-path in ada-mode
> 5.2.1 tells me that there is no compelling reason for it.

I can interpret all of the above complaints as "there should be an easy
way to set 'compilation-search-path' appropriately for what I'm doing
_now_".

I totally agree, which is why ada-mode provides an easy way to set it
for compiling/editing Ada files, and why I'm using the Emacs 25
"project" support to provide ways to set it for other projects.

My Emacs currently has a "PrjSelect" menu, allowing me to easily switch
between projects. That sets other things besides compilation-search-path
(compilation-error-regexp-alist, compilation-filter-start, for example).

I've attempted to discuss this on emacs-devel; there seems to be a
mindset that you should restart Emacs if you want to switch projects, as
Eclipse, GPS, and Android Studio require. I think that's too
heavy-handed. But it means "PrjSelect" won't make it into core Emacs; I
could make it an ELPA package. 

I'm surprised that EDE (emacs-25/lisp/cedet/ede/*) doesn't set
compilation-search-path; it provides support for compiling projects. It
would be interesting to see how that is handled (or if it is just
ignored). 

ada-mode has "deselect" functions for all the features set by a project
file. Currently they run when ever selecting a new ada-mode project
file; the previous one is deselected first. We could provide
'ada-prj-deselect-current', so you can easily unset
compilation-search-path before starting your COBOL compile or grep.

-- 
-- Stephe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]