Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Ability to set HISTNO to a certain position from within zshrc

This is quite a bit later, but here it goes....
--- Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> } It almost seems like there should be a infer-back-into-history, where it
> } determines the inferred line, and jumps to it in history.
> Isn't that what history-search-backward does?
History-search-backward looks at the first word of the current line, and then
searches for the next line back in history that starts with the same first

The "infer" widgets are funkier search widgets, they look at the previous
history line, look back past that line in history for that same line, and then
return the line following it.  Though it looks like all the infer widgets copy
the inferred line, none change HISTNO back to that line.

> } Maybe even an accept-and-down-history-or-infer, which accepts,
> } attempts to go down in history, and if at the end of the history,
> } attempts to infer the next command.
> I think all the tools are available to write this as a user-defined widget.
> As a crude stab at it:
> aadhoi () {
>     local buffer="$BUFFER"
>     if zle down-history
>     then
>     	zle up-history
> 	BUFFER="$buffer"
> 	zle accept-line-and-down-history
>     else
> 	zle -U $'\exinfer-next-history\n'
> 	zle accept-and-hold
>     fi
> }

I tried this. (And thanks for the code!)  Though, I wasn't able to get it to
hit the else case. (Probably I'm doing something silly.) I looked at the zshzle
man page, it doesn't really say what kind of return value to expect from
down-history.  I looked at the source code for downhistory (I didn't look at
the code for those functions it called) and it looked that it would always
succeed if nohistbeep was set(!?). I didn't have it set, but tried using setopt
to change it without success.

As I said in the original message, I just wanted to set HISTNO from my .zshrc.
Though that's not possible.  It seems like some simple functionality is
missing; the ability to go to a history entry, and the ability to figure out
what the last entry is.  In some ways it seems like the zle widgets are not
fully oriented towards writing zle widgets. 

Though it is very easy to modify history by adding entries to history.  Based
on the code you sent, it even seems like it is difficult within a widget to
figure out if you're at the end of history.  You have to do an indirect test,
attempt to do a down-history and if that fails you are at the end.  


Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

Messages sorted by: Reverse Date, Date, Thread, Author