zsh-workers
 help / color / mirror / code / Atom feed
From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-workers@zsh.org
Subject: Re: completion for compilers (cc, gcc...) and -o
Date: Mon, 4 May 2020 01:17:10 +0200	[thread overview]
Message-ID: <20200503231710.GA2808728@zira.vinc17.org> (raw)
In-Reply-To: <20200502004347.5b6d880a@tarpaulin.shahaf.local2>

On 2020-05-02 00:43:47 +0000, Daniel Shahaf wrote:
> 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.

I type / validate commands quite quickly in general. So, I have some
protections, e.g. "rm" aliased to "rm -i" (ditto for cp and mv), and
I use NO_CLOBBER. But for -o, there is no protection if the target
already exists.

Note: I also use \rm, etc., but in such a case, I pay more attention
to what I type.

> Besides, source files are generally in version control, so the
> destruction will generally be reversible (up to local mods).

Generally, but not .i files. I've never seen such files in sources.
Actually, the only use of .i files I've heard of is testcases for
compilers. The first step is to generate the .i file, normally
with a command like "gcc -E [options] file.c > file.i", then do
a sequence of reduction steps on the .i file in order to get a
minimal testcase.

> > 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.

Sorry, I meant "unxz -c". In general, xz-compressed files will
have a ".xz" extension, but this is not mandatory (with sometimes
a good reason: one can imagine a text-based file format with its
own extension but compressed with xz), and "unxz -c" will happily
decompress such a file (to stdout). However, zsh assumes the .xz
extension by default in unxz completion.

In short, with its completion rules, zsh makes arbitrary choices
about what to complete, based on the common usage. And I think
that the same kind of choice should be done concerning .i files.

> > Typing "gcc file.i -o f[TAB]" and getting "gcc file.i -o file.i"
> > does not make any sense.
> 
> Agreed.

So the completion rule should avoid generating such a case.

[...]
> > 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.

The user would probably have chosen the type of generation before
the -o. For instance, if the directory contains file.c, then "file"
should be regarded as a prefix candidate in what follows:

  cc -c -o <TAB>

should complete to "file.o", and

  cc -E -o <TAB>

could complete to "file.i", but

  cc -o <TAB>

should just complete to "file", and the user could add an extension
if he wishes to do so.

About, I've said "file.o", "file.i" and "file", because "file" was
the only prefix candidate. The list of prefix candidates should be
the source files in the directory with their extension removed.

For instance, if a directory contains:

  bar.c
  foo.i
  obj.o

and the completion should give a .o file (due to the -c as above),
then the possible completions are

  bar.o   (because of bar.c)
  foo.o   (because of foo.i)
  obj.o   (usual completion to files that already exist)

With -E, bar.i should be a possible completion, but I have some
objection concerning foo.i (as I've said earlier). If foo.i is
already a source argument in the command line, then it must not
be proposed for the completion after -o.

With just "cc -o", the possible completions are

  bar   (because of bar.c)
  foo   (because of foo.i)
  obj   (as one can generate executables from .o files, i.e. cc can
        be used for linking, and the executable name is likely to be
        based on one of the existing source or .o files)

Well, that's no longer completing to existing files, but some kind
of predictive completion.

> "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…

See above.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

  parent reply	other threads:[~2020-05-03 23:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30  8:51 Vincent Lefevre
2020-04-30 17:57 ` Bart Schaefer
2020-04-30 18:14 ` Daniel Shahaf
2020-04-30 20:17   ` Vincent Lefevre
2020-04-30 20:32     ` Bart Schaefer
2020-04-30 20:54       ` Vincent Lefevre
2020-04-30 22:34         ` Daniel Shahaf
2020-04-30 22:36           ` Daniel Shahaf
2020-04-30 23:07             ` Bart Schaefer
2020-04-30 22:05     ` Daniel Shahaf
2020-05-01  1:11       ` Vincent Lefevre
2020-05-02  0:43         ` Daniel Shahaf
2020-05-02  1:26           ` Bart Schaefer
2020-05-03 23:17           ` Vincent Lefevre [this message]
2020-05-04 23:58             ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200503231710.GA2808728@zira.vinc17.org \
    --to=vincent@vinc17.net \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).