Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bug#270632: zsh: Completion and spaces
- X-seq: zsh-workers 20346
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Clint Adams <schizo@xxxxxxxxxx>
- Subject: Re: Bug#270632: zsh: Completion and spaces
- Date: Thu, 9 Sep 2004 14:37:20 -0700 (PDT)
- Cc: zsh-workers@xxxxxxxxxx, 270632-submitter@xxxxxxxxxxxxxxx
- In-reply-to: <20040909151552.GA21470@xxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20040908115321.GA2417@xxxxxxxxx> <20040908180950.GC25987@xxxxxxxxxxx> <20040908194101.GD2775@xxxxxxxxx> <20040908202633.GA3130@xxxxxxxxxxx> <Pine.LNX.4.61.0409081645470.31752@xxxxxxxxxxxxxxxxxx> <20040908235639.GB6785@xxxxxxxxxxx> <Pine.LNX.4.61.0409090754020.4924@xxxxxxxxxxxxxxxxxx> <20040909151552.GA21470@xxxxxxxxxxx>
- Reply-to: zsh-workers@xxxxxxxxxx
On Thu, 9 Sep 2004, Clint Adams wrote:
> ... how about this for the zsh/parameter solution?
>
[...]
> +lastc="$history[$#history]" # Retrieve previous command
That doesn't account for $NUMERIC, nor for "holes" in the history number
sequence (the various "ignore" options) that can cause upwards movement to
skip certain numbers. That's part of the reason that I didn't try to
write this patch before ...
The following is untested.
Index: Functions/Zle/smart-insert-last-word
--- smart-insert-last-word.~1.2.~ 2003-03-14 17:27:01.000000000 -0800
+++ smart-insert-last-word 2004-09-09 14:34:57.000000000 -0700
@@ -1,7 +1,8 @@
# smart-insert-last-word
# Inspired by Christoph Lange <langec@xxxxxx> from zsh-users/3265;
# rewritten to correct multiple-call behavior after zsh-users/3270;
-# modified to work with copy-earlier-word after zsh-users/5832.
+# modified to work with copy-earlier-word after zsh-users/5832;
+# tweaked for auto-suffix-removal behavior after zsh-users/7841.
#
# This function as a ZLE widget can replace insert-last-word, like so:
#
@@ -41,7 +42,7 @@
# (($+_ilw_hist)) || integer -g _ilw_hist _ilw_count _ilw_cursor
_ilw_lcursor
integer cursor=$CURSOR lcursor=$CURSOR
-local lastcmd pattern numeric=$NUMERIC
+local lastc lastcmd pattern numeric=$NUMERIC
# Save state for repeated calls
if (( HISTNO == _ilw_hist && cursor == _ilw_cursor )); then
@@ -64,11 +65,19 @@
_ilw_hist=$HISTNO
_ilw_count=$NUMERIC
-zle .up-history || return 1 # Retrieve previous command
-lastcmd=( ${${(z)BUFFER}:#\;} ) # Split into shell words
-zle .down-history # Return to current command
-CURSOR=$cursor # Restore cursor position
-NUMERIC=${numeric:-1} # In case of fall through
+if zmodload -i zsh/parameter
+then
+ lastc=( ${(kOn)history} ) # Get all history numbers
+ (( $#lastc > NUMERIC )) || return 1 # Check for overflow
+ lastc=$history[$lastc[NUMERIC]] # Remember previous command
+else
+ zle .up-history || return 1 # Check for overflow
+ lastc=$BUFFER # Remember previous command
+ zle .down-history # Return to current command
+fi
+lastcmd=( ${${(z)lastc}:#\;} ) # Split into shell words
+CURSOR=$cursor # Restore cursor position
+NUMERIC=${numeric:-1} # In case of fall through
(( NUMERIC > $#lastcmd )) && return 1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author