zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: compset -q oddities
Date: Wed, 14 Sep 2016 03:22:54 +0000	[thread overview]
Message-ID: <20160914032254.GA32528@fujitsu.shahaf.local2> (raw)
In-Reply-To: <160912232853.ZM27002@torch.brasslantern.com>

Bart Schaefer wrote on Mon, Sep 12, 2016 at 23:28:53 -0700:
> On Sep 12, 11:06pm, Daniel Shahaf wrote:
> } Subject: Re: compset -q oddities
> }
> } Thanks, but I don't understand how any of those examples constitutes
> } a "pilot error" or an empty word.
> 
> Some clarification, then:
> 
> } In #1, "~~~" is a complete word; completion changed it to "~~~~~~" which
> } is also a complete word but wasn't a candidate completion.
> 
> You didn't start from ~~~.  You started from an empty word and typed
> TAB twice.  ~~~ was never on the line.  I concur that the result of
> the second attempt is weird, I would have expected it just to fail.
> 

I would have expected the second <TAB> press to do nothing, since that's
what it does if the _f compadd's "xyz" instead of "~~~".

> On the first tab (empty word), the prefix is empty but "compset -q"
> causes completion to believe there is quoting on the line (backslash
> by default).  The compadd call makes ~~~ a valid completion, which
> when added is quoted to \~\~\~.  The effect of compset is then undone,
> meaning the backslash-quoting that was presumed removed is restored,
> and you end up with \\\~\\\~\\\~.
> 

All this is fine.  It would also have been correct for the first level
of quoting not to occur, since «~~~» doesn't need command-line escaping.

> On the second tab, one level of quoting is removed by compset to get
> \~\~\~ as the prefix.  Again compadd inserts \~\~\~ which does match
> the prefix, so it's a valid completion, but somewhere along the line
> all the \~ go back to \\\~ and now \~ doesn't match any more and so
> instead of being discarded because it's already present in the prefix,
> it gets appended and you end up with \\\~\\\~\\\~\\\~\\\~\\\~.
> 
> This happens for any compadd containing a tilde, it doesn't have to
> be the first character in the word.  So something wonky is going on
> with the handlng of tildes.  Actually the same thing happens with a
> leading "=" (tilde can be anywhere), so it's quotestring() that is
> contributing to the mahem (the large "else if" condition on lines
> 5824-5836).

That condition quotes the tilde because isset(EXTENDEDGLOB) is true.
This makes sense as far as quotestring() is concerned, but when called
from completion, this causes the tilde to be quoted even though
${_comp_caller_options[extendedglob]} is unset.

Bypassing this by making _f restore options[extendedglob] before calling
compadd fixes a few cases with «compadd 'a~b'» and with «compadd '~~~'»
followed by «f ~~~<TAB>», but «f <TAB><TAB>» is still wrong: it gives
\\~~~ and then \\\~\~\~\\~~~.

The backslash in \\~~~ is probably added by quotestring() [despite
unsetting extendedglob] because the 'u==s' part of the condition is
true.  Perhaps making quotestring() not add that redundant first
backslash would workaround the issue, i.e., would cause the "wonkiness"
in comp*.c not to get triggered.

> } In #2 and #3, the input is a prefix of a valid command line ("g
> } $'\'foo\''" and "h "$'foo'"" respectively).
> 
> No, that's not what I meant.  The *word* being completed is meant to
> be a partial command line, not the whole buffer.  I know that the doc
> says "split on spaces into separate words, respecting the usual shell
> quoting conventions" but the implementation calls set_comp_sep() which
> "splits the current word as if it were a command line".  But read on.
> 
> } #2 does not involve an
> } empty word; the word there is "'" (a single-byte word).
> 
> Also not quite true; the word in both #2 and #3 is an un-closed quoted
> string.  The result of that parse is not well-defined.
> 

Okay.

> I also don't know any circumstance in which it would be correct to call
> "compset -q" twice in succession as you did in #3.
> 

Something like this:

    sh -c "sh -c '<TAB>

The documentation of compset explicitly mentions that 'compset -q' might
be called recursively.

> However, on closer inspection I don't think there's actually anything
> $'...', so it's probably a spurious DPUTS.

Thanks for the detailed answer.

Daniel


  parent reply	other threads:[~2016-09-14  3:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-11  7:30 Daniel Shahaf
2016-09-12  2:14 ` Bart Schaefer
2016-09-12 23:06   ` Daniel Shahaf
2016-09-13  6:28     ` Bart Schaefer
2016-09-13 10:21       ` Peter Stephenson
2016-09-14 17:56         ` Bart Schaefer
2016-09-15  5:10           ` Daniel Shahaf
2016-09-16  0:40             ` Bart Schaefer
2016-09-16  3:05               ` [PATCH] Etc/BUGS: Remove fixed items, add 'compset -q' item from workers/39306 Daniel Shahaf
2016-09-16  5:00                 ` Bart Schaefer
2016-09-14  3:22       ` Daniel Shahaf [this message]
2016-09-14  5:20         ` compset -q oddities Bart Schaefer
2016-09-14  6:12           ` Daniel Shahaf
2016-09-14 14:59             ` Bart Schaefer
2016-09-14 19:52               ` Oliver Kiddle
2016-09-15  3:08                 ` Bart Schaefer
2016-09-14  8:31           ` Peter Stephenson
2016-09-14 16:04             ` Bart Schaefer

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=20160914032254.GA32528@fujitsu.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --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).