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

Re: Wishlist for zsh: 3 tcsh features

Bart Schaefer wrote:

> On Oct 8,  6:10pm, Oliver Kiddle wrote:
> } Those two widgets annoyingly don't allow you to navigate up and down in
> } multiple line commands so you may prefer to try `up-line-or-search' and

Of course this only really matters because I'm binding to the cursor
up/down keys.

> I don't think it's possible to get more primitive than up-line-or-history,
> which goes up one line in a multi-line buffer or up one history entry at
> the beginning of the buffer.  Unless you're looking for a primitive that
> won't move out of the multi-line buffer when it reaches the top?

Yes. I had in mind using something like up-line || history-b-s-b

> Meanwhile, something like this should work:
>     function up-line-or-beginning-search {
>         if [[ $LASTWIDGET != $WIDGET ]]
>         then
>             if [[ $BUFFER == *$'\n'* ]]
>             then
>                 __last_up_line=up-line-or-history
>             else
>                 __last_up_line=history-beginning-search-backward
>             fi
>         fi
>         zle .${__last_up_line:-beep}
>     }

That is great, thanks. I never thought to check for multi-line buffers
by looking in BUFFER for a newline.

I presume that the LASTWIDGET check and __last_up_line saving is there
so that if the history search retrieved a multi-line command, it would
continue to use history-beginning-search-backward. Unfortunately, this
means it won't do a history search from the first line of a multi-line
buffer - not that that matters much - so I changed it to this:

  if [[ ${BUFFER[1,CURSOR]} == *$'\n'* ]]; then
    zle up-line-or-history
    zle history-beginning-search-backward

Please let me know if that has problems which I missed. Next I'll have
to get it to do something more useful from a PS2 prompt.


This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit

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