zsh-workers
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Daniel Shahaf <d.s@daniel.shahaf.name>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Bug in completion with curly braces?
Date: Mon, 23 Nov 2020 00:46:17 -0600	[thread overview]
Message-ID: <CAMP44s1AOsnpqvVF2FAb7XRx3E4sfFV3-=xDfvk1WTMgWGcdYg@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7af7n8NH5b-8Vi2MUWAzbC7-=RQDLX1kCh1R58oMgTLUw@mail.gmail.com>

On Sun, Nov 22, 2020 at 2:36 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Sat, Nov 21, 2020 at 6:58 PM Felipe Contreras
> <felipe.contreras@gmail.com> wrote:
> >
> > So the options are:
> >
> > 1. Fail the completion
> > 2. Complete something I didn't ask for (but it's close)
> > 3. Complete correctly what I asked for
> >
> > I'm saying if 3 is not feasible, then perhaps 2 would make sense
> > rather than 1. It's at least something.
>
> It's up to your completion function to tell it that #2 is OK, and what
> to offer in that circumstance.  That's one thing e.g. _alternative is
> for.

I'm not using _alternative, I'm using compadd. If compadd doesn't do
what I told it to do, then #1 it is.

> In this specific example, though, any time an unquoted "{" appears on
> the command line at the time completion is invoked, it's being treated
> as the start of a brace expansion and therefore removed from the match
> comparisons so that completion can try to fill in a comma-separated
> list of replacements.
>
> This does appear to be related to a couple of actual bugs, because
> "setopt ignorebraces" is supposed to disable this, but does not do so
> correctly.  Before I get into that, here's a hack to take advantage of
> the brace-completion behavior to get something that works the way I
> think you would like:
>
> _foo() {
>   local stashes=('stash@{0}' 'stash@{1}');
>   if [[ $words[CURRENT] = *\{* ]]
>   then compadd -Q -d stashes ${stashes//\{/}
>   else compadd -Q -a stashes
>   fi
> }

Yeah, this almost works, but I'm not interested in hacks.

My real function is something like this:

__compadd () {
  compadd -Q -p "${2-}" -S "${3- }" ${@[4,-1]} -- ${=1}
}

I'm not going to add dozens of lines of code just for this corner-case
depending on the value of $1. If compadd doesn't work on this case,
then it doesn't work on this case.

> As to the bug ... there are actually a few of them, all inter-related.
>
> 1)  _comp_options includes "NO_ignorebraces" so isset(IGNOREBRACES) is
> never true in zle_tricky.c:get_comp_string
> 2) Even if that's removed from _comp_options (and set in the caller
> context), when the brace is added to $PREFIX it is escaped with a
> backslash, so it no longer matches the string on the line and
> completion fails
> 3) When IGNOREBRACES is set, the $debug_indent string in
> _complete_debug is mis-handled
> 4) Possibly as a consequence of that, invoking _complete_debug from
> outside GDB with ignorebraces causes the shell to exit (no reported
> error, it just exits)
>
> #3 is relatively easy to fix but I won't yet in case someone can track
> down #4 (I've had no luck).

So, in theory if the user has ignorebraces set, there would be no need
to use quotes for the curly braces?

Cheers.

-- 
Felipe Contreras


  parent reply	other threads:[~2020-11-23  6:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20  1:50 Felipe Contreras
2020-11-20  2:52 ` Mikael Magnusson
2020-11-21 15:28 ` Daniel Shahaf
2020-11-21 21:08   ` Felipe Contreras
2020-11-21 22:32     ` Bart Schaefer
2020-11-22  0:37       ` Felipe Contreras
2020-11-22  2:28         ` Bart Schaefer
2020-11-22  2:58           ` Felipe Contreras
2020-11-22 20:35             ` Bart Schaefer
2020-11-22 21:20               ` Bart Schaefer
2020-11-23  3:03               ` Daniel Shahaf
2020-11-23  7:15                 ` Bart Schaefer
2020-11-23  6:46               ` Felipe Contreras [this message]
2020-11-23  7:17                 ` Bart Schaefer
2021-04-18 21:43                   ` Bart Schaefer
2020-11-23 17:31                 ` Bart Schaefer
2020-11-24 23:21                   ` Oliver Kiddle
2020-11-25  5:06                     ` Felipe Contreras
2021-12-02 19:45                       ` PATCH: bashcompinit quoting (was Re: Bug in completion with curly braces?) Oliver Kiddle

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='CAMP44s1AOsnpqvVF2FAb7XRx3E4sfFV3-=xDfvk1WTMgWGcdYg@mail.gmail.com' \
    --to=felipe.contreras@gmail.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=schaefer@brasslantern.com \
    --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).