summaryrefslogtreecommitdiff
path: root/Functions
diff options
context:
space:
mode:
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Zle/copy-earlier-word11
-rw-r--r--Functions/Zle/smart-insert-last-word23
2 files changed, 25 insertions, 9 deletions
diff --git a/Functions/Zle/copy-earlier-word b/Functions/Zle/copy-earlier-word
index bbc8af35c..63e7edaef 100644
--- a/Functions/Zle/copy-earlier-word
+++ b/Functions/Zle/copy-earlier-word
@@ -5,15 +5,20 @@
# and start from the word before last. Otherwise, it will operate on
# the current line.
+emulate -L zsh
+
if (( ${NUMERIC:-0} )); then
- # 1 means last word, 2 second last, etc.
- (( __copyword = ${NUMERIC:-0} ))
+ # 1 means last word, 2 second last, etc.
+ (( __copyword = ${NUMERIC:-0} ))
+ zstyle -s :$WIDGET widget __copywidget
elif [[ -n $__copyword && $WIDGET = $LASTWIDGET ]]; then
(( __copyword-- ))
elif [[ $LASTWIDGET = *insert-last-word ]]; then
__copyword=-2
+ __copywidget=$LASTWIDGET
else
__copyword=-1
+ zstyle -s :$WIDGET widget __copywidget
fi
-zle .insert-last-word 0 $__copyword
+zle ${__copywidget:-.insert-last-word} 0 $__copyword
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