zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk
Subject: Re: configuration question
Date: Thu, 05 Aug 1999 16:07:31 +0200	[thread overview]
Message-ID: <9908051407.AA36170@ibmth.df.unipi.it> (raw)
In-Reply-To: "Wim Yedema"'s message of "05 Aug 1999 15:33:22 DFT." <uqvbtcm73od.fsf@hpas11.natlab.research.philips.com>

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


  reply	other threads:[~1999-08-05 14:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-05 13:33 Wim Yedema
1999-08-05 14:07 ` Peter Stephenson [this message]
1999-08-05 16:00   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9908051407.AA36170@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).