mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-30 07:10:58 +02:00
18143: cooperation between copy-earlier-word and smart-insert-last-word
This commit is contained in:
parent
dae12df8cd
commit
1fb9c83eb6
3 changed files with 58 additions and 25 deletions
|
@ -386,6 +386,23 @@ transpose-words; do
|
||||||
zle -N $widget bash-$widget
|
zle -N $widget bash-$widget
|
||||||
done)
|
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)
|
tindex(cycle-completion-positions)
|
||||||
item(tt(cycle-completion-positions))(
|
item(tt(cycle-completion-positions))(
|
||||||
After inserting an unambiguous string into the command line, the new
|
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 '^X^Z' predict-on
|
||||||
bindkey '^Z' predict-off)
|
bindkey '^Z' predict-off)
|
||||||
)
|
)
|
||||||
findex(smart-insert-last-word)
|
tindex(smart-insert-last-word)
|
||||||
item(tt(smart-insert-last-word))(
|
item(tt(smart-insert-last-word))(
|
||||||
This function may replace the tt(insert-last-word) widget, like so:
|
This function may replace the tt(insert-last-word) widget, like so:
|
||||||
|
|
||||||
example(zle -N insert-last-word smart-insert-last-word)
|
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.
|
words in comments are ignored when tt(INTERACTIVE_COMMENTS) is set.
|
||||||
|
|
||||||
Otherwise, the rightmost ``interesting'' word from the previous command is
|
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:]]#=*'
|
zstyle :insert-last-assignment match '[[:alpha:]][][[:alnum:]]#=*'
|
||||||
bindkey '\e=' insert-last-assignment)
|
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()
|
enditem()
|
||||||
|
|
||||||
subsect(Styles)
|
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.
|
is toggled. This is most useful in combination with the tt(toggle) style.
|
||||||
The default does not display these messages.
|
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()
|
enditem()
|
||||||
|
|
||||||
texinode(Other Functions)()(ZLE Functions)(User Contributions)
|
texinode(Other Functions)()(ZLE Functions)(User Contributions)
|
||||||
|
|
|
@ -5,15 +5,20 @@
|
||||||
# and start from the word before last. Otherwise, it will operate on
|
# and start from the word before last. Otherwise, it will operate on
|
||||||
# the current line.
|
# the current line.
|
||||||
|
|
||||||
|
emulate -L zsh
|
||||||
|
|
||||||
if (( ${NUMERIC:-0} )); then
|
if (( ${NUMERIC:-0} )); then
|
||||||
# 1 means last word, 2 second last, etc.
|
# 1 means last word, 2 second last, etc.
|
||||||
(( __copyword = ${NUMERIC:-0} ))
|
(( __copyword = ${NUMERIC:-0} ))
|
||||||
|
zstyle -s :$WIDGET widget __copywidget
|
||||||
elif [[ -n $__copyword && $WIDGET = $LASTWIDGET ]]; then
|
elif [[ -n $__copyword && $WIDGET = $LASTWIDGET ]]; then
|
||||||
(( __copyword-- ))
|
(( __copyword-- ))
|
||||||
elif [[ $LASTWIDGET = *insert-last-word ]]; then
|
elif [[ $LASTWIDGET = *insert-last-word ]]; then
|
||||||
__copyword=-2
|
__copyword=-2
|
||||||
|
__copywidget=$LASTWIDGET
|
||||||
else
|
else
|
||||||
__copyword=-1
|
__copyword=-1
|
||||||
|
zstyle -s :$WIDGET widget __copywidget
|
||||||
fi
|
fi
|
||||||
|
|
||||||
zle .insert-last-word 0 $__copyword
|
zle ${__copywidget:-.insert-last-word} 0 $__copyword
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# smart-insert-last-word
|
# smart-insert-last-word
|
||||||
# Inspired by Christoph Lange <langec@gmx.de> from zsh-users/3265;
|
# 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:
|
# This function as a ZLE widget can replace insert-last-word, like so:
|
||||||
#
|
#
|
||||||
|
@ -50,14 +51,24 @@ else
|
||||||
NUMERIC=1
|
NUMERIC=1
|
||||||
_ilw_lcursor=$lcursor
|
_ilw_lcursor=$lcursor
|
||||||
fi
|
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_hist=$HISTNO
|
||||||
_ilw_count=$NUMERIC
|
_ilw_count=$NUMERIC
|
||||||
|
|
||||||
zle .up-history || return 1 # Retrieve previous command
|
zle .up-history || return 1 # Retrieve previous command
|
||||||
lastcmd=( ${(z)BUFFER} ) # Split into shell words
|
lastcmd=( ${${(z)BUFFER}:#\;} ) # Split into shell words
|
||||||
zle .down-history # Return to current command
|
zle .down-history # Return to current command
|
||||||
CURSOR=$cursor # Restore cursor position
|
CURSOR=$cursor # Restore cursor position
|
||||||
NUMERIC=${numeric:-1} # In case of fall through
|
NUMERIC=${numeric:-1} # In case of fall through
|
||||||
|
|
||||||
(( NUMERIC > $#lastcmd )) && return 1
|
(( NUMERIC > $#lastcmd )) && return 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue