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

Re: Tags in function files



On Sep 17, 10:37am, DervishD wrote:
}
}     OK, thanks :) BTW, the special parameters as 'words' and the
} like, are too created and initialized by compinit (I mean, the new
} completion system...)?

No, those are set up by the ZLE internals.  However, they're provided
only to "completion widgets", which means those created with "zle -C"
(as opposed to those created with "zle -N").

The new completion system (there's been a half-hearted attempt to start
using "compsys" to refer to this, to distinguish from "compctl" without
having to write a whole paragraph like this one ... I'm tempted to write
and document a function named "compsys", or at least put an index entry
with that name into the docs) is an extensive example of what can be
accomplished with "zle -C" plus the "compadd" builtin.

The really short summary is that "zle -C" tells zsh how to display the
results computed by your widget, and "compadd" from within the widget
tells zsh what those results are.  Then for finer control you can get
into playing with the values of the "compstate" parameter.  You probably
got all that already from PWS's user guide, intro to chapter 6.

} $words doesn't seem to work, so I'm thinking about using 'BUFFER' for
} command line parsing in order to call one of the completion functions
} I need. Like _main_complete, but lots simpler.

Keep in mind that one of the things _main_complete does is reset a whole
lot of setopts to be sure that all completion functions operate in the
same syntactic environment.  If, for example, you setopt KSH_ARRAYS, then
the behavior of things like $words won't match the compsys documentation.

A handy debugging tool for widgets of any sort is "zle -M".  E.g.:

zagzig% bung() { 
function> zle -M "words: $words"
function> compadd $words[1]
function> }
zagzig% zle -C bung-word .complete-word bung
zagzig% bindkey ^XB bung-word
zagzig% foo 

If I hit C-x B at this point I see:

zagzig% foo foo
words: foo

If I then type a "g" and hit C-x B again I get a beep (because "g" can't be
matched to the compadd'd match "foo") and see:

zagzig% foo foo g
words: foo foo g



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