zsh-workers
 help / color / Atom feed
* [Bug] Doubled completions with suffix aliases and grouping
@ 2020-07-05 17:46 Guido Cella
  2020-07-05 18:09 ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Guido Cella @ 2020-07-05 17:46 UTC (permalink / raw)
  To: zsh-workers

[Bug] Doubled completions with suffix aliases and grouping
When completion grouping is enabled and a directory contains only regular files whose suffixes have aliases defined, file completions are listed twice. This seems to be caused by the fact that when there are no executables or directories to complete, zsh completes every file in the directory (grouped as "executable file"), and only later adds files that match suffix aliases.

This can be reproduced with:
alias -s txt=$EDITOR
autoload compinit
compinit
zstyle ':completion:*' group-name ''
zstyle ':completion:*:descriptions' format '%F{yellow}%B%d%b%f'
mkdir /tmp/foo
cd /tmp/foo
: >{1..9}.txt
./<Tab>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Bug] Doubled completions with suffix aliases and grouping
  2020-07-05 17:46 [Bug] Doubled completions with suffix aliases and grouping Guido Cella
@ 2020-07-05 18:09 ` Bart Schaefer
  2020-07-05 19:24   ` Guido Cella
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2020-07-05 18:09 UTC (permalink / raw)
  To: zsh-workers

This isn't really a bug; completions are never de-duped across
groupings that are displayed separately.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Bug] Doubled completions with suffix aliases and grouping
  2020-07-05 18:09 ` Bart Schaefer
@ 2020-07-05 19:24   ` Guido Cella
  2020-07-07  4:51     ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Guido Cella @ 2020-07-05 19:24 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Sun, Jul 05, 2020 at 11:09:22AM -0700, Bart Schaefer wrote:
> This isn't really a bug; completions are never de-duped across
> groupings that are displayed separately.
I think that the bug is adding files that aren't executable to the
"executable file" grouping. If you create a directory or real executable
in the /tmp/foo diretory or my example, the txt files are no longer
grouped as executable file.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Bug] Doubled completions with suffix aliases and grouping
  2020-07-05 19:24   ` Guido Cella
@ 2020-07-07  4:51     ` Bart Schaefer
  2020-07-07  6:57       ` Guido Cella
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2020-07-07  4:51 UTC (permalink / raw)
  To: Bart Schaefer, zsh-workers

On Sun, Jul 5, 2020 at 12:24 PM Guido Cella <guidocella91@gmail.com> wrote:
>
> I think that the bug is adding files that aren't executable to the
> "executable file" grouping.

Aye, well, that's not exactly a bug either.  The position taken when
developing the completion code was that it's always better to offer
something that the user might possibly mean rather than to offer
nothing; i.e., err on the side of too much information rather than too
little.  Because _command_names uses _alternative, the two branches
(executables and suffix-aliases) don't "know" that the other might
produce overlapping matches, so each generates its result
independently, and when executables finds nothing, it falls back to
all files.

There are two elements of your specific example that could potentially
be considered bugs.  The first is that there's no file-patterns zstyle
for the "executables" tag; the closest you can get is to set one for
the :completion:complete:-command-:: context.  The second is that this
doesn't work:

zstyle :completion::complete:-command-::executables ignored-patterns '*(^*)'

Instead you have to do this:

zstyle :completion::complete:-command-::executables ignored-patterns '*(#q^*)'

However, I think you'll find if you do that latter, you'll get what you want.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Bug] Doubled completions with suffix aliases and grouping
  2020-07-07  4:51     ` Bart Schaefer
@ 2020-07-07  6:57       ` Guido Cella
  2020-07-07 17:20         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Guido Cella @ 2020-07-07  6:57 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Mon, Jul 06, 2020 at 09:51:06PM -0700, Bart Schaefer wrote:
> On Sun, Jul 5, 2020 at 12:24 PM Guido Cella <guidocella91@gmail.com> wrote:
> >
> > I think that the bug is adding files that aren't executable to the
> > "executable file" grouping.
> 
> Aye, well, that's not exactly a bug either.  The position taken when
> developing the completion code was that it's always better to offer
> something that the user might possibly mean rather than to offer
> nothing; i.e., err on the side of too much information rather than too
> little.  Because _command_names uses _alternative, the two branches
> (executables and suffix-aliases) don't "know" that the other might
> produce overlapping matches, so each generates its result
> independently, and when executables finds nothing, it falls back to
> all files.
> 
> There are two elements of your specific example that could potentially
> be considered bugs.  The first is that there's no file-patterns zstyle
> for the "executables" tag; the closest you can get is to set one for
> the :completion:complete:-command-:: context.  The second is that this
> doesn't work:
> 
> zstyle :completion::complete:-command-::executables ignored-patterns '*(^*)'
> 
> Instead you have to do this:
> 
> zstyle :completion::complete:-command-::executables ignored-patterns '*(#q^*)'
> 
> However, I think you'll find if you do that latter, you'll get what you want.
I agree that it's better to complete all files rather than to offer
nothing, my problem is that it completes all files again even when
suffix aliases do offer matches.

zstyle :completion::complete:-command-::executables ignored-patterns '*(#q^*)'
is worse since it stops completing directories (and real executables)
when there's matching suffix alias. :/

mkdir {1..9}
touch foo.txt
./<Tab>

Only foo.txt is completed.

Anyway, by navigating the completion code I could guess fixing this
would require changing the code too much because executables and suffix
aliases are completed from different places. I only enabled grouping so
I could set list-dirs-first and have suffix aliases for everything, so
it's annoying to get double completions, even of many files, each time I
browse a leaf directory.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Bug] Doubled completions with suffix aliases and grouping
  2020-07-07  6:57       ` Guido Cella
@ 2020-07-07 17:20         ` Bart Schaefer
  2020-07-07 17:59           ` Guido Cella
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2020-07-07 17:20 UTC (permalink / raw)
  To: Bart Schaefer, zsh-workers

On Mon, Jul 6, 2020 at 11:57 PM Guido Cella <guidocella91@gmail.com> wrote:
>
> zstyle :completion::complete:-command-::executables ignored-patterns '*(#q^*)'
> is worse since it stops completing directories (and real executables)

Hmm, OK, I've forgotten that ignored-patterns is only doing name
matching, not globbing.

How about this?

zstyle -e :completion::complete:-command-::executables ignored-patterns \
  'reply=("*.(${(j:|:k)saliases})")'

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Bug] Doubled completions with suffix aliases and grouping
  2020-07-07 17:20         ` Bart Schaefer
@ 2020-07-07 17:59           ` Guido Cella
  0 siblings, 0 replies; 7+ messages in thread
From: Guido Cella @ 2020-07-07 17:59 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Tue, Jul 07, 2020 at 10:20:48AM -0700, Bart Schaefer wrote:
> On Mon, Jul 6, 2020 at 11:57 PM Guido Cella <guidocella91@gmail.com> wrote:
> >
> > zstyle :completion::complete:-command-::executables ignored-patterns '*(#q^*)'
> > is worse since it stops completing directories (and real executables)
> 
> Hmm, OK, I've forgotten that ignored-patterns is only doing name
> matching, not globbing.
> 
> How about this?
> 
> zstyle -e :completion::complete:-command-::executables ignored-patterns \
>   'reply=("*.(${(j:|:k)saliases})")'
That fixes the issues. Thank you!

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-05 17:46 [Bug] Doubled completions with suffix aliases and grouping Guido Cella
2020-07-05 18:09 ` Bart Schaefer
2020-07-05 19:24   ` Guido Cella
2020-07-07  4:51     ` Bart Schaefer
2020-07-07  6:57       ` Guido Cella
2020-07-07 17:20         ` Bart Schaefer
2020-07-07 17:59           ` Guido Cella

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git