about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Ackersviller <packersv@users.sourceforge.net>2007-11-26 03:41:21 +0000
committerPaul Ackersviller <packersv@users.sourceforge.net>2007-11-26 03:41:21 +0000
commit53d894e7a368c782abbab56dc7f5048851a69138 (patch)
treeaff4ad7d08d096a50ff11debac38de8d894fdec7
parent1d63bd904a08d0836b5f2248ce8dde47986242dd (diff)
downloadzsh-53d894e7a368c782abbab56dc7f5048851a69138.tar.gz
zsh-53d894e7a368c782abbab56dc7f5048851a69138.tar.xz
zsh-53d894e7a368c782abbab56dc7f5048851a69138.zip
Merge of Mikael Magnusson: 24076, 24081, 24082: need to cancel option
processing with -- after widget calls with arguments.
-rw-r--r--Doc/Zsh/zle.yo14
-rw-r--r--Functions/Zle/backward-kill-word-match35
-rw-r--r--Functions/Zle/delete-whole-word-match55
-rw-r--r--Functions/Zle/kill-word-match34
4 files changed, 137 insertions, 1 deletions
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 5bb76ff35..d45c71ab3 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -544,7 +544,19 @@ saved and then restored after the call to tt(widget); `tt(-n) var(num)'
 sets the numerical argument temporarily to var(num), while `tt(-N)' sets it
 to the default, i.e. as if there were none.
 
-Any further arguments will be passed to the widget.  If it is a shell
+With the option tt(-K), var(keymap) will be used as the current keymap
+during the execution of the widget.  The previous keymap will be
+restored when the widget exits.
+
+Normally, calling a widget in this way does not set the special
+parameter tt(WIDGET) and related parameters, so that the environment
+appears as if the top-level widget called by the user were still
+active.  With the option tt(-w), tt(WIDGET) and related parameters are set
+to reflect the widget being executed by the tt(zle) call.
+
+Any further arguments will be passed to the widget; note that as
+standard argument handling is performed, any general argument list
+should be preceded by tt(-)tt(-).  If it is a shell
 function, these are passed down as positional parameters; for builtin
 widgets it is up to the widget in question what it does with them.
 Currently arguments are only handled by the incremental-search commands,
diff --git a/Functions/Zle/backward-kill-word-match b/Functions/Zle/backward-kill-word-match
new file mode 100644
index 000000000..ded4db2b5
--- /dev/null
+++ b/Functions/Zle/backward-kill-word-match
@@ -0,0 +1,35 @@
+emulate -L zsh
+setopt extendedglob
+
+autoload match-words-by-style
+
+local curcontext=":zle:$WIDGET" word done
+local -a matched_words
+integer count=${NUMERIC:-1}
+
+if (( count < 0 )); then
+  (( NUMERIC = -count ))
+  zle ${WIDGET##backward-}
+  return
+fi
+
+while (( count-- )); do
+
+  match-words-by-style
+
+  word="$matched_words[2]$matched_words[3]"
+
+  if [[ -n $word ]]; then
+    if [[ -n $done || $LASTWIDGET = *kill* ]]; then
+      CUTBUFFER="$word$CUTBUFFER"
+    else
+      zle copy-region-as-kill -- "$word"
+    fi
+    LBUFFER=$matched_words[1]
+  else
+    return 1
+  fi
+  done=1
+done
+
+return 0
diff --git a/Functions/Zle/delete-whole-word-match b/Functions/Zle/delete-whole-word-match
new file mode 100644
index 000000000..5b31ad5b0
--- /dev/null
+++ b/Functions/Zle/delete-whole-word-match
@@ -0,0 +1,55 @@
+# Delete the entire word around the cursor.  Does not handle
+# a prefix argument; either the cursor is in the word or it isn't.
+# The word may be just before the cursor, e.g.
+#   print this is a line
+#             ^ here
+# and then the word before (i.e. `this') will be deleted.
+#
+# If the widget has the name `kill' in, the text deleted will be
+# saved for future yanking in the normal way.
+
+emulate -L zsh
+setopt extendedglob
+
+local curcontext=:zle:$WIDGET
+local -a matched_words
+# Start and end of range of characters to remove.
+integer pos1 pos2
+
+autoload -U match-words-by-style
+match-words-by-style
+
+if [[ -n "${matched_words[3]}" ]]; then
+    # There's whitespace before the cursor, so the word we are deleting
+    # starts at the cursor position.
+    pos1=$CURSOR
+else
+    # No whitespace before us, so delete any wordcharacters there.
+    pos1="${#matched_words[1]}"
+fi
+
+if [[ -n "${matched_words[4]}" ]]; then
+    # There's whitespace at the cursor position, so only delete
+    # up to the cursor position.
+    (( pos2 = CURSOR + 1 ))
+else
+    # No whitespace at the cursor position, so delete the
+    # current character and any following wordcharacters.
+    (( pos2 = CURSOR + ${#matched_words[5]} + 1 ))
+fi
+
+# Move the cursor then delete the block in one go for the
+# purpose of undoing (and yanking, if appropriate).
+(( CURSOR = pos1 ))
+
+# If the widget name includes the word `kill', the removed
+# text goes into the cutbuffer in the standard way.
+if [[ $WIDGET = *kill* ]]; then
+  local word="${BUFFER[pos1+1,pos2-1]}"
+  if [[ $LASTWIDGET = *kill* ]]; then
+    CUTBUFFER="$CUTBUFFER$word"
+  else
+    zle copy-region-as-kill -- "$word"
+  fi
+fi
+BUFFER="${BUFFER[1,pos1]}${BUFFER[pos2,-1]}"
diff --git a/Functions/Zle/kill-word-match b/Functions/Zle/kill-word-match
new file mode 100644
index 000000000..5fcaeb86c
--- /dev/null
+++ b/Functions/Zle/kill-word-match
@@ -0,0 +1,34 @@
+emulate -L zsh
+setopt extendedglob
+
+autoload match-words-by-style
+
+local curcontext=":zle:$WIDGET" word done
+local -a matched_words
+integer count=${NUMERIC:-1}
+
+if (( count < 0 )); then
+  (( NUMERIC = -count ))
+  zle backward-$WIDGET
+  return
+fi
+
+while (( count-- )); do
+  match-words-by-style
+
+  word="${(j..)matched_words[4,5]}"
+
+  if [[ -n $word ]]; then
+    if [[ -n $done || $LASTWIDGET = *kill* ]]; then
+      CUTBUFFER="$CUTBUFFER$word"
+    else
+      zle copy-region-as-kill -- $word
+    fi
+    RBUFFER=${(j..)matched_words[6,7]}
+  else
+    return 1
+  fi
+  done=1
+done
+
+return 0