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

Re: up-line-or-search question



On Wed, Feb 27, 2002 at 04:08:06PM +0000, Oliver Kiddle wrote:
>  --- Dominik Vogt <dominik.vogt@xxxxxx> wrote: 
> > 
> > Actually, that does not do what I want.  I'd need
> > 
> >   up-line-or-history-beginning-search-backward
> >   up-line-or-history-beginning-search-forward
> > 
> > Since I still want to be able to navigate through the lines in the
> > ZLE.
> 
> Is this closer to what you want:
> 
> up-line-or-beginning-search-backward() {
>   if [[ $LBUFFER == *$'\n'* ]]; then
>     zle up-line-or-history
>   else
>     zle history-beginning-search-backward
>   fi
> }
> 
> zle -N up-line-or-beginning-search-backward
> 
> If it is, this was discussed some time around about last November. A
> few variations on the idea were posted including a similar function for
> forward.

It's close, but not exactly what I need.  For reference, I have
attached my final solution including documentation.  Since it
contains tabs, don't simply copy-and-paste it.

Bye

Dominik ^_^  ^_^

-- 
Dominik Vogt, email: d.vogt@xxxxxxxxxxx
LifeBits Aktiengesellschaft, Albrechtstr. 9, D-72072 Tuebingen
fon: ++49 (0) 7071/7965-0, fax: ++49 (0) 7071/7965-20
###################################################################
# ZLE functions:
#   up-line-or-beginning-search-backward
#   down-line-or-beginning-search-forward
#
# If these functions are invoked if the cursor is at the beginning
# of the first line of the buffer (ignoring leading whitespace) or
# in any line except the first, they work exactly like
# up-line-or-history and down-line-or-history.  However, the
# cursor is moved to the beginning of the line afterwards. # If
# invoked when the cursor is in the first line, but not at the
# beginning of the line (leading whitespace are ignored), they
# work like history-beginning-search-backward and
# history-beginning-search-forward
###################################################################

# needed later; why doesn't zle have beginning_of_buffer and
# end-of-buffer functions?
beginning-of-buffer() {
  while [[ ! $LBUFFER == "" ]]; do
    zle beginning-of-line
  done
}
zle -N beginning-of-buffer

up-line-or-beginning-search-backward() {
  if [[ ${LBUFFER/#[ 	]#/} == "" ]]; then
    zle up-history
    zle beginning-of-line
  elif [[ $LBUFFER == *$'\n'* ]]; then
    zle up-line-or-history
  else
    zle history-beginning-search-backward
  fi
}
down-line-or-beginning-search-forward() {
  if [[ ${LBUFFER/#[ 	]#/} == "" || $LBUFFER == *$'\n'* ]]; then
    local DO_MOVE_TO_BOB=""
    if [[ ! $RBUFFER == *$'\n'* ]]; then
      DO_MOVE_TO_BOB=1
    fi
    zle down-line-or-history
    if [[ $DO_MOVE_TO_BOB == 1 ]]; then
      zle beginning-of-buffer
    fi
  else
    zle history-beginning-search-forward
  fi
}
zle -N up-line-or-beginning-search-backward
zle -N down-line-or-beginning-search-forward

#bindkey "\e[A" up-line-or-beginning-search-backward
#bindkey "\e[B" down-line-or-beginning-search-forward


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