zsh-workers
 help / color / mirror / code / Atom feed
* configuration question
@ 1999-08-05 13:33 Wim Yedema
  1999-08-05 14:07 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Wim Yedema @ 1999-08-05 13:33 UTC (permalink / raw)
  To: zsh-workers

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?

wim yedema


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

* Re: configuration question
  1999-08-05 13:33 configuration question Wim Yedema
@ 1999-08-05 14:07 ` Peter Stephenson
  1999-08-05 16:00   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 1999-08-05 14:07 UTC (permalink / raw)
  To: zsh-workers

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@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


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

* Re: configuration question
  1999-08-05 14:07 ` Peter Stephenson
@ 1999-08-05 16:00   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1999-08-05 16:00 UTC (permalink / raw)
  To: zsh-workers

On Aug 5,  4:07pm, Peter Stephenson wrote:
} Subject: Re: configuration question
}
} Wim Yedema wrote:
} > I'd like replace self-insert with a function that automatically
} > does something like "history-beginning-search-backward"
} 
} I got the following to work

A couple of minor adjustments:

    predict-on() {
	zle -N self-insert insert-and-predict
	zle -N magic-space insert-and-predict
    }
    predict-off() {
	zle -A .self-insert self-insert
	zle -A .magic-space magic-space
    }

The whole idea is actually pretty cool.

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

I'll bet, especially considering that you did.


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


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

end of thread, other threads:[~1999-08-05 16:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-05 13:33 configuration question Wim Yedema
1999-08-05 14:07 ` Peter Stephenson
1999-08-05 16:00   ` 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).