zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: Marlon Richert <marlon.richert@gmail.com>,
	Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [BUG] Any type of file in command position gets misleadingly completed as 'executable file'
Date: Thu, 11 Nov 2021 02:41:58 +0100	[thread overview]
Message-ID: <77920-1636594918.537752@n8BC.rFQv.eL6F> (raw)
In-Reply-To: <CAH+w=7Y=YsW6Yf9cA1_UK54Y6SOvYkeH1WLpNe3Uh0k6jHu1wA@mail.gmail.com>

Marlon Richert wrote:
> % foo^D
> executable file
> foo/
> % touch bar
> % bar^D
> executable file
> bar

I was about to say I cannot reproduce this and you must have something
in a system rc file. However, I can reproduce it by putting . in $PATH.
Is that perhaps the case? If so, I wouldn't think that's a particularly
clever idea.

Bart Schaefer wrote:
> On Wed, Nov 10, 2021 at 2:01 PM Marlon Richert <marlon.richert@gmail.com> wrote:
> >
> > The problem is in _files and it is two-fold:
> > * _files always adds '*:all-files', which ignores the pattern passed
> > with the -g flag.
>
> There's a comment:
>   # People prefer to have directories shown on first try as default.
>   # Even if the calling function didn't use -/.
>
> In fact the actual assumption is that most people prefer to have
> SOMETHING completed rather than nothing, unless they've specifically
> requested otherwise.

I'm fairly sure that's where the consensus was at the time. If you press
tab you expect something. Globs specified in completions may not always
be perfect. With some other setup like a plugin that does continuous
completion after each key then I can see it being less desirable.

> You can change this behavior by
>
> zstyle ":completion:*" file-patterns ...

Where the all-files fallback is less ideal is where other things are
completed alongside files, e.g for:
  _alternative 'files:file:_files -g "*.png(-.)"' 'others:other:(one two three)'

You can avoid that by using _complete twice. I've never used the feature
to call _complete twice because it used to be too slow but I should
perhaps reconsider:
  zstyle ':completion:*::::' completer ... _complete _complete:-all ...
  zstyle ':completion:*' file-patterns '%p:globbed-files *(-/):directories'
  zstyle ':completion:*:complete-all:*' file-patterns '*:all-files'

> > * Even though _files passes its file pattern tags to _next_label, if
> > _files was passed a tag and/or description, it _always_ prefers these
> > over the ones returned by _next_label's call to _description.

It was never intended that file-patterns would divide matches into
separate groups by default.

It doesn't "always" prefer them. Only when the [[ -n "$end" ]] condition
is set. That corresponds to the value in file-patterns including a
description, e.g. *(-/):directories:directory

Without this, it'd be using empty descriptions.

However, it is surely a bug that $end is not reinitialised with each
iteration of the for loop. That makes it difficult to use the
description we were passed for the globbed-files but to put the
globbed-files first and directories second.

It also looks like a bug that the recursive-files style is only
implemented where $end is set.

I'll put together a patch for those two points tomorrow. And add an
example to the documentation.

> > (As an aside, the docs speak of an
> > 'other-files' tag used when zstyle list-directories-first is set, but
> > this is never actually offered. Let's remove that, too.)
>
> It appears "other-files" was (inadvertently?) removed by workers/36165
> (Oliver, back in 2015).

That was intentional. Leaving it in the documentation wasn't.

Oliver

diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 89b918d60..a8beece2d 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -979,11 +979,6 @@ kindex(other-accounts, completion tag)
 item(tt(other-accounts))(
 used to look up the tt(users-hosts) style
 )
-kindex(other-files, completion tag)
-item(tt(other-files))(
-for the names of any non-directory files.  This is used instead
-of tt(all-files) when the tt(list-dirs-first) style is in effect.
-)
 kindex(packages, completion tag)
 item(tt(packages))(
 for packages (e.g. tt(rpm) or installed tt(Debian) packages)
@@ -1978,9 +1973,7 @@ kindex(list-dirs-first, completion style)
 item(tt(list-dirs-first))(
 This is used by file completion.  If set, directories to be completed
 are listed separately from and before completion for other files,
-regardless of tag ordering.  In addition, the tag tt(other-files)
-is used in place of tt(all-files) for the remaining files, to indicate
-that no directories are presented with that tag.
+regardless of tag ordering.
 )
 kindex(list-grouped, completion style)
 item(tt(list-grouped))(



  reply	other threads:[~2021-11-11  1:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 21:59 Marlon Richert
2021-11-10 22:34 ` Bart Schaefer
2021-11-11  1:41   ` Oliver Kiddle [this message]
2021-11-11 13:51     ` 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=77920-1636594918.537752@n8BC.rFQv.eL6F \
    --to=opk@zsh.org \
    --cc=marlon.richert@gmail.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).