From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2591 invoked from network); 9 Jun 1998 20:27:30 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 9 Jun 1998 20:27:30 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id QAA19707; Tue, 9 Jun 1998 16:22:54 -0400 (EDT) Resent-Date: Tue, 9 Jun 1998 16:22:23 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980609132319.ZM7074@candle.brasslantern.com> Date: Tue, 9 Jun 1998 13:23:19 -0700 In-Reply-To: <980609114223.ZM6613@candle.brasslantern.com> Comments: In reply to "Bart Schaefer" "Re: up-line-or-search still 'fixed'!" (Jun 9, 11:42am) References: <19980428143325.59341@gmp-fores1.uk.jpmorgan.com> <199804281408.PAA32237@taos.demon.co.uk> <19980609141304.41665@gmp-fores1.uk.jpmorgan.com> <980609082238.ZM5717@candle.brasslantern.com> <980609114223.ZM6613@candle.brasslantern.com> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-users@math.gatech.edu Subject: User-defined replacement for *-line-or-search in 3.1.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"Z6gXH1.0.co4.ybPVr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1584 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu My first real attempt at a zle widget. It fudges some things, but it works better than the corresponding builtins most of the time (which is too bad). Hey, zsh-workers, read the comments, particularly about assignment to CURSOR. Shouldn't $#LBUFFER == $CURSOR == $#moveorsearchpattern on first call to this function? If so, why is the +1 necessary? (If I leave it out, the call to history-beginning-search-*ward uses too short a prefix.) --- 8< --- snip --- 8< --- function uplineorsearch () { if [[ -n "$LBUFFER" ]] then # Check whether we need to restart the search. This is crude, as # it assumes no history search begins with space (histignorespace) # and that a matching prefix of LBUFFER means repeat the search. if [[ -n "$RBUFFER" || "$LBUFFER" != ${moveorsearchpattern:-" "}* ]] then # Set the search pattern to the first word or prefix. moveorsearchpattern=(${=LBUFFER}) moveorsearchpattern=${moveorsearchpattern[1]} fi # The next test attempts to determine whether the search will # succeed or fail, so as not to move the cursor if it fails. # This may not be worth the effort ... if [[ -n "$(fc -lnm $moveorsearchpattern\* -99999 -1)" ]] then # Ideally here, this would modify the buffer to insert the # search pattern, then search, and restore the buffer in # the event of failure. Failure can't be detected, so do # less-intrusive but less-accurate cursor-fiddling tricks. # Why is +1 needed here, but not needed at $#BUFFER? CURSOR=$[$#moveorsearchpattern+1] zle history-beginning-search-backward CURSOR=$#BUFFER else zle history-search-backward # Just to get a feep fi else unset moveorsearchpattern zle up-line-or-history fi } function downlineorsearch () { # See comments in uplineorsearch. if [[ -n "$LBUFFER" ]] then if [[ -n "$RBUFFER" || "$LBUFFER" != ${moveorsearchpattern:-" "}* ]] then moveorsearchpattern=(${=LBUFFER}) moveorsearchpattern=${moveorsearchpattern[1]} fi if [[ -n "$(fc -lnm $moveorsearchpattern\* -99999 -1)" ]] then CURSOR=$[$#moveorsearchpattern+1] zle history-beginning-search-forward CURSOR=$#BUFFER else zle history-search-forward # Just to get a feep fi else unset moveorsearchpattern zle down-line-or-history fi } zle -N up-line-or-search uplineorsearch zle -N down-line-or-search downlineorsearch -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com