zsh-users
 help / color / mirror / code / Atom feed
* Delaying menu completion
@ 2001-08-13 17:53 martin.ebourne
  2001-08-14  6:48 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: martin.ebourne @ 2001-08-13 17:53 UTC (permalink / raw)
  To: zsh-users


Hi,

Having decided I like this new ^Xa for expanding all matches, as suggested
by Sven, I've been inspired onto 'greater' things...

Currently I try to avoid menu completion because I prefer the old style of
stopping when an ambiguous expansion is met, and me typing a character to
resolve it. However, menu selection clearly has a significant plus side so
I'd like the option to use either. Essentially I want to complete as normal
on tab (since that's the most efficient way normally), and then press a
different key to drop into menu selection if it'll be easier.

So, what I've done is kept my curent completion settings which don't menu
complete, added the style menu = select, and bound the menu-complete widget
onto a key. In addition to being a really easy change, this does almost
exactly what I want. However,

Problem 1

It falls down with _match and _approximate. These two both launch into menu
selection on their own and I can't seem to stop them. Setting style
insert-unambiguous = yes gets me part of the way there, but they still
won't stop fully. Now obviously these completers are not particularly
useful without menu completion, but the problem here is that I want it to
wait until I ask it to do that - especially with _approximate, since I may
not be looking at the screen (or more likely the computer won't have caught
up with me), and so I'll continue typing without knowing it's entered menu
completion. And when that happens the usual result is a mess (I've had
_approximate in there for a while and almost removed it because of this).

So what I'd like is for _match and _approximate to just list the
possibilities and do nothing else if they've got nothing better to do. Then
I'll invoke menu selection and go from there. The _list completer does
something a little similar but I still want any common prefix etc added,
and I still want _complete to work as normal.

Problem 2

Currently I've bound a function key to menu-complete. However, what I'd
really like is to use the down arrow key. This would have the advantage of
putting me on the arrow keys ready for the menu selection, and seems a
logical way of dropping down on to the list. I only want the down arrow to
do this if there's already a completion list shown, because the rest of the
time I want it to have its normal use (which for me is
history-beginning-search-forward).

So I tried this:

_menu_or_down() {
  if [[ $compstate[old_list] == shown ]]
  then
    zle menu-complete
  else
    zle .history-beginning-search-forward
  fi
}

zle -C menu-or-down menu-complete _menu_or_down
bindkey "^[[B" menu-or-down

This does the test correctly but zsh complains that it isn't in ZLE when
trying to call the original widgets (which surprised me). The first one can
be replaced with _main_complete I guess, but I can't see a way round it for
the second one. Using zle -N etc makes the widget calls work but then the
compstate isn't available for testing...

Any suggestions for this?

Also, the second parameter after zle -C (menu-complete here) - the
documentation says that this is the built in widget it behaves like. I
couldn't understand from the documentation though what exactly this was
used for and why it was needed.

Cheers,

Martin.





This e-mail message is CONFIDENTIAL and may contain legally privileged
information.  If you are not the intended recipient you should not  read,
copy, distribute, disclose or otherwise use the information in this e-mail.
Please also telephone or fax us immediately and delete the message from
your system.  E-mail may be susceptible to data corruption, interception
and unauthorised amendment, and we do not accept liability for any such
corruption, interception or amendment or the consequences thereof.


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

* Re: Delaying menu completion
  2001-08-13 17:53 Delaying menu completion martin.ebourne
@ 2001-08-14  6:48 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2001-08-14  6:48 UTC (permalink / raw)
  To: martin.ebourne, zsh-users

On Aug 13,  6:53pm, martin.ebourne@arcordia.com wrote:
}
} complete, added the style menu = select, and bound the menu-complete widget
} onto a key. In addition to being a really easy change, this does almost
} exactly what I want. However,
} 
} Problem 1
} 
} It falls down with _match and _approximate. These two both launch into menu
} selection on their own and I can't seem to stop them. Setting style
} insert-unambiguous = yes gets me part of the way there, but they still
} won't stop fully.

It's hard to say exactly what's going on without knowing your styles, and
Sven may know better ... but have you tried

    zstyle ':completion::match:*' insert-unambiguous pattern
    zstyle ':completion::approximate*:*' insert-unambiguous yes

??  That seems to me to do what you want, with one caveat which I will
get to in a moment.  The reason for "approximate*" above is that the
contexts "approximate" and "correct" are never tested by themselves;
they always have the number of corrections appended.

The caveat I mentioned is that _approximate has this strange test in it:

    [[ "${#compstate[unambiguous]}" -ge "${#:-$PREFIX$SUFFIX}" ]]

That means that the unambiguous prefix must be longer than the word on
the command line.  I.e., there's no way to prevent it dropping into
menu completion unless all the matches have a common prefix longer than
what's on the line right now.  I don't remember what that was supposed
to accomplish, but it seems a rather unlikely situation.  Sven?

} Problem 2
} 
} Currently I've bound a function key to menu-complete. However, what I'd
} really like is to use the down arrow key.
} 
} So I tried this:
} 
} _menu_or_down() {
}   if [[ $compstate[old_list] == shown ]]
}   then
}     zle menu-complete
}   else
}     zle .history-beginning-search-forward
}   fi
} }
} 
} zle -C menu-or-down menu-complete _menu_or_down
} bindkey "^[[B" menu-or-down

No, you can't use "zle -C ..." there.  You're not defining a new
completion widget, you're defining an "ordinary" widget that happens
to call a completion command; and you can't call other zle commands
from a completion widget.  So what you'd want is

    zle -N menu-or-down _menu_or_down

Then "zle menu-complete" will call the completion widgets as needed.
Unfortunately $compstate[old_list] is not available until after you
enter one of the completion widgets, so you're going to need a helper
function of some kind, that will be used as the non-menu completion
widget, and that sets a global variable that can be tested in place
of $compstate when you invoke _menu_or_down.

} Also, the second parameter after zle -C (menu-complete here) - the
} documentation says that this is the built in widget it behaves like. I
} couldn't understand from the documentation though what exactly this was
} used for and why it was needed.

The code that controls the display, decides whether to expand or list
or perform menu completion, etc., is all still in C.  You can override
most of it by poking values into compstate et al., but the defaults are
set up based on the behavior indicated by zle -C.  There are probably
a few other details that I'm forgetting, as well.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2001-08-14  6:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-13 17:53 Delaying menu completion martin.ebourne
2001-08-14  6:48 ` 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).