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

Re: Color in completions



On Feb 2, 12:21pm, Sebastian Gniazdowski wrote:
} Subject: Re: Color in completions
}
} > Hmm, I get (after editing _zplugin to add -C):
} >
} > burner% zplg
} > tags in context :completion::complete:zplg::
} >     argument-1  (_arguments _zplugin)
} > tags in context :completion::complete:zplg:argument-1:
} >     commands  (_zplugin)
} 
} The "zplg" is weird.

Sorry, my bad.  Some other stuff I was fooling with leaked in.  This is
the effect of the COMPLETE_ALIASES option:

burner% setopt completealiases 
burner% zpl
tags in context :completion::complete:zpl::
    argument-1  (_arguments _zplugin)
tags in context :completion::complete:zpl:argument-1:
    commands  (_zplugin)

If I make sure completaliases is off, then without -C/curcontext I get:

burner% zplg
tags in context :completion::complete:zplugin::
    argument-1  (_arguments _zplugin)

(note no "commands") and with -C/curcontext I get:

burner% zplg
tags in context :completion::complete:zplugin::
    argument-1  (_arguments _zplugin)
tags in context :completion::complete:zplugin:argument-1:
    commands  (_zplugin)

} Again to compare what I have:
} 
} % zplg
} tags in context :completion::complete:zplugin::
}     argument-1  (_arguments _zplugin)
}     commands    (_describe _zplugin)

The difference must be with zstyle, e.g., the completer style -- I am
(now that I got rid of completealiases) testing with the absolute
minimum setup after "zsh -f" so I have only one zstyle:

burner% zstyle -L
zstyle ':completion:*:zplugin:*:argument-rest' list-colors '=(#b)(*)/(*)==1;35=1;33'
burner% 

} When I add -C to _arguments (btw, when to use -C?):

Doc:

     The option -C tells _arguments to modify the curcontext parameter
     for an action of the form `->STATE'.  This is the standard
     parameter used to keep track of the current context.  Here it (and
     not the context array) should be made local to the calling
     function to avoid passing back the modified value and should be
     initialised to the current value at the start of the function:

          local curcontext="$curcontext"

     This is useful where it is not possible for multiple states to be
     valid together.

As I understand this, the point of -C is to create distinct zstyle
contexts for different ->state targets, so that the context can be
referenced in the caller of _arguments (and otherwise downstream) after
_arguments has returned.  So e.g. in _zplugin, in the "case $state"
block, when _wanted is called it sees the context set by _arguments -C
instead of the context in which _zplugin started.

} What zstyle would you do to handle zpl, zplg aliases? I could provide
} multiple Zstyles so that no user will be left without colors.

I'm not sure what you mean by this -- normally you would provide only
the tag names, it's up to the user to decide on the context.

If you mean what settings you should suggest, you could try:

    zstyle ':completion:*:zpl*:*:argument-rest' list-colors ...

} > Your #mark style is more specific than my suggestion.  That means it
} > matches neither the argument-1 tag nor the command and plugins tags.
} 
} I wish I could understand all this better.

Zstyles are a little weird because they're backwards from typical usage.
Normally the user would supply a fixed string and the code would have a
pattern that it compared.  With zstyle, the code has the fixed (though
incrementally constructed) string [the context] and the user supplies
the pattern, so that the same style can apply to multiple contexts.

So for completion the more colons and fewer wildcards that appear in
the user's zstyle commands, the more specifically those settings apply.

(It's potentially important to remember that the colons are specific to
the use of zstyle in compsys and have no special significance to the
internals of the zstyle command.)

-- 
Barton E. Schaefer



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