zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-users@math.gatech.edu
Subject: User-defined replacement for *-line-or-search in 3.1.4
Date: Tue, 9 Jun 1998 13:23:19 -0700	[thread overview]
Message-ID: <980609132319.ZM7074@candle.brasslantern.com> (raw)
In-Reply-To: <980609114223.ZM6613@candle.brasslantern.com>

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


       reply	other threads:[~1998-06-09 20:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <19980428143325.59341@gmp-fores1.uk.jpmorgan.com>
     [not found] ` <199804281408.PAA32237@taos.demon.co.uk>
     [not found]   ` <19980609141304.41665@gmp-fores1.uk.jpmorgan.com>
     [not found]     ` <980609082238.ZM5717@candle.brasslantern.com>
     [not found]       ` <vbu35utvzk.fsf@snake.isode.com>
     [not found]         ` <980609114223.ZM6613@candle.brasslantern.com>
1998-06-09 20:23           ` Bart Schaefer [this message]
1998-06-10  4:25             ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=980609132319.ZM7074@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).