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

Re: up-line-or-search question

On Wed, Mar 27, 2002 at 10:19:23AM -0800, Bart Schaefer wrote:
> Search up successfully, and then immediately try to search down again?

That now works. I probably had something messed up yesterday.

> E.g., change :predict to :zle:predict ?


> I wish we'd thought about that sooner ... it's not a bad idea, but it
> means changing predict-on, incremental-complete-word, etc. ... maybe
> we can use the excuse of differentiating complex stateful widgets from
> simple zle functions.

I would be inclined to change them anyway but if it worries you, we could
use something like:

zstyle -t :zle:predict verbose || zle -t :predict verbose

I've put the functions below in a recent form but without some of my
weirder additions. Suggestions on suitable shortenings for the style
contexts welcome. Or any other changes?

I've also added another bit to the up-line function which causes it
to still do an up-history if the search failed but we are not
currently in a search. This allows it to still be clear when a
search reaches it's end but it will still go up when searching isn't
going to do anything. Any views on this? Perhaps it also needs
a style. Note that a corresponding change to the down function
would be needed.


up-line-or-beginning-search() {
  [[ $LASTWIDGET != $__searching ]]
  local insearch=$?

  if [[ $LBUFFER == *$'\n'* ]]; then
    zle .up-line-or-history
  elif [[ -n $PREBUFFER ]] && 
      zstyle -t ':zle:up-line-or-beginning-search' edit-buffer
    zle .push-line-or-edit
    (( insearch )) && CURSOR=$__savecursor
    if ! zle .history-beginning-search-backward && (( ! insearch )); then
      zle .up-history
    zstyle -T ':zle:up-line-or-beginning-search' leave-cursor &&
        zle .end-of-line

down-line-or-beginning-search() {
  if [[ ${+NUMERIC} -eq 0 &&
      ( $LASTWIDGET = $__searching || $RBUFFER != *$'\n'* ) ]]
    [[ $LASTWIDGET = $__searching ]] && CURSOR=$__savecursor
    if zle .history-beginning-search-forward; then
      [[ $RBUFFER = *$'\n'* ]] || 
          zstyle -T ':zle:down-line-or-beginning-search' leave-cursor &&
	  zle .end-of-line
    [[ $RBUFFER = *$'\n'* ]] || return
  zle .down-line-or-history

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.

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