zsh-workers
 help / color / mirror / code / Atom feed
* _files' default descriptions of globbed-files and all-files are identical
@ 2022-01-26 15:30 Daniel Shahaf
  2022-01-26 22:06 ` Eric Cook
  2022-01-27 10:09 ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Shahaf @ 2022-01-26 15:30 UTC (permalink / raw)
  To: zsh-workers; +Cc: Eric Cook

     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


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

end of thread, other threads:[~2022-01-27 10:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 15:30 _files' default descriptions of globbed-files and all-files are identical Daniel Shahaf
2022-01-26 22:06 ` Eric Cook
2022-01-26 22:15   ` Eric Cook
2022-01-27 10:09 ` Peter Stephenson

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).