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

Re: up-line-or-search question



On Mar 26,  2:30pm, Oliver Kiddle wrote:
} Subject: Re: up-line-or-search question
}
} I think the best to use is perhaps Martin Ebourne's from 16011. It is
} as follows though I've modified it slightly so that it will do a down
} line if we are back at the end of the history and so that you can force
} a down history with a numeric argument.

You mean this code:

}   if [[ $LASTWIDGET = $__searching || $NUMERIC -gt 0 ]] &&
}       zle .history-beginning-search-forward; then
}     __searching=$WIDGET

That doesn't look quite right to me.  If history-beginning-search-forward
fails, it may get tried *again* by the final "else" clause.  And that's
forcing a search with a numeric argument, not a down history?

Seems like it should be

down-line-or-beginning-search() {
  if [[ ${+NUMERIC} -eq 0 &&
        ( $LASTWIDGET = $__searching || $RBUFFER != *$'\n'* ) ]]
  then
    __searching=$WIDGET
    zle .history-beginning-search-forward
  else
    __searching=''
    zle .down-line-or-history
  fi
}


} Does anyone think it is worth it to incorporate Dominik Vogt's changes
} in users/4712 which basically just account for lines containing only
} spaces and tabs?

There's nothing wrong with them, but I probably wouldn't.
 
} In the function I use, I also have:
} 
}   elif [[ -n $PREBUFFER ]]; then
}     zle .push-line-or-edit
} 
} in the middle of the up-line function (unfortuately adding an
} up-line-or-history after push-line-or-edit doesn't seem to work).

Yes, I have that too.  As I've mentioned before, push-line-or-edit
has to do a trashzle() internally to force the redraw without the PS2
prompt, and that has the side-effect of aborting everything that the
editor is doing, so the function can't continue after calling it.  I
wish there were a better way.

} I was also hoping to move the cursor to the end of the line after
} searches but I can't see how I can move it back before the next search
} without using the mark.

Stash the value of CURSOR in another global, __searching_pos or some
such, and re-assign to CURSOR only when [[ -n $__searching ]].

} I was hoping someone else would answer the question in users/4735
} because I don't know the answer myself and suspect it can't be done.

Sure it can; I missed 4735 somehow.  You just append the arguments to
the `zle' command after the name of the widget.  In the case of the
specific question in 4735, it's the numeric argument, so you have to
use -n, e.g.:

	zle .vi-fetch-history -n $NUMERIC

I forget whether the default is to propagate $NUMERIC (i.e. if the above
is redundant and you only need -n to change the value).

-- 
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   



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