Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: is there a mix of history-search-backward and history-beginning-search-backward
- X-seq: zsh-users 2582
- From: Peter Stephenson <pws@xxxxxx>
- To: zsh-users@xxxxxxxxxxxxxx
- Subject: Re: is there a mix of history-search-backward and history-beginning-search-backward
- Date: Wed, 08 Sep 1999 17:27:57 +0200
- In-reply-to: "Andy Spiegl"'s message of "Wed, 08 Sep 1999 15:02:13 +0200." <19990908150213.D4878@xxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
Andy Spiegl wrote:
> A while ago I asked:
> >
> > I want to bind to ^P a widget that acts like
> > history-beginning-search-backward, but always moves the cursor to the end
> > of the line, like history-search-backward does. Or said the other way:
> > I want history-search-backward to look at more than the first word.
> >
> > Do you know a way to get this behavior?
>
> Does noone have any idea about this?
Sorry, I meant to try this and then got sidetracked into things like
applying patches.
I assume you're using zsh 3.1, in which case it's not so hard:
probably you need 3.1.6 for the $LASTWIDGET test to work, which is
crucial. I've called the functions
history-beginning-search-{back,for}ward-end. If you shorten the
names, you will need to change the pattern matched against
$LASTWIDGET, because the functions need to know that one of the two
was called last, and hence the position to compare up to is already
set. (Wasted ten minutes wondering why an `if' with a missing `then'
didn't work. I think we're too lenient with the syntax.)
I might put these in the Functions/Zle directory (after Bart has found out
whatever's wrong with them).
# function history-beginning-search-forward-end {
# history-beginning-search-forward, with cursor at end.
integer ocursor=$CURSOR stat
if [[ $LASTWIDGET = history-beginning-search-(back|for)ward-end ]]; then
# Last widget called set $hbs_pos.
CURSOR=$hbs_pos
else
hbs_pos=$CURSOR
fi
if zle history-beginning-search-forward; then
# success, go to end of line
zle end-of-line
else
# failure, restore position
CURSOR=$ocursor
return 1
fi
# }
# function history-beginning-search-backward-end {
# history-beginning-search-backward, with cursor at end.
integer ocursor=$CURSOR stat
if [[ $LASTWIDGET = history-beginning-search-(back|for)ward-end ]]; then
# Last widget called set $hbs_pos.
CURSOR=$hbs_pos
else
hbs_pos=$CURSOR
fi
if zle history-beginning-search-backward; then
# success, go to end of line
zle end-of-line
else
# failure, restore position
CURSOR=$ocursor
return 1
fi
# }
--
Peter Stephenson <pws@xxxxxx> 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