summary refs log tree commit diff
path: root/Functions/Zle/smart-insert-last-word
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Zle/smart-insert-last-word')
-rw-r--r--Functions/Zle/smart-insert-last-word23
1 files changed, 17 insertions, 6 deletions
diff --git a/Functions/Zle/smart-insert-last-word b/Functions/Zle/smart-insert-last-word
index 512e118fe..380c19954 100644
--- a/Functions/Zle/smart-insert-last-word
+++ b/Functions/Zle/smart-insert-last-word
@@ -1,6 +1,7 @@
 # smart-insert-last-word
 # Inspired by Christoph Lange <langec@gmx.de> from zsh-users/3265;
-# rewritten to correct multiple-call behavior after zsh-users/3270.
+# rewritten to correct multiple-call behavior after zsh-users/3270;
+# modified to work with copy-earlier-word after zsh-users/5832.
 #
 # This function as a ZLE widget can replace insert-last-word, like so:
 #
@@ -50,14 +51,24 @@ else
     NUMERIC=1
     _ilw_lcursor=$lcursor
 fi
+# Handle the up to three arguments of .insert-last-word
+if (( $+1 )); then
+    if (( $+3 )); then
+	((NUMERIC = -($1)))
+    else
+	((NUMERIC = _ilw_count - $1))
+    fi
+    (( NUMERIC )) || LBUFFER[lcursor+1,cursor+1]=''
+    numeric=$((-(${2:--numeric})))
+fi
 _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
+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
 
 (( NUMERIC > $#lastcmd )) && return 1