zsh-workers
 help / color / mirror / code / Atom feed
* Re: Let's finish this new completion stuff
@ 1999-02-22 16:01 Sven Wischnowsky
  0 siblings, 0 replies; 11+ messages in thread
From: Sven Wischnowsky @ 1999-02-22 16:01 UTC (permalink / raw)
  To: zsh-workers


Another reply to this, not directly connected to the implementation of 
the completion stuff.

Peter Stephenson wrote:

> By the way, is it
> really necessary to have the `cmd=$(whence -p $COMMAND)' on every call to
> command/argument completion?  I haven't thought about it, but maybe it can
> be optimised away in a lot of cases.

The problem is that this is immediatly used when testing pattern
completions. And I think this is important to have since `*/X11/*' is
a better test for X-programs than `x*', which is just plain wrong.
I first tried `eval cmd2\==$COMMAND' but that makes zsh stop if there
is no such command (`zsh: foo not found').

> I'm still vaguely of the opinion it would be quite nice to have long
> Posix-style options for the comp* commands, as I suggested some time ago,
> e.g. 
> 
> complist -mf
> 
> could also be
> 
> complist --external --files
> 
> or something for readability.

Yes, but maybe we should do this is some generic way in builtin.c, so
that we can add such long options to (almost) all builtins. I.e. a way 
to store the long names together with the short names they are aliases 
for and then make execbuiltin() put them in the ops array as usual.


Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Let's finish this new completion stuff
@ 1999-02-23  9:08 Sven Wischnowsky
  0 siblings, 0 replies; 11+ messages in thread
From: Sven Wischnowsky @ 1999-02-23  9:08 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> I don't want to get into anything that looks like a multidimensional
> array.

We already allow multiple subscripst in parameter expansion, not in
assignments.

> OK would be $matches[prefix(num)] or something ... though in
> thinking about it a bit further, I think I prefer requiring the (r) or
> (R) flag to activate any such magic, e.g. $matches[(r)prefix(num)].
> The connection to patterns is useful; it's just a special case of a
> pattern.

Yes, I'd prefer requiring the `(r)', too. (Hm, I already said that,
didn't I? I think so...)

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Let's finish this new completion stuff
@ 1999-02-22 10:36 Sven Wischnowsky
  0 siblings, 0 replies; 11+ messages in thread
From: Sven Wischnowsky @ 1999-02-22 10:36 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> By the way, your doc for the new completion stuff doesn't mention any
> of the $argv-modifying etc. side-effects of the condition codes (except
> for -iprefix changing $IPREFIX), as far as I can tell.

I had it for `-string' and `-class', too, but forgot it for `-after'
and `-between'.

Bye
 Sven

--- od/Zsh/compwid.yo	Mon Feb 22 10:49:09 1999
+++ Doc/Zsh/compwid.yo	Mon Feb 22 11:10:07 1999
@@ -382,15 +382,19 @@
 var(min) and equal to or less than var(max)
 )
 item(tt(-after) var(string))(
-true if the cursor is after a word that is equal to var(string)
+true if the cursor is after a word that is equal to var(string); this
+removes all words up to and including the matched word from the
+positional parameters
 )
 item(tt(-mafter) var(pattern))(
 like tt(-after) but using pattern matching
 )
 item(tt(-between) var(string1) var(string2))(
 true if the cursor is after a word that is equal to var(string1), if
-there is also a word that is equal to va(string2), this is true only
-if the cursor is before it
+there is also a word that is equal to var(string2), this is true only
+if the cursor is before it; as a side effect, all words before
+var(string1) and after var(string2) (both inclusive) are removed from
+the positional parameters
 )
 item(tt(-mbetween) var(pattern1) var(pattern2))(
 like tt(-between) but using pattern matching

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Let's finish this new completion stuff
@ 1999-02-22  9:44 Sven Wischnowsky
  1999-02-23  5:28 ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Sven Wischnowsky @ 1999-02-22  9:44 UTC (permalink / raw)
  To: zsh-workers


I'm trying to reply simultaneously to Peter and Bart here...

Bart:
> Preliminary remark:  I think it's premature to be talking about "finishing"
> this stuff.  There are, what, three? people actually trying this out right
> now?  And one of them is the implementor of 90% of the underlying code.
> This is not the way to do a usability study.  I imagine we're going to be
> tweaking things for a long while.

Yes, I know that only too well. It was an attempt to draw more
attention to the mail... (sorry).

> } - Using the positional parameters as we do now has some drawbacks. We
> }   could make the completion widget store them in another array but
> }   then the modifying tests (see below) would still change `argv'
> 
> Let me see if I understand this.  Referring to the tests that modify the
> word list as a side-effect:
> 
> As of the current date, those tests (a) expect to find the previous word
> list in the positionals, and (b) always stuff the new word list into the
> positional parameters of whatever function calls them.  So if you forget
> to pass the previous word list to a sub-function as its arguments, none
> of the tests work as expected.
> 
> Have I got that right?

Yep.

> If we don't use the positionals, we should use another special variable
> with a hardwired name, as PWS suggested.

That was what I meant, fine.

> What do you do in cases where COMMAND presently doesn't contain a real
> command name?

The `context'-name would be in the `CONTEXT'-parameter (or the one we
use to replace `CONTEXT'), the words from the line would still be in
the `words' array (e.g the words when completing inside an array value 
or inside a condition).

> } - We could also put the `COMMAND' into the `CONTEXT' parameter which I 
> }   would like to replace with a associative array with keys:
> 
> So whichever of these was uninteresting would simply not be set?

Yes (or empty).

> Anyway, let's call this hypothetical associative array `compstate' for
> purposes of discussion.
> 
> }   - `command'   if this is used as the replacement for `COMMAND'.
> }   - `redirect'  for the string of the redirection operator
> }   - `parameter' for the `value' and `subscript' contexts where it will 
> }                 contain the name of the parameter
> }   - `type'      as the replacement for the old `CONTEXT'
> 
> I like `context' better.  `Type' means too many different things.

I was thinking about calling the array `context' and didn't like
`$context[context]'. If the parameter has another name, I'd prefer
using `context' as the key, too.

Peter now:
> This sounds OK, but if $COMMAND is really just going to be $words[1] or
> whatever it might be a bit confusing to put it here too --- for example, if
> you are completing after `nice' so that $words gets narrowed to whatever's
> after, does $context[command] refer to `nice' or to the next word, and when
> you change the context (shift words; (( CURRENT-- )) ) is the user or the
> shell responsible for changing it?  I think we should just stick to using
> $words or whatever name anyone else suggests, if that's agreed upon.

I meant to either store it in `words' exclusive-or in
`context'. The narrowing would be done by the shell when using the
modifying whatevers but could, of course be done in shell code (and
with everything in the `words' array this would be much easier).

Bart again:
> Why not put everything that's not another array in here?
> 
> 	CURRENT		-->	compstate[current]
> 	PREFIX		-->	compstate[prefix]
> 	IPREFIX		-->	compstate[ignored]
> 	SUFFIX		-->	compstate[suffix]
> 	NMATCHES	-->	compstate[nmatches]
> 	MATCHER		-->	compstate[matcher]

Actually, I thought about this, too. But `$PREFIX' looks so
nice. Still, I wouldn't mind stuffing everything into one associative
array.

Peter:
> > - The example code currently uses the return value of the shell
> >   functions or a parameter (in the new version I just sent) to decide
> >   whether more completion definitions should be used. This can not be
> >   combined with `compcall' which currently gives no information about
> >   things like that. I'm not too sure about this, but maybe we would
> >   want to add a special parameter that will be used by `compcall' and
> >   that can also (of course) be used in the shell code. (Someone else
> >   should decide this since I don't care that much about `compctl' any
> >   more.)
> 
> I'd have thought for anyone still using compctl it would be good enough
> just to be able to test $NMATCHES.  If anybody wants anything more
> sophisticated, they're going to be going over to new completion anyway.

*Good* (That's what I wanted to hear ;-)

Bart:
> } The testing problem:
> } 
> } Some of the condition codes we currently have could easily be replaced
> } by shell code so we should probably remove them. The question was/is
> } with what we would replace them.
> 
> I have a radical suggestion:  Replace them with magic elements of the
> compstate array.  A special associative predefined by zsh doesn't have
> to be implemented by a simple hash table; it can do its own special
> interpretation of the subscripts.
> 
> Then we can invent a whole lot of new syntax for the completion stuff,
> and hide it where the lexer already skipparens() it.

I like `magic' syntax, but I'm not sure if the users would like it...

> [ examples for implementing tests in shell code ]
> 
> These are so messy I'm not going to try work them out on the fly here:
> 
> [[ -string str ]]
> ...
> [[ -mbetween pat1 pat2 ]]

I showed shell code for them in message 5386, possible, but...

> An alternate idea is to require the (r) or (R) subscript flags to make
> the magic syntax active, so you get something like:
> 
>     $compstate[(r)position(x)]	 if compstate[current] == x, expands
>     				 to $words[x], else expands to nothing
> 
>     $compstate[(R)position(x,y)] if compstate[current] is between x
> 				 and y, expands to $words[x,y]

Hm, I like this, but I'll need some more comments on it before
trying to implement something like this.

> I suggest making the existing list available in a parameter that can
> be tested and modified directly; the sets.afn of that array can do the
> equivalent of `compadd`.  For booleans like "are we menu-completing,"
> see the AA idea above.

Making the list of completions generated so far available isn't that
easy without disallowing adding further completions. Also, we can't
easily deliver all the information stored with an array. But now that
we are speaking about sepcial subscript-syntax anyway, how about:

  $matches[num][prefix]  gives the `compadd -p'-prefix of the num'th
                         match
  $matches[num][string]  the string to list

And so on. I've no idea how difficult to implement this would be,
though.

> } - Options to say what should be done with the matches genereated,
> }   e.g.: `list them', `don't list them', `use menu-completion', `insert 
> }   it into the line', etc.
> 
> Don't those options belong on complist/compadd?  Or is it not possible
> to have some of the matches listed and others not?  (That is, is it a
> requirement that there be a single global switch for this stuff?)

With `compadd' one can add matches that are not to be shown. But what
I meant is the post-processing and that can not be set on a per-match
basis (we can't have one half of the matches menu-completed and the
other half with normal completion). I hadn't thought about using the
associative array for this, though (as Peter suggested, too). But,
yes, you are right, if we make this a more complete
`context-information' thing, this kind of information could (or
should) be stored there (and taken from there after the completion
widgets finish).

> By the way, again, one thing I haven't figured out how to do with the
> new completion stuff is the equivalent of `compctl -X`.  How does one
> add an explanation string, and when does it get shown?

You just use `complist -X ...'. Explanation strings are stored with
groups of matches. So a `complist -X ...' stores a string in the
sorted group named `default'. To store strings in other groups one
would use `complist -J ... -X ...' (or `-V').

Peter:
> In other words, internal control of what the widget is really doing: `I'm
> fed up with being an expand-or-complete, I want to be a list-choices'.
> Maybe this needs to integrate somehow with `zle ...' calls, but I can't
> offhand think how.

Hm, hadn't thought about `zle ...' and have no ideas now.

> I presume it's easy enough to tell whether you're completing after a ~
> anyway -- just look to see if there's a slash yet.  The advantage of
> something like a context would be you can finally solve the problem compctl
> -T was invented to solve in a modular way, i.e. making your own list of
> usernames.  With a context you can just plug in your own comps[-tilde-] by
> the autoload-scanning mechanism.  Thinks: this doesn't have to be a context
> generated by the C code, there's nothing to stop _normal looking up
> $comps[-tilde-] by itself if it thinks that's a good idea, [and maybe
> completing users if there isn't one (it can even check $COMPSKIP) --- but
> perhaps the best idea would be to provide a _tilde handler for -tilde-
> which the user then modifies directly].

Yes, that's what I was thniking about. Let the C-code do the test for
`$...' (which isn't that easy with all the flag-parsing and so on) and 
let the widget do the `[[ -iprefix '~' ]] ...' or whatever.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Let's finish this new completion stuff
@ 1999-02-22  8:50 Sven Wischnowsky
  0 siblings, 0 replies; 11+ messages in thread
From: Sven Wischnowsky @ 1999-02-22  8:50 UTC (permalink / raw)
  To: zsh-workers


Matt Armstrong wrote:

> > Before I get tired of asking the same questions again and
> > again, I'll write down all the things I'm thinking about
> > and which I'd like to discuss before we start implementing
> > them.
> >
> > *Please* take the time to send comments, suggestions, answers,
> > questions or whatever.
> 
> I think the completion stuff is one of the most important aspects of zsh 
> (it is what motivated me to switch to zsh from tcsh).  So, I'd love to 
> contribute to this discussion.
> 
> However, I must admit that I haven't understood most of the completion 
> related discussion to date.  I think this is in part because it is a 
> complex subject, but also because I came in in the middle of the 
> development.
> 
> The thing that'd help me understand most is an easy way to see a 
> function call trace when __complete_expand-or-complete and friends get 
> called.  Is something like that possible?

This is for normal completion (the one not bound to special keys):

- The C-Code calls `_main_complete', that is the completion widget.
- This function first looks up the entry for `-first-' in the
  associative array `comps' which is used as the table to connect
  command names (and a few special names like `-first-', `-default-',
  etc) with the names of the functions that generate the completions
  for that command.
  If there is an entry for `-first-', the function is called, after
  that `COMPSKIP' is tested (the replacement for `compctl -t'): if it
  is set, no other completions are generated.
  All functions generating matches get the words from the command line 
  as positional parameters.
- When other completions (vaguely speaking: for the command itself)
  are to be generated, `_main_complete' looks at the value of
  `CONTEXT' to find out which function to call. For contexts like
  mathematical expressions and so on, other special names surrounded
  by hyphens are used for looking at `comps'. Again, the function
  found, if any, is invoked.
- Completion in command position and in arguments is handled in
  another function: `_normal'. For completion in command position it
  just calls the entry for `-command-' in the `comps' array. For
  arguments this function first gets the command name to use. These
  may actually be two names: if a path is given on the line, the whole
  path and the last component are tried. If the name on the line starts
  with `=' the full pathname is used. Otherwise the name on the line
  and the pathname of that command is used.
  With these names, the (normal) array `patcomps' is searched. Entries 
  in this array look like `pat func', i.e.: a pattern and the name of
  a function separated by a space. Whenever an element is found whose
  pattern matches one of the command names produced, the function is
  invoked to generate matches. After that, `COMPSKIP' is tested again.
  After the patterns were tried, lookup in the associative array
  `comps' is done again, with the two command names (one after
  another), if no entry for them is found, the entry for `-default-'
  is used again. As soon as an entry is found, the function is
  invoked.

So, the call chain for normal argument-completion is:

  C-Code
    _main_complete
      _normal
        functions for patterns, if any
        function for the command or for `-default-

For non-argument-or-command completion the call chain is:

  C-Code
    _main_complete
      function for special context or for `-default-'

Completion bound to special keys just calls the function for that key
directly with no intervening helper functions.

The functions generating the matches may call `compalso <name> <args>'
to let the completion code generate matches for another command named
`<name>', where the `<args>' are the words from the line (i.e. the
positional parameters). That function looks at `comps' to find the
function to call. Completion generating functions that need to do
sub-command completion (e.g. `find' between `-(ok|exec)' and `\;') can 
simple call `_normal' to do the completion-lookup and match-generation 
on the word-range which is normally set by invoking one of the
modifying condition codes.

Hope this helps.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Let's finish this new completion stuff
@ 1999-02-21  3:59 Matt Armstrong
  1999-02-22  8:59 ` Peter Stephenson
  0 siblings, 1 reply; 11+ messages in thread
From: Matt Armstrong @ 1999-02-21  3:59 UTC (permalink / raw)
  To: wischnow, zsh-workers

> Before I get tired of asking the same questions again and
> again, I'll write down all the things I'm thinking about
> and which I'd like to discuss before we start implementing
> them.
>
> *Please* take the time to send comments, suggestions, answers,
> questions or whatever.

I think the completion stuff is one of the most important aspects of zsh 
(it is what motivated me to switch to zsh from tcsh).  So, I'd love to 
contribute to this discussion.

However, I must admit that I haven't understood most of the completion 
related discussion to date.  I think this is in part because it is a 
complex subject, but also because I came in in the middle of the 
development.

The thing that'd help me understand most is an easy way to see a 
function call trace when __complete_expand-or-complete and friends get 
called.  Is something like that possible?


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Let's finish this new completion stuff
@ 1999-02-19 15:21 Sven Wischnowsky
  1999-02-20 15:01 ` Peter Stephenson
  0 siblings, 1 reply; 11+ messages in thread
From: Sven Wischnowsky @ 1999-02-19 15:21 UTC (permalink / raw)
  To: zsh-workers


Before I get tired of asking the same questions again and again, I'll
write down all the things I'm thinking about and which I'd like to
discuss before we start implementing them.


*Please* take the time to send comments, suggestions, answers,
questions or whatever.


The special parameters:

- Using the positional parameters as we do now has some drawbacks. We
  could make the completion widget store them in another array but
  then the modifying tests (see below) would still change `argv'
  unless we make the test get the name of the array to work upon as an 
  argument. But then we could equally well let users use `read' to get 
  the words (which I wouldn't like but that may be only my problem).
  Of course we could also make the completion code store the words in
  an array and give them as positional parameters. The we would have
  the problem mentioned by Bart that the value of CURRENT may be off
  by one for those who use `ksharrays', unless we use the setting of
  that option when setting CURRENT in the completion code.
- I would like to remove the parameter `COMMAND' since this has
  already become yet another way to describe the context (`COMMAND' is 
  a bit of a misnomer currently). When using an array to report the
  words on the line we could store it in this array as the first word
  which should make non-automatic modification of this array
  easier. With that we could get rid of the `command' or `argument'
  CONTEXT, replacing both of them with one name.
- We could also put the `COMMAND' into the `CONTEXT' parameter which I 
  would like to replace with a associative array with keys:
  - `command'   if this is used as the replacement for `COMMAND'.
  - `redirect'  for the string of the redirection operator
  - `parameter' for the `value' and `subscript' contexts where it will 
                contain the name of the parameter
  - `type'      as the replacement for the old `CONTEXT'
  - `quote'     if we want to do this, this could be set to `single',
                `double', or the empty string giving information about 
		the quotes the completion code thinks we are in
  We may find other interesting things here and with an associative
  array it would be easy to add new types of context information.
- The example code currently uses the return value of the shell
  functions or a parameter (in the new version I just sent) to decide
  whether more completion definitions should be used. This can not be
  combined with `compcall' which currently gives no information about
  things like that. I'm not too sure about this, but maybe we would
  want to add a special parameter that will be used by `compcall' and
  that can also (of course) be used in the shell code. (Someone else
  should decide this since I don't care that much about `compctl' any
  more.)


The testing problem:

Some of the condition codes we currently have could easily be replaced
by shell code so we should probably remove them. The question was/is
with what we would replace them. There seems to be support for doing
this with a builtin and indeed some of the examples have shown that we 
sometimes only need the modification, not the result of the test. So
that is already almost decided, but I'd like to put it into a builtin
that does not only the testing. I already spoke about my wish to add a 
builtin that gives control over some of the surrounding completion
code and I'd like to put it there. That builtin would have several
options (again):

- Options to control the special parameters. For the modifications we
  could either add one option per modification (e.g. using the
  characters known from `compctl -x': `-s <str>' and the like), or use 
  (nearly) the syntax Bart sometimes used (although I don't know if
  this was suggested syntax): `-m ignored-prefix <str>'.
  With these/this option(s) the builtin would set it's return value in 
  a way that it can be used for testing, but that would only be a
  `side effect'.
  Here we could also add a built-in replacement for the `compsave' and 
  `compreset' aliases from the example code. Let's give it two options 
  to save and restore the state of all the special parameters. It
  would be the user's responsibility to make those calls symmetrical.
- Options to get information from the calling completion code,
  e.g. things like `is there already a valid list', `will menu-
  completion be used' (which would also test for automenu) and the
  like.
- Options to say what should be done with the matches genereated,
  e.g.: `list them', `don't list them', `use menu-completion', `insert 
  it into the line', etc.

I really think we should have a way to specify things like the last
ones, giving full control to the user. Later we may use this builtin
to give access to the matches already generated, allowing users to
look at them, change them, or delete them. Also we could then clean up 
the `-U' and `-m' options to `compadd' (the way Peter already suggested
it): making `compadd' do matching unless the `-U' option is used and
remove the `-m' option. What keeps me from doing this already is that
`-U' switches on menu-completion which is not what one wants if the
function using `compadd' did the matching.


Miscellaneous:

- As Bart already said, the name `complist' is a misnomer (I was
  thinking about `it adds a list of matches...'). Any suggestion for a 
  better name from someone who knows more English synonyms or has more 
  ideas than I would be welcome (we could use `compctl' for it, making 
  it behave differently when called from a completion widget...).
- Since `compctl' is already used I'd also like to hear suggestions
  for the control-builtin I proposed.
- I already spoke about the `problem' with completion after `~', `=',
  and `$' when `complist' is used. Currently the code automatically
  uses the builtin way to complete in such places. I'd like to change
  this by making `complist' behave as if it didn't know better and
  adding contexts reported to the user via the `context' parameter for 
  these circumstances. The question is: should I add contexts for `~'
  and `=' - almost doesn't look like it's worth it.
- Bart suggested making the leading underscore special in the
  `functions' builtin and `compctl -K ...'. I like this, but I'd like
  to hear what others think about it before...


Ok. I'm curious if I get answers this time.


Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

end of thread, other threads:[~1999-02-23  9:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-22 16:01 Let's finish this new completion stuff Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1999-02-23  9:08 Sven Wischnowsky
1999-02-22 10:36 Sven Wischnowsky
1999-02-22  9:44 Sven Wischnowsky
1999-02-23  5:28 ` Bart Schaefer
1999-02-22  8:50 Sven Wischnowsky
1999-02-21  3:59 Matt Armstrong
1999-02-22  8:59 ` Peter Stephenson
1999-02-19 15:21 Sven Wischnowsky
1999-02-20 15:01 ` Peter Stephenson
1999-02-22  0:15   ` 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).