zsh-users
 help / color / mirror / code / Atom feed
* incr. search: skip duplicates on the same history event
@ 2007-06-16 18:31 Frank Terbeck
  2007-06-16 19:03 ` Richard Hartmann
  0 siblings, 1 reply; 3+ messages in thread
From: Frank Terbeck @ 2007-06-16 18:31 UTC (permalink / raw)
  To: zsh users

Hey list,

Someone on IRC came up with the following question:

Say, you got a few history events that got the string 'make' in them:

  % make depend
  % make clean ; make all ; sudo make install

After a few more commands, you do a
'history-incremental-search-backward' for 'make' and get back the last
event with the three make calls on one line. Now you can reinvoke
'history-incremental-search-backward' again to jump back to earlier
occurrences of 'make' in the history:

  % make clean ; make all ; sudo make install
    ^            ^               ^
    |            |               |
    |            |               \-- ^Rmake
    |            |
    |            \-- 1st time you hit ^R after making
    |                your initial search.
    |
    \-- after hitting ^R for the 2nd time you end up here.

Now, the idea is to after searching backwards for the first time
(^Rmake), hitting ^R again, to go further backwards should ignore any
other occurrences of 'make' in the current history event and jump
directly to the next history event containing 'make' ('make depend')
in the example above.

I have been playing around to get this working and had a few rather
complex solutions, that all failed somehow. :-)

So, I took another approach and the closest I got (which works) is the
following. It exists the incremental search and re-enters it if you
continue typing. That is not an exceptionally nice solution and it
would require additional tweaking to become usable.

[snip]
self-insert () {
  if [[ $LASTWIDGET == incsearch ]] ; then
    zle history-incremental-search-backward $LASTSEARCH
  fi
  zle .self-insert
}
zle -N self-insert
incsearch () {
  if [[ $LASTWIDGET == incsearch ]] ; then
    zle history-search-backward
  else
    zle history-incremental-search-backward
  fi
}
zle -N incsearch
bindkey '^r' incsearch
[snap]

However, I hope that someone has got a better idea to solve this.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


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

end of thread, other threads:[~2007-06-17  0:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-16 18:31 incr. search: skip duplicates on the same history event Frank Terbeck
2007-06-16 19:03 ` Richard Hartmann
2007-06-17  0:32   ` 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).