summary refs log tree commit diff
path: root/Functions/Zle/transpose-words-match
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2003-03-28 11:34:07 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2003-03-28 11:34:07 +0000
commit1e57c42f470bdd2ab6179ec44dae96fd3377a1dd (patch)
tree5f9c38c21bcbbcba7b7524f9df7e4f99b8344424 /Functions/Zle/transpose-words-match
parent2941469f616202f51da7ba9ceafa3f419f34573b (diff)
downloadzsh-1e57c42f470bdd2ab6179ec44dae96fd3377a1dd.tar.gz
zsh-1e57c42f470bdd2ab6179ec44dae96fd3377a1dd.tar.xz
zsh-1e57c42f470bdd2ab6179ec44dae96fd3377a1dd.zip
18394: New word movement and editing widgets.
Diffstat (limited to 'Functions/Zle/transpose-words-match')
-rw-r--r--Functions/Zle/transpose-words-match31
1 files changed, 31 insertions, 0 deletions
diff --git a/Functions/Zle/transpose-words-match b/Functions/Zle/transpose-words-match
new file mode 100644
index 000000000..52891b6ac
--- /dev/null
+++ b/Functions/Zle/transpose-words-match
@@ -0,0 +1,31 @@
+# Transpose words, matching the words using match-words-by-style, q.v.
+# The group of word characters preceeding the cursor (not necessarily
+# 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
+integer count=${NUMERIC:-1}
+
+while (( count-- > 0 )); do
+    match-words-by-style
+
+    [[ -z "$matched_words[2]$matched_words[5]" ]] && return 1
+
+    LBUFFER="$matched_words[1]$matched_words[5]${(j..)matched_words[3,4]}\
+$matched_words[2]"
+    RBUFFER="${(j..)matched_words[6,7]}"
+
+done
+
+return 0