about summary refs log tree commit diff
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
parentdae12df8cd7be415187cdb936e5103fb71436543 (diff)
downloadzsh-1fb9c83eb6cce967d9429aa1ee49d14c0f96d863.tar.gz
zsh-1fb9c83eb6cce967d9429aa1ee49d14c0f96d863.tar.xz
zsh-1fb9c83eb6cce967d9429aa1ee49d14c0f96d863.zip
18143: cooperation between copy-earlier-word and smart-insert-last-word
-rw-r--r--Doc/Zsh/contrib.yo49
-rw-r--r--Functions/Zle/copy-earlier-word11
-rw-r--r--Functions/Zle/smart-insert-last-word23
3 files changed, 58 insertions, 25 deletions
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 980c982a3..4f1995f6d 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -386,6 +386,23 @@ transpose-words; do
   zle -N $widget bash-$widget
 done)
 )
+tindex(copy-earlier-word)
+item(tt(copy-earlier-word))(
+This widget works like a combination of tt(insert-last-word) and
+tt(copy-prev-shell-word).  Repeated invocations of the widget retrieve
+earlier words on the relevant history line.  With a numeric argument
+var(N), insert the var(N)th word from the history line; var(N) may be
+negative to count from the end of the line.
+
+If tt(insert-last-word) has been used to retrieve the last word on a
+previous history line, repeated invocations will replace that word with
+earlier words from the same line.
+
+Otherwise, the widget applies to words on the line currently being edited.
+The tt(widget) style can be set to the name of another widget that should
+be called to retrieve words.  This widget must accept the same three
+arguments as tt(insert-last-word).
+)
 tindex(cycle-completion-positions)
 item(tt(cycle-completion-positions))(
 After inserting an unambiguous string into the command line, the new
@@ -571,13 +588,14 @@ zle -N predict-off
 bindkey '^X^Z' predict-on
 bindkey '^Z' predict-off)
 )
-findex(smart-insert-last-word)
+tindex(smart-insert-last-word)
 item(tt(smart-insert-last-word))(
 This function may replace the tt(insert-last-word) widget, like so:
 
 example(zle -N insert-last-word smart-insert-last-word)
 
-With a numeric prefix, it behaves like tt(insert-last-word), except that
+With a numeric prefix, or when passed command line arguments in a call
+from another widget, it behaves like tt(insert-last-word), except that
 words in comments are ignored when tt(INTERACTIVE_COMMENTS) is set.
 
 Otherwise, the rightmost ``interesting'' word from the previous command is
@@ -592,20 +610,6 @@ example(zle -N insert-last-assignment smart-insert-last-word
 zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*'
 bindkey '\e=' insert-last-assignment)
 )
-findex(copy-earlier-word)
-item(tt(copy-earlier-word))(
-This widget works like a combination of tt(insert-last-word) and
-tt(copy-prev-shell-word).  Repeated invocations of the widget retrieve
-earlier words on the relevant history line.  With a numeric argument
-var(N), insert the var(N)th word from the history line; var(N) may be
-negative to count from the end of the line.
-
-If tt(insert-last-word) has been used to retrieve the last word on a
-previous history line, repeated invocations will replace that word with
-earlier words from the same line.
-
-Otherwise, the widget applies to words on the line currently being edited.
-)
 enditem()
 
 subsect(Styles)
@@ -767,6 +771,19 @@ these widgets display a message below the prompt when the predictive state
 is toggled.  This is most useful in combination with the tt(toggle) style.
 The default does not display these messages.
 )
+kindex(widget, widget style)
+item(tt(widget))(
+This style is similar to the tt(command) style: For widget functions that
+use tt(zle) to call other widgets, this style can sometimes be used to
+override the widget which is called.  The context for this style is the
+name of the calling widget (em(not) the name of the calling function,
+because one function may be bound to multiple widget names).
+
+example(zstyle :copy-earlier-word widget smart-insert-last-word)
+
+Check the documentation for the calling widget or function to determine
+whether the tt(widget) style is used.
+)
 enditem()
 
 texinode(Other Functions)()(ZLE Functions)(User Contributions)
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