Zsh Mailing List Archive
Messages sorted by:
PATCH: Re: Completing strings from history?
- X-seq: zsh-users 3752
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: PATCH: Re: Completing strings from history?
- Date: Tue, 27 Mar 2001 11:13:21 +0200 (MET DST)
- In-reply-to: Adam Spiers's message of Mon, 26 Mar 2001 17:47:37 +0100
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
Apologies for posting a patch to the -users list.
Adam Spiers wrote:
> I think the reason this is all such a mess is because there's no
> internal mechanism for controlling the behaviour of automenu when it
> reaches the start or end of the match list, so it had to be
> reimplemented in the shell function. Ideally the `stop' style would
> be implemented in the core of the completion code to control this, and
> which would greatly simplify the current nastiness that is
> _history_complete_word. It would also leave the core engine in charge
> of deciding when to generate the match list, rather than the current
> We could also then move the verbosity control from the `stop' style
> (which can currently be `true' or `verbose') into the `verbosity'
> style, which would make much more sense.
> Sven? ;-)
You mean the `verbose' style, I think.
Anyway. I don't want to mess with it so short before the official
release (esp. since it can be made better with the means we have now,
see below). For the time after the release I already said that I
wanted to look into moving more of the C-completion-code into shell
code (and probably integrate completion widgest better with normal zle
widgets). Then we can think about menu completion behaviour, too.
Actually I once tried to kindle interest in moving the menu completion
behaviour into shell code -- at that time I wrote the _menu completer --
but obviously nobody was interested enough, I don't have enough
experience with menu completion and was far too busy at that time
So, no I don't plan to add this to the core just now (and it would
have to be controlled by options anyway, because it's in C and that
doesn't use styles).
> Incidentally, the `Completion System Configuration' section in the
> info pages is enormous; how about splitting it up into smaller chunks?
Every volunteer is certainly welcome ;-)
Ok, below is my first attempt at making _history_complete_words
smarter. I didn't integrate Bart's changes, maybe that should be
The behaviour is now to stop at the beginning/end once. Going up or
down in the previously used direction will wrap around. Reversing the
direction when at the beginning or end will also work (at least it
works for me).
That beep was partly caused by a little quirk of the C-code. It was
the beep output when the completion is ambiguous. It was a bit ugly
that it beeped even if the old list was re-used -- the hunk in the
C-code changes that. But that means that on still gets the beep at
the first attempt and after a wrap-around. One can use `unsetopt
listbeep' to turn this particular beep off.
The function also intentionally beeps when reaching the beginning or
end. This can easily be changed or made optional using the `stop'
I hope with the style settings Bart and Adam reported the behaviour is
now good enough...
RCS file: /cvsroot/zsh/zsh/Completion/Commands/_history_complete_word,v
retrieving revision 1.10
diff -u -r1.10 _history_complete_word
--- Completion/Commands/_history_complete_word 2001/02/28 16:55:28 1.10
+++ Completion/Commands/_history_complete_word 2001/03/27 08:57:14
@@ -50,36 +50,51 @@
- if [[ -n "$compstate[old_list]" &&
- ( -n "$stop" || "$compstate[insert]" = menu ) ]] ; then
- # array of matches is newest -> oldest (reverse of history order)
- if [[ "$direction" == 'older' ]]; then
- if [[ compstate[old_insert] -eq $_hist_menu_length ||
- "$_hist_stop" == 'oldest' ]]; then
- [[ "$stop" = verbose ]] &&
- _message 'beginning of history reached'
- elif [[ "$_hist_stop" == 'newest' ]]; then
- zle -Rc
+ if [[ ( -n "$compstate[old_list]" ||
+ ( $LASTWIDGET = _history-complete-* && -n $_hist_stop ) ) &&
+ ( -n "$stop" || "$compstate[insert]" = menu ) ]]; then
+ if [[ "$direction" == older ]]; then
+ if [[ $_hist_stop = new ]]; then
+ elif [[ $_hist_stop = old ]]; then
+ elif [[ compstate[old_insert] -lt _hist_menu_length ]]; then
(( compstate[insert] = compstate[old_insert] + 1 ))
+ _message 'beginning of history reached'
+ return 1
elif [[ "$direction" == 'newer' ]]; then
- if [[ compstate[old_insert] -eq 1 || "$_hist_stop" == 'newest' ]]; then
- [[ "$stop" = verbose ]] && _message 'end of history reached'
- elif [[ "$_hist_stop" == 'oldest' ]]; then
- zle -Rc
+ if [[ $_hist_stop = old ]]; then
+ compstate[insert]=$(( $compstate[nmatches] - 1 ))
+ elif [[ $_hist_stop = new ]]; then
+ elif [[ compstate[old_insert] -gt 1 ]]; then
(( compstate[insert] = compstate[old_insert] - 1 ))
+ _message 'end of history reached'
+ return 1
+ return 0
RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v
retrieving revision 1.35
diff -u -r1.35 compresult.c
--- Src/Zle/compresult.c 2001/03/05 10:48:11 1.35
+++ Src/Zle/compresult.c 2001/03/27 08:57:14
@@ -822,7 +822,7 @@
/* At this point, we might want a completion listing. Show the listing *
* if it is needed. */
- if (isset(LISTBEEP))
+ if (isset(LISTBEEP) && !oldlist)
ret = 1;
if (uselist && (usemenu != 2 || (!listshown && !oldlist)) &&
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by: