zsh-workers
 help / color / mirror / code / Atom feed
* _files: -/ causes caller's _alternative to be disregarded
@ 2016-09-02  4:32 Daniel Shahaf
  2016-09-02  5:03 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Shahaf @ 2016-09-02  4:32 UTC (permalink / raw)
  To: zsh-workers

I ran into a problem, and found something that was wrong and fixed it
and that made the problem go away, but I don't fully understand why the
patch does in fact fix the problem.

Here's a minimal example:

[[[
% _g() { _files -/ "$@" }
% _f() { _alternative 'x:x:_g' 'y:y:_hosts' }
% compdef _f f 
% zstyle \* list-dirs-first true 
% f <TAB>
(shows just files, doesn't show hosts)
]]]

Tracing, _files takes this codepath:
.
    37	elif [[ $type = */* ]]; then
    38	  glob="*(-/)"
    ⋮
    66	elif zstyle -t ":completion:${curcontext}:" list-dirs-first; then
    67	  pats=( " *(-/):directories:directory ${${glob:-*}//:/\\:}(#q^-/):globbed-files" '*:all-files' )
                                               ^^^^^^^^^^^^^^^^^^^^
.
and «*(-/)(#q^-/)» is not a valid pattern.

Adding another #q fixes the symptom:

[[[
diff --git Completion/Unix/Type/_files Completion/Unix/Type/_files
index 6987824..2b0c558 100644
--- Completion/Unix/Type/_files
+++ Completion/Unix/Type/_files
@@ -35,7 +35,7 @@ if (( $tmp[(I)-g*] )); then
   [[ "$glob" = (#b)(*\()([^\|\~]##\)) && $match[2] != \#q* ]] &&
       glob="${match[1]}#q${match[2]}"
 elif [[ $type = */* ]]; then
-  glob="*(-/)"
+  glob="*(#q-/)"
 fi
 tmp=$opts[(I)-F]
 if (( tmp )); then
]]]

What I'm not clear about is why the invalid pattern for the
"globbed-files" tag caused the "y:y:_hosts" alternative to be skipped.

Cheers,

Daniel

P.S.  The non-minimal example was «git push <TAB>» not offering remotes.


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

* Re: _files: -/ causes caller's _alternative to be disregarded
  2016-09-02  4:32 _files: -/ causes caller's _alternative to be disregarded Daniel Shahaf
@ 2016-09-02  5:03 ` Bart Schaefer
  2016-09-02 18:20   ` Daniel Shahaf
  2016-09-02 18:29   ` Daniel Shahaf
  0 siblings, 2 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-09-02  5:03 UTC (permalink / raw)
  To: zsh-workers

On Sep 2,  4:32am, Daniel Shahaf wrote:
}
} What I'm not clear about is why the invalid pattern for the
} "globbed-files" tag caused the "y:y:_hosts" alternative to be skipped.

The bad pattern causes _path_files to abort at line 468:

    tmp1=( $~tmp1 ) 2> /dev/null

This bails out all the way back to _dispatch line 63:

  eval "$comp" && ret=0

But _path_files has already done at least one "compadd" by that time, and
in fact the aborted part isn't going to do anything except unwind the
loop and return success, so you get the files completed but nothing
else.  However, the completer will have appeared to fail (returns non-
zero even though compadd was called) so another downstream completer
might get tried that ideally shouldn't be.  That's too late for the
_alternative part, though.

Good catch, though normally _path_files attempts to fix up glob quals
to avoid this.  However, doesn't (#q-/)(#q^-/) end up matching nothing?
(I think that's WHY the aborted portion is inconsequential.)  Is that
really what is intended here?


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

* Re: _files: -/ causes caller's _alternative to be disregarded
  2016-09-02  5:03 ` Bart Schaefer
@ 2016-09-02 18:20   ` Daniel Shahaf
  2016-09-02 18:29   ` Daniel Shahaf
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-09-02 18:20 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Thu, Sep 01, 2016 at 22:03:55 -0700:
> Good catch, though normally _path_files attempts to fix up glob quals
> to avoid this.  However, doesn't (#q-/)(#q^-/) end up matching nothing?
> (I think that's WHY the aborted portion is inconsequential.)  Is that
> really what is intended here?

I don't know what is intended, but I could imagine doing it differently:
perhaps directories that match the -g pattern should be separated from
directories that don't.  For example, «_files -g "M*"» in the zsh tree
currently lists "Misc" under the "directories" tag along with all other
directories, but instead it could show "Misc" either in a new
"globbed-directories" tag [when list-dirs-first is set], or in the
existing "globbed-files" tag alongside "Makefile.in".


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

* Re: _files: -/ causes caller's _alternative to be disregarded
  2016-09-02  5:03 ` Bart Schaefer
  2016-09-02 18:20   ` Daniel Shahaf
@ 2016-09-02 18:29   ` Daniel Shahaf
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-09-02 18:29 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote on Thu, Sep 01, 2016 at 22:03:55 -0700:
> Good catch, though normally _path_files attempts to fix up glob quals
> to avoid this.  However, doesn't (#q-/)(#q^-/) end up matching nothing?
> (I think that's WHY the aborted portion is inconsequential.)  Is that
> really what is intended here?

I'm not sure what was intended, but I can imagine doing it differently:

Currently, list-dirs-first lists all directories in one group and all
matched files that are not directories in another.  Instead, it could
have three groups: matched directories, matched non-directories,
unmatched non-directories.

For example, «_files -g "M*"» in the zsh tree could show "Misc", either
in its own group [as the only directory matching the pattern], or under
the globbed-files tag alongside plain files matching that pattern.

(For _files -/, this change would simply mean the 'directories' tag
would be empty and the 'globbed-files' tag would have the matches,
instead of the other way around.  But for patterns that match some
directories, the change would be meaningful.)


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

end of thread, other threads:[~2016-09-02 18:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-02  4:32 _files: -/ causes caller's _alternative to be disregarded Daniel Shahaf
2016-09-02  5:03 ` Bart Schaefer
2016-09-02 18:20   ` Daniel Shahaf
2016-09-02 18:29   ` Daniel Shahaf

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