Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: matlab-history-beginning-search-backward
- X-seq: zsh-users 14444
- From: Guido van Steen <gvsteen@xxxxxxxxx>
- To: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Subject: Re: matlab-history-beginning-search-backward
- Date: Wed, 30 Sep 2009 15:38:22 -0700 (PDT)
- Cc: zsh-users@xxxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1254350302; bh=+AANR6vHfxv0bED3o0E6nxyCQKTiQq7veTypjP34o74=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=je+9FBUvQNKhQ/0dXbffUU7+eDDTBSRWKtygbLpt7aJYMTHOClvTEvsFpNHiop6ue+uLkXpYk0/sMvGvlCX3umVxYTtZCvXax/2tTZzDk34K9vpjwanGdeg5sbJpvIVMVCk51lSmouhtsua3NQyjW1BeBLMkFjEdMVCAMEQaUAo=
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=d2MV1Qeyk1PcbwUz88HgiF+GOvRTuU8zA/I3V3ghnxGK4xMFKcVh5BJ1hhbYcGwPTLiKzDWgaJZ8BF1d+TE4v63sKGAxrw4nvUTd4bb92yiUMgh7he2uCaFPD2IZ5YVfAT9hDQcUqoCkQy9iVaeaU2dqyirxC07TzHZbmtWjw7o=;
- In-reply-to: <20090930205339.7dbad268@pws-pc>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
Hi Peter,
Awesome! This works exactly like what I had in mind. As an exercise for myself I may try to add some cursor handling.
Thank you very, very much!!!
Guido
--- On Wed, 9/30/09, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
> Subject: Re: matlab-history-beginning-search-backward
> To: zsh-users@xxxxxxxxxx
> Date: Wednesday, September 30, 2009, 9:53 PM
> On Wed, 30 Sep 2009 09:52:10 -0700
> (PDT)
> Guido van Steen <gvsteen@xxxxxxxxx>
> wrote:
> > I use the "history-beginning-search-backward" widget
> quite
> > frequently. It searches for commands in the command
> history that START
> > WITH "LBUFFER".
> >
> > I like this behaviour. It is simple and it keeps my
> attention fixed on
> > one line. What I don't like about the widget is that
> ONLY searches for
> > commands that start with "LBUFFER". Instead I would
> prefer a similar
> > widget that searches for commands in the command
> history, in such a way
> > that "LBUFFER" is a SUBSTRING of these commands.
>
> (I moved this to zsh-users.)
>
> This seemed to work. I stole a lot of it from
> history-beginning-search-menu. It implements forward
> and backward
> searches, so you can do something like
>
> zle -N history-substring-search-forward
> history-substring-search-backward
> zle -N history-substring-search-backward
> bindkey '\ep' history-substring-search-backward
> bindkey '\en' history-substring-search-forward
>
> At this point, it is traditional for people to say it's
> absolutely
> crucial that the cursor be posititioned etc. etc...
>
> pws
>
>
> # history-substring-search-backward
> # can also be used for the widget
> history-substring-search-forward.
>
> emulate -L zsh
> setopt extendedglob
>
> zmodload -i zsh/parameter
>
> local search=$LBUFFER MATCH MBEGIN MEND
>
> typeset -g ZLE_HISTORY_SUBSTRING_MATCH
>
> if [[ $LASTWIDGET = history-substring-search-* ]]; then
> # here's one I prepared earlier
> search=$ZLE_HISTORY_SUBSTRING_MATCH
> else
> # We need to quote metacharacters in the search
> string
> # since they are otherwise active in the reverse
> subscript.
> # We need to avoid quoting other characters since
> they aren't
> # and just stay quoted, rather annoyingly.
>
> search=${LBUFFER//(#m)[\][()\\*?#<>~^]/\\$MATCH}
> ZLE_HISTORY_SUBSTRING_MATCH=$search
> fi
>
> local -aU matches
> matches=(${(kon)history[(R)*${search}*]})
>
> # Filter out any match that's the same as the original.
> # Note this isn't a pattern this time.
> matches=(${matches:#${LBUFFER}})
>
> (( ${#matches} )) || return 1
>
> if [[ $WIDGET = *forward* ]]; then
> eval "matches=(\${matches:#<-$HISTNO>})"
> (( ${#matches} )) || return 1
> HISTNO=${matches[1]}
> else
> eval "matches=(\${matches:#<$HISTNO->})"
> (( ${#matches} )) || return 1
> HISTNO=${matches[-1]}
> fi
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author