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

Re: Is it possible to list all styles in all contexts?

On Mar 28,  3:18pm, Ian Tegebo wrote:
} Intuitively, I think I should be able to list them all with:
} zstyle -L "*"

Unlike options or builtin commands, styles are not enumerated anywhere.
You can think of them as *very* fancy names for variables.  Anyone can
invent a style having any name and use it for any reason; they happen
to be used in the completion system because we first thought of needing
them in conjunction with completions, but the zstyle command exists
entirely separately from the completion modules.
} To rephrase the original question, how do I programmatically expand
} all contexts into a horizontal tree whose leaves also contain the
} values tied to those styles?

Asking to list all style contexts is like asking to list all possible
shell functions.  It's meaningless; until you set a style it doesn't
exist to be listed, and no matter how many of them you have it's always
possible (up to the limits of your process memory) to create another.

On top of that, although styles are looked up using fixed strings, they
are set using patterns, so there are a large number of ways to refer
to any given context (exponential in proportion to the length of the
string used to look the style up, I think).  Even the use of colons to
separate parts of a context is an invention of the completion system
and has nothing to do with the operation of the zstyle command.

There's no registry that you can consult of lookup contexts for styles.
Within the completion system, the lookup contexts themselves are built
up dynamically during the operation of the system, including things
like the name of the command you're completing, what argument position
to that command you're completing, and even what kinds of strings can
be completed at the current position on the command line.  Even if you
could list them all, you wouldn't want to; there may be thousands of
possible values for the command name alone.

The closest to a listing is the "Completion System Configuration"
section of the manual, where there is an explanation of the syntax
for the contexts constructed by the completion system to describe the
command line.  Everything but the colons and the word "completion" at
the beginning is mutable, but except in special cases you only care
about two bits: the TAG and the style name itself.  The documentation
is only able to enumerate a few special cases of COMMAND (which are
not really commands at all and have names like "-subscript-" or
"-parameter-"), but it's got pretty thorough coverage of the most
common values of TAG and of the standard list of style names that may
be looked up.

You can also set up a command line representing a completion you want
to know about, and then press ctrl-x h.  This will show you the set
of TAG values the completion system would generate and four of the
five parts (all but the FUNCTION) of the context string that prefixes
those tags when styles are looked up.  It'll also show you a list of
the possible values for FUNCTION, but it can't predict the style
names that might eventually be asked for when one FUNCTION is finally
selected and called.  For that you have to look at the documentation
of the functions, or if that seems unsatisfactory, at their source.

I suspect that most people do one (or more) of three things:
(1) Run compinstall and let it create the style settings it knows.
(2) Grab someone else's canned set of styles and tweak it.
(3) Create styles incrementally as they work, by using ctrl-x h when
    the encounter a command they haven't used completion with before
    and the default doesn't do what they want.

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