2003-03-28 12:34:07 +01:00
|
|
|
# Transpose words, matching the words using match-words-by-style, q.v.
|
2003-04-25 13:18:50 +02:00
|
|
|
# The group of word characters preceding the cursor (not necessarily
|
2003-03-28 12:34:07 +01:00
|
|
|
# immediately) are transposed with the group of word characters following
|
|
|
|
# the cursor (again, not necessarily immediately).
|
|
|
|
#
|
|
|
|
# Note the style skip-chars, used in the context of the current widget.
|
|
|
|
# This gives a number of character starting from the cursor position
|
|
|
|
# which are never considered part of a word and hence are always left
|
|
|
|
# alone. The default is 0 and typically the only useful alternative
|
|
|
|
# is one. This would have the effect that `fooXbar' with the cursor
|
|
|
|
# on X would be turned into `barXfoo' with the cursor still on the X,
|
|
|
|
# regardless of what the character X is.
|
|
|
|
|
|
|
|
autoload match-words-by-style
|
|
|
|
|
|
|
|
local curcontext=":zle:$WIDGET" skip
|
|
|
|
local -a matched_words
|
2003-04-03 12:24:40 +02:00
|
|
|
integer count=${NUMERIC:-1} neg
|
|
|
|
|
|
|
|
(( count < 0 )) && (( count = -count, neg = 1 ))
|
2003-03-28 12:34:07 +01:00
|
|
|
|
|
|
|
while (( count-- > 0 )); do
|
|
|
|
match-words-by-style
|
|
|
|
|
|
|
|
[[ -z "$matched_words[2]$matched_words[5]" ]] && return 1
|
|
|
|
|
2003-04-03 12:24:40 +02:00
|
|
|
if (( neg )); then
|
|
|
|
LBUFFER="$matched_words[1]"
|
|
|
|
RBUFFER="$matched_words[5]${(j..)matched_words[3,4]}\
|
|
|
|
$matched_words[2]${(j..)matched_words[6,7]}"
|
|
|
|
else
|
|
|
|
LBUFFER="$matched_words[1]$matched_words[5]${(j..)matched_words[3,4]}\
|
2003-03-28 12:34:07 +01:00
|
|
|
$matched_words[2]"
|
2003-04-03 12:24:40 +02:00
|
|
|
RBUFFER="${(j..)matched_words[6,7]}"
|
|
|
|
fi
|
2003-03-28 12:34:07 +01:00
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|