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

Re: configuration question



Wim Yedema wrote:
> I'd like replace self-insert with a function that automatically
> does something like "history-beginning-search-backward" the problem
> with this is that it beeps when nothing is found and that the current
> history number changes, meaning that every time I type something I
> go backwards in the history even if the character that I type suits
> the current history event just fine.
> 
> I tried something like this
> 
> ---
> insert-and-predict () {
>   LBUFFER="$LBUFFER$KEYS"
>   RBUFFER=""
>   zle history-beginning-search-backward
> }
> 
> autoload insert-and-predict
> zle -N self-insert insert-and-predict
> ---
> 
> can someone stop the beep and give me the right behaviour?

Turning the beep off should be easy:  just stick `return 0' at the end of
the function --- that only works from 3.1.6, however.  The beep is
triggered by the return status of the zle command.

As for the other behaviour, I don't quite know what you're finally aiming
at (how are you going to edit the line?), but I got the following to work
by binding predict-on and predict-off:

predict-on() { zle -N self-insert insert-and-predict; }
zle -N predict-on
predict-off() { zle -A self-insert .self-insert; }
zle -N predict-off
insert-and-predict () {
  if [[ ${RBUFFER[1]} = ${KEYS[-1]} ]]; then
    # same as what's typed, just move on
    zle forward-char
  else
    LBUFFER="$LBUFFER$KEYS"
    RBUFFER=""
    zle history-beginning-search-backward
  fi
  return 0
}
zle -N insert-and-predict

It's interesting what happens if you get predict-off wrong.

Note that it's now possible to give arguments to `zle
history-search-backwards' in a widget function, which might be another way
of doing what you want.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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