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

Re: Bug#270632: zsh: Completion and spaces



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