zsh-workers
 help / color / mirror / code / Atom feed
* Tags in function files
@ 2003-09-16 20:35 DervishD
  2003-09-17  7:48 ` Oliver Kiddle
  0 siblings, 1 reply; 6+ messages in thread
From: DervishD @ 2003-09-16 20:35 UTC (permalink / raw)
  To: Zsh

    Hi all :)

    Here am I again... This time is a simple question ;) The tags
appearing on files containing completion functions (I mean, #compdef
and #autoload), are hardcoded in Zsh or is the new completion system
who parses it? I mean, can I use those tags in my shell scripts
without using the new completion system?

    I would like to write some simple functions for completing a
couple of commands, but I don't use the new completion system, as by
default (with no completion, nor old nor new) my needs are covered
at 99%

    Thanks a lot :))

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Tags in function files
  2003-09-16 20:35 Tags in function files DervishD
@ 2003-09-17  7:48 ` Oliver Kiddle
  2003-09-17  8:37   ` DervishD
  0 siblings, 1 reply; 6+ messages in thread
From: Oliver Kiddle @ 2003-09-17  7:48 UTC (permalink / raw)
  To: DervishD; +Cc: Zsh

DervishD wrote:
>     Here am I again... This time is a simple question ;) The tags
> appearing on files containing completion functions (I mean, #compdef
> and #autoload), are hardcoded in Zsh or is the new completion system
> who parses it? I mean, can I use those tags in my shell scripts
> without using the new completion system?

It is the compinit shell function which parses them. So it is just the
new completion system and not anything hardcoded into zsh.

You can use them in your own shell scripts if you really want. You might
regret it if you start using the new completion system later though so
it might be wiser to use a different word in your tags.

Oliver


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

* Re: Tags in function files
  2003-09-17  7:48 ` Oliver Kiddle
@ 2003-09-17  8:37   ` DervishD
  2003-09-17 16:30     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: DervishD @ 2003-09-17  8:37 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh

    Hi Oliver :)

 * Oliver Kiddle <okiddle@yahoo.co.uk> dixit:
> > and #autoload), are hardcoded in Zsh or is the new completion system
> > who parses it? I mean, can I use those tags in my shell scripts
> > without using the new completion system?
> It is the compinit shell function which parses them. So it is just the
> new completion system and not anything hardcoded into zsh.

    OK, thanks :) BTW, the special parameters as 'words' and the
like, are too created and initialized by compinit (I mean, the new
completion system...)? $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.

> You can use them in your own shell scripts if you really want. You might
> regret it if you start using the new completion system later though so
> it might be wiser to use a different word in your tags.

    I take note, thanks :))) Anyway I was asking just for avoiding
explicit calls to 'compdef', but I noticed that compdef is just a
function defined by compinit!, so I cannot use it. No problem anyway.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Tags in function files
  2003-09-17  8:37   ` DervishD
@ 2003-09-17 16:30     ` Bart Schaefer
  2003-09-17 19:37       ` DervishD
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2003-09-17 16:30 UTC (permalink / raw)
  To: Zsh

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


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

* Re: Tags in function files
  2003-09-17 16:30     ` Bart Schaefer
@ 2003-09-17 19:37       ` DervishD
  2003-09-18  3:44         ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: DervishD @ 2003-09-17 19:37 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh

    Hi Bart :))

    Thanks a lot for your exhaustive answer, I've learned a lot :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> }     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").

    OK, now all makes sense. I was testing with a dummy widget (NOT a
completion one...) and I was able to use 'zle complete-word' inside
my widget, but I couldn't use '$words' (it expanded to nothing). On
the other hand, I created a dummy completion widget with zle -C but
then I wasn't able to use the predefined widgets inside. Namely
something like this:

my_comp () {
    zle .complete-word
}

zle -C dummycomp complete-word my_comp

bindkey "^O" dummycomp

    When I hit '^O' zsh complains:

my_comp:zle:1: widgets can only be called when ZLE is active

    Is this intended or am I totally clueless? I mean, instead of
using compadd, I would like to be able to last-resort to some
predefined completion widget, or even call some zle widget to move
the cursor, retrieve the story, clean the command line, etc... That
is, using some of the zle facilities inside my completion widget.

> The new completion system

    I really like your suggestion, let's call it compsys ;)))

> is an extensive example of what can be
> accomplished with "zle -C" plus the "compadd" builtin.

    I've been reading some of the functions: compinit, compadd, some
of the _* functions, etc... It's a very good job, truly. I'm amazed...
 
> 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.

    I've read the entire guide, since it seems to be pretty valid
(only minor differences with my version of zsh). In fact I've learned
a lot of zsh, not only completions, but globbing, parameter
expansion, zle, etc... The guide is great. Now I feel like I can go
for the Zsh manual ;))) In the interim I'm reading the FAQ.

> } $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.

    Oh, yes, I know, but I just want to learn and make some
completions work in my box. I will try my best to set the options so
if I made a change it doesn't affect the completions.

> If, for example, you setopt KSH_ARRAYS, then
> the behavior of things like $words won't match the compsys documentation.

    My problem with the compsys documentation is that I don't know
which parameters, tags and the like are defined by compsys and which
ones are controled by Zsh guts ;)) I'm learning, slowly but surely ;)
 
> A handy debugging tool for widgets of any sort is "zle -M".  E.g.:

    THANKS!!!! That's nice!

    Thanks again for your kind answer. This is a difficult issue for
me and I really don't have all the time I would like to put it on
learning Zsh, and your help is very valuable.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


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

* Re: Tags in function files
  2003-09-17 19:37       ` DervishD
@ 2003-09-18  3:44         ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2003-09-18  3:44 UTC (permalink / raw)
  To: Zsh

[reordering things a little ...]

On Sep 17,  9:37pm, DervishD wrote:
>
>     My problem with the compsys documentation is that I don't know
> which parameters, tags and the like are defined by compsys and which
> ones are controled by Zsh guts ;)) I'm learning, slowly but surely ;)

If it's in "man zshcompwid" (info doc, Completion Widgets section) then
it's an internal parameter.  If it's in "man zshcompsys" (Completion
System section) then it's created by _main_complete or one of the helper
functions it calls.

Nearly all the parameters that you're supposed to access directly are
internal; parameters of compsys are mostly "hidden" behind zstyles, or
commands such as compdef.

Conversely, all zstyles, tags, etc. are defined by compsys.  There are
no internally-defined tags.  (There are several builtins to manipulate
them [for speed], but you're not supposed to need to know that.)

So if you're not using compinit, you can ignore anything that's said
about styles and tags.

>     OK, now all makes sense. I was testing with a dummy widget (NOT a
> completion one...) and I was able to use 'zle complete-word' inside
> my widget, but I couldn't use '$words' (it expanded to nothing). On
> the other hand, I created a dummy completion widget with zle -C but
> then I wasn't able to use the predefined widgets inside.

Right.  ZLE is separate from the collection of completion modules.  When
a completion widget is invoked, zsh/zle gives control to zsh/complete,
and won't accept control back again until the completion widget returns.
Thus you can begin a completion from a normal widget, but you can't call
back to a normal widget from a completion.  (The normal widget can keep
going after the completion finishes, but that's something different.)

However, please note that there are no predefined completion widgets!

There are only predefined completion _behaviors_ which happen to be
described by a set of widget names.  The competion widgets that _used_
to be predefined are now supplied by the zsh/compctl module, which has
to be loaded in order for those widgets to do anything.

As it turns out, if you attempt to use completion without first defining
at least one widget, zsh automatically loads zsh/compctl just so that
something sensible will happen.  The illusion of predefined completion
widgets is maintained, but it really is an illusion.

> Namely something like this:
> 
> my_comp () {
>     zle .complete-word
> }
> 
> zle -C dummycomp complete-word my_comp

This sort of thing is why "compcall" (from the zsh/compctl module) is
provided.  You want:

    zmodload -i zsh/compctl
    my_comp () {
	compcall -D
    }

The behavior of "compcall" is selected by the 2nd argument of "zle -C";
you can't switch from complete-word to expand-or-complete in midstream
(except in so far as poking into the compstate parameter allows).

> I would like to be able to last-resort to some
> predefined completion widget, or even call some zle widget to move
> the cursor, retrieve the story, clean the command line, etc... That
> is, using some of the zle facilities inside my completion widget.

Unfortunately you can't do the latter of those directly from within
the completion widget.  What you can do, I believe (having never tried
it myself), is something like this:

    my_comp_wrapper () {
	local some_variable_set_by_my_comp_on_failure
	zle dummycomp	# Invoke your completion, let it return
	if [[ -n $some_variable_set_by_my_comp_on_failure ]]
	then
	    # move the cursor, retrieve the story, clean the command line
	fi
    }
    zle -N my_comp_wrapper
    bindkey '^O' my_comp_wrapper

Just remember NOT to declare some_variable_set_by_my_comp_on_failure as
a local in my_comp.  You want it to modify its caller's local.


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

end of thread, other threads:[~2003-09-18  3:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-16 20:35 Tags in function files DervishD
2003-09-17  7:48 ` Oliver Kiddle
2003-09-17  8:37   ` DervishD
2003-09-17 16:30     ` Bart Schaefer
2003-09-17 19:37       ` DervishD
2003-09-18  3:44         ` Bart Schaefer

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