Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Improved completion for git commit objects (__git_commit_objects)



Daniel Shahaf wrote on Wed, Mar 04, 2015 at 02:40:00 +0000:
> Daniel Hahler wrote on Wed, Mar 04, 2015 at 00:46:42 +0100:
> >    _guard '[[:xdigit:]](#c,40)' 'commit object name'
> > +
> > +  : ${(AA)commits::=${(f)"$(_call_program commits git --no-pager log --oneline -2 --format='%h%n%s')"}}
> > +  __git_command_successful $pipestatus || return 1
> > +
> > +  _wanted commits expl 'commit object name' compadd "$@" -k - commits && ret=0
> >  }
> > 
> > I do not fully understand how "_guard" is meant to be used - I need to comment/remove it.
> > Should this get chained, e.g. with "_wanted", instead?
> 
> What's the desired behaviour?  Suppose that ${(k)commits} is [0123abc,
> 4567def] and the user types '--fixup=fedbca<TAB>'.  In this case, you'd
> still want the second argument to _guard to be displayed, right?
> 
> In this case, I think you should retain _guard in the "the 'commits' tag
> is wanted, but none of ${(k)commits} matches the input so far" codepath.
> Makes sense?

Never mind that — I think you can just remove the _guard call.  The
function of _guard is to display a message when the current word matches
a pattern (sort of conditionalizing the second colon-separated part of
an _arguments option definition); _wanted will print that message
instead of _guard.

That confused me too the first time I encountered that function.
Perhaps a clarification:

diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 5890f17..89cd051 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -4278,12 +4278,12 @@ option `tt(-)tt(-help)'.
 )
 findex(_guard)
 item(tt(_guard) [ var(options) ] var(pattern descr))(
-This function is intended to be used in the var(action) for
-the specifications passed to tt(_arguments) and similar functions.  It
-returns immediately with a non-zero return status if
-the string to be completed does not match the var(pattern).  If the
-pattern matches, the var(descr) is displayed; the function then returns
-status zero if the word to complete is not empty, non-zero otherwise.
+This function displays var(descr) if var(pattern) matches the string to
+be completed.  It is intended to be used in the var(action) for the
+specifications passed to tt(_arguments) and similar functions.
+
+The return status is zero if the message was displayed and the word to
+complete is not empty, and non-zero otherwise.
 
 The var(pattern) may be preceded by any of the options understood by
 tt(compadd) that are passed down from tt(_description), namely tt(-M),

Daniel



Messages sorted by: Reverse Date, Date, Thread, Author