about summary refs log tree commit diff
path: root/Functions/Zle/smart-insert-last-word
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2003-01-27 16:41:15 +0000
committerBart Schaefer <barts@users.sourceforge.net>2003-01-27 16:41:15 +0000
commit1fb9c83eb6cce967d9429aa1ee49d14c0f96d863 (patch)
treeac74015a933bc97f3284404e29ba70a8662b8a56 /Functions/Zle/smart-insert-last-word
parentdae12df8cd7be415187cdb936e5103fb71436543 (diff)
downloadzsh-1fb9c83eb6cce967d9429aa1ee49d14c0f96d863.tar.gz
zsh-1fb9c83eb6cce967d9429aa1ee49d14c0f96d863.tar.xz
zsh-1fb9c83eb6cce967d9429aa1ee49d14c0f96d863.zip
18143: cooperation between copy-earlier-word and smart-insert-last-word
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