zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Cc: Eric Cook <llua@gmx.com>
Subject: _files' default descriptions of globbed-files and all-files are identical
Date: Wed, 26 Jan 2022 15:30:05 +0000	[thread overview]
Message-ID: <20220126153005.GC1732@tarpaulin.shahaf.local2> (raw)

     1	$ cd "$(mktemp -d)" 
     2	$ touch foo bar
     3	$ zsh -f
     4	% autoload compinit && compinit
     5	% zstyle '*' format '::: %d' 
     6	% zstyle '*' group-name '' 
     7	% _f() { _files -g '*(+true)' } 
     8	% _g() { _files -g '*(+false)' } 
     9	% compdef _f f
    10	% compdef _g g 
    11	% f <TAB>
    12	::: file
    13	bar  foo
    14	% g <TAB>
    15	::: file
    16	bar  foo
    17	% zstyle ':completion:*' file-patterns '%p:globbed-files:globbed\ files *(-/):directories' '*:all-files:other\ files'
    18	% f <TAB>
    19	::: globbed files
    20	bar  foo
    21	% g <TAB>
    22	::: file
    23	bar  foo

The invocations on lines 11 and 14 generate the same output.
Consequently, if a completion function uses «_files -g "*(+foo)"» for
some non-trivial value of foo, a user can't immediately tell whether the
files they're seeing are those that match the criterion, or the
«*:all-files» group.

One way to approach this is to set the file-patterns style, as on
line 17.  That makes the two cases generate different output.

Should this setting be the default?

I'm not proposing to literally set a zstyle by default, but to change
_files so it assumes this value if no style is set; for instance:

diff --git a/Completion/Unix/Type/_files b/Completion/Unix/Type/_files
index f03b4a148..14cfe4e4e 100644
--- a/Completion/Unix/Type/_files
+++ b/Completion/Unix/Type/_files
@@ -71,11 +71,11 @@ if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then
     fi
   done
 elif zstyle -t ":completion:${curcontext}:" list-dirs-first; then
-  pats=( " *(-/):directories:directory ${${glob:-*}//:/\\:}(#q^-/):globbed-files" '*:all-files' )
+  pats=( " *(-/):directories:directory ${${glob:-*}//:/\\:}(#q^-/):globbed-files:globbed\\ files" "*:all-files:other\\ files" )
 else
   # People prefer to have directories shown on first try as default.
   # Even if the calling function didn't use -/.
-  pats=( "${${glob:-*}//:/\\:}:globbed-files *(-/):directories" '*:all-files ' )
+  pats=( "${${glob:-*}//:/\\:}:globbed-files:globbed\\ files *(-/):directories:directories" "*:all-files:other\\ files" )
 fi
 
 tried=()

Thoughts?

---

I've discussed this on IRC and Eric did not support the change.  If I
understand correctly (and I'm not sure I do), Eric'd prefer that the
completion function would use _path_files instead or that the user would
set the file-patterns style on a specific context.  Eric, please
add/correct this as needed.

Cheers,

Daniel


             reply	other threads:[~2022-01-26 15:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-26 15:30 Daniel Shahaf [this message]
2022-01-26 22:06 ` Eric Cook
2022-01-26 22:15   ` Eric Cook
2022-01-27 10:09 ` Peter Stephenson

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=20220126153005.GC1732@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=llua@gmx.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).