zsh-users
 help / color / mirror / code / Atom feed
* history-incremental-search-backward with a twist
@ 2001-09-28 21:16 Hannu Koivisto
  2001-09-29  1:41 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Hannu Koivisto @ 2001-09-28 21:16 UTC (permalink / raw)
  To: Zsh Users' List

Greetings,

What would I have to do if I wanted to have commands that work just
like history-incremental-search-{forward,backward} but consider
only history elements that start with what is written on the
command line at the time of invocation of such a searching command?
That is, if I say...

scp -r ssdlkjsd foo:<RET>
echo foo<RET>
scp^Rfoo

...with such a modified history-incremental-search-backward command
bound to ^R, I'd like it to find that first line immediately and
not "echo foo" which is what current
history-incremental-search-backward would find.

-- 
Hannu
Please don't send copies of list mail


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

* Re: history-incremental-search-backward with a twist
  2001-09-28 21:16 history-incremental-search-backward with a twist Hannu Koivisto
@ 2001-09-29  1:41 ` Bart Schaefer
  2001-09-29  2:41   ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2001-09-29  1:41 UTC (permalink / raw)
  To: Hannu Koivisto, zsh-users

On Sep 29, 12:16am, Hannu Koivisto wrote:
}
} What would I have to do if I wanted to have commands that work just
} like history-incremental-search-{forward,backward} but consider
} only history elements that start with what is written on the
} command line at the time of invocation of such a searching command?

Presuming you have 4.0.x, this is ridiculously easy ...

    function beginning-incremental-search {
	zle .${WIDGET/beginning/history} $LBUFFER
    }
    zle -N beginning-incremental-search-backward beginning-incremental-search
    zle -N beginning-incremental-search-forward beginning-incremental-search

    bindkey "^R" beginning-incremental-search-backward

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: history-incremental-search-backward with a twist
  2001-09-29  1:41 ` Bart Schaefer
@ 2001-09-29  2:41   ` Bart Schaefer
  2001-09-29 14:51     ` Hannu Koivisto
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2001-09-29  2:41 UTC (permalink / raw)
  To: Hannu Koivisto, zsh-users

On Sep 29,  1:41am, Bart Schaefer wrote:
}
} Presuming you have 4.0.x, this is ridiculously easy ...

Except that I forgot about the silly problem with repeating the keystroke;
the "minibuffer" doesn't really have a "keymap", so you have to name the
widget the right thing.  Like so:

    function beginning-incremental-search {
	if [[ $LASTWIDGET == $WIDGET ]]
	then zle .$WIDGET
	else zle .$WIDGET $LBUFFER
	fi
    }

    zle -N history-incremental-search-backward beginning-incremental-search
    zle -N history-incremental-search-forward beginning-incremental-search

Which means you can't use the old history-incremental-search-* any more if
you want this variant to work.

Note to zsh-workers:  We really need to get real keymaps in there.  It
shouldn't even be very difficult any more, at least in the -dev version.

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: history-incremental-search-backward with a twist
  2001-09-29  2:41   ` Bart Schaefer
@ 2001-09-29 14:51     ` Hannu Koivisto
  2001-09-29 17:17       ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Hannu Koivisto @ 2001-09-29 14:51 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer <schaefer@brasslantern.com> writes:

| On Sep 29,  1:41am, Bart Schaefer wrote:
| }
| } Presuming you have 4.0.x, this is ridiculously easy ...

I have 4.0.2, running on Debian GNU/Linux unstable x86; sorry I
forgot to mention this.

|     function beginning-incremental-search {
| 	if [[ $LASTWIDGET == $WIDGET ]]
| 	then zle .$WIDGET
| 	else zle .$WIDGET $LBUFFER
| 	fi
|     }
| 
|     zle -N history-incremental-search-backward beginning-incremental-search
|     zle -N history-incremental-search-forward beginning-incremental-search

This doesn't seem to do what I want.  Let's try again.  If, after
evaluating that, I say:

dir bar foo
echo foo
dir^Rfoo

I see:

[my-prompt] dir
failing bck-i-search: dirfoo_

whereas I expected it to find "dir bar foo" history entry.  That
is, your change seems to insert to the bck-i-search: -prompt, as if
I had written it, what I have on the command line at the moment I
invoke the search.  In order to do what I want, such insertion
would work only if a) the search would be regexp search and b) it
inserted "^<what I have on the command line>.*" instead of just
"<what I have on the command line>".

| Which means you can't use the old history-incremental-search-* any more if
| you want this variant to work.

This is not a problem; I don't think I have any use for normal
history-incremental-search-* behaviour.

-- 
Hannu
Please don't send copies of list mail


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

* Re: history-incremental-search-backward with a twist
  2001-09-29 14:51     ` Hannu Koivisto
@ 2001-09-29 17:17       ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2001-09-29 17:17 UTC (permalink / raw)
  To: Hannu Koivisto, zsh-users

On Sep 29,  5:51pm, Hannu Koivisto wrote:
} Subject: Re: history-incremental-search-backward with a twist
}
} |     function beginning-incremental-search {
} | 	if [[ $LASTWIDGET == $WIDGET ]]
} | 	then zle .$WIDGET
} | 	else zle .$WIDGET $LBUFFER
} | 	fi
} |     }
} | 
} |     zle -N history-incremental-search-backward beginning-incremental-search
} |     zle -N history-incremental-search-forward beginning-incremental-search
} 
} This doesn't seem to do what I want.   [...]  That
} is, your change seems to insert to the bck-i-search: -prompt, as if
} I had written it, what I have on the command line at the moment I
} invoke the search.

Everything to the left of the cursor at the moment you invoke the search,
but otherwise yes.

} In order to do what I want, such insertion
} would work only if a) the search would be regexp search and b) it
} inserted "^<what I have on the command line>.*" instead of just
} "<what I have on the command line>".

Ah.  Well, zsh doesn't have re-search, though it does recognize "^" as
anchoring to beginning of line.  So you could change one line of the
above to

    else zle .$WIDGET "^$LBUFFER"

Beyond that, try looking at Functions/Zle/incremental-complete-word in the
distribution for ideas of how to implement something more like you want.
Or Functions/Zle/predict-on might be easier to modify -- you'd have to
replace `zle .history-beginning-search-backward' with your own search.

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2001-09-29 17:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-28 21:16 history-incremental-search-backward with a twist Hannu Koivisto
2001-09-29  1:41 ` Bart Schaefer
2001-09-29  2:41   ` Bart Schaefer
2001-09-29 14:51     ` Hannu Koivisto
2001-09-29 17:17       ` 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).