Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: completion for compilers (cc, gcc...) and -o
Vincent Lefevre wrote on Fri, 01 May 2020 03:11 +0200:
> On 2020-04-30 22:05:32 +0000, Daniel Shahaf wrote:
> > Vincent Lefevre wrote on Thu, 30 Apr 2020 20:17 +00:00:
> > > On 2020-04-30 18:14:59 +0000, Daniel Shahaf wrote:
> > > > Vincent Lefevre wrote on Thu, 30 Apr 2020 10:51 +0200:
> > > > > The -o option is currently handled by
> > > > >
> > > > > '-o:output file:_files -g "^*.(c|h|cc|C|cxx)(-.)"'
> > > > >
> > > > > I wonder whether .i files (preprocessed files, e.g. for bug reports)
> > > > > should be excluded too. One can choose such files for output with
> > > > > "gcc -E", but:
> > > > > * in this case, one generally chooses to use the shorter ">" (or a
> > > > > pipe) rather than "-o" (gcc -E file.c > file.i);
> > > >
> > > > I don't see how the existence of other ways to create .i files is
> > > > a reason not to complete .i files after -o.
> > >
> > > I've googled a bit, and most examples with -E and storage in a file
> > > used the redirection.
> >
> > You've got your conditional probabilities backwards. The _a priori_
> > likelihood that -o should be used to create a .i file is irrelevant to
> > what should be completed after -o.
>
> The issue is that with a completion result on -o that is unexpected by
> the user, there is a risk of destroying a source file, while the user
> may expect something more sensible.
That'd be a pilot error. People should read command lines before
executing them. That's also why _rm doesn't filter out source files,
even though rm(1) is as likely to destroy source files as the -o option
in _gcc.
Besides, source files are generally in version control, so the
destruction will generally be reversible (up to local mods).
(And I'm still not convinced that completing .i after -o is unexpected.)
> And note that after all, filename extensions are just conventions,
> and the whole completion system is based on it, so that for instance,
> completion on "xz -c" will not propose filenames that do not end with
> ".xz" (except when there are no other candidates), even though there
> may be unlikely candidates without a ".xz" suffix.
I can't quite parse this paragraph, sorry.
> Typing "gcc file.i -o f[TAB]" and getting "gcc file.i -o file.i"
> does not make any sense.
Agreed.
> > > BTW, all examples used the -E first, so perhaps
> > > accept .i files for -o only when -E is present.
> > >
> > > Note that GCC describes .i files as source files (among other
> > > extensions of source files).
> >
> > They're _intermediate_ files; they can be either input or output. But
> > they _can_ be output, so we should complete them, shouldn't we?
>
> I would say only with -E, then.
Maybe complete them always, but not under the same tag as output files
which aren't intermediate files (such as .so files)? When the user has
typed «cc -o <TAB>», we don't know whether the user intends to create
a .i, or .o, or .exe, or .so, but in any case separating the possibilities
by type (= set of extensions) is likely to be helpful.
"In the face of ambiguity, refuse the temptation to guess."
Cheers,
Daniel
P.S. I don't understand why it's useful for -o to complete .c files when
all files in the directory are .c files. Wouldn't a "No matches" error
be more practical? I suppose there's a way to coerce the tag-order style
into providing these semantics…
Messages sorted by:
Reverse Date,
Date,
Thread,
Author