about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-12-09 14:44:42 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-12-09 14:44:42 +0000
commit4419b75dbc81eff685dcb2d812280b21e8d1e25e (patch)
treeba51138e01bce2ff22ced7d38bc8fd1f548c504e
parent69b4b8bdde76b5aee6befa2b66957db22b3f6353 (diff)
downloadzsh-4419b75dbc81eff685dcb2d812280b21e8d1e25e.tar.gz
zsh-4419b75dbc81eff685dcb2d812280b21e8d1e25e.tar.xz
zsh-4419b75dbc81eff685dcb2d812280b21e8d1e25e.zip
20612: add options to match-words-by-style widget
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/contrib.yo12
-rw-r--r--Functions/Zle/match-words-by-style63
3 files changed, 65 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 4626e6bd8..464d4f1dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-12-09  Peter Stephenson  <pws@csr.com>
+
+	* 20612: Doc/Zsh/contrib.yo, Functions/Zle/match-words-by-style:
+	options to match-words-by-style can override styles.
+
 2004-12-07  Peter Stephenson  <pws@csr.com>
 
 	* 20605: Doc/Zsh/builtins.yo, Src/builtin.c, Src/exec.c,
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index b7c80211e..14a402785 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -513,6 +513,18 @@ tt(skip-chars) style, (5) the word at or following the cursor (6) any
 non-word characters following that word (7) the remainder of the line.  Any
 of the elements may be an empty string; the calling function should test
 for this to decide whether it can perform its function.
+
+It is possible to pass options with arguments to tt(match-words-by-style)
+to override the use of styles.  The options are:
+startsitem()
+sitem(tt(-w))(var(word-style))
+sitem(tt(-s))(var(skip-chars))
+sitem(tt(-c))(var(word-class))
+sitem(tt(-C))(var(word-chars))
+endsitem()
+
+For example, tt(match-words-by-style -w shell -c 0) may be used to
+extract the command argument around the cursor.
 )
 tindex(delete-whole-word-match)
 item(tt(delete-whole-word-match))(
diff --git a/Functions/Zle/match-words-by-style b/Functions/Zle/match-words-by-style
index 0ca51d4fd..9d637a587 100644
--- a/Functions/Zle/match-words-by-style
+++ b/Functions/Zle/match-words-by-style
@@ -57,12 +57,17 @@
 # will appear in <whitespace-after-cursor> if it is whitespace, else in
 # <word-after-cursor>.  This style is mostly useful for forcing
 # transposition to ignore the current character.
-
+#
+# The values of the styles can be overridden by options to the function:
+#  -w <word-style>
+#  -s <skip-chars>
+#  -c <word-class>
+#  -C <word-chars>
 
 emulate -L zsh
 setopt extendedglob
 
-local wordstyle spacepat wordpat1 wordpat2 opt charskip
+local wordstyle spacepat wordpat1 wordpat2 opt charskip wordchars wordclass
 local match mbegin mend pat1 pat2 word1 word2 ws1 ws2 ws3 skip
 local MATCH MBEGIN MEND
 
@@ -70,8 +75,32 @@ if [[ -z $curcontext ]]; then
     local curcontext=:zle:match-words-by-style
 fi
 
-zstyle -s $curcontext word-style wordstyle
-zstyle -s $curcontext skip-chars skip
+while getopts "w:s:c:C:" opt; do
+  case $opt in
+    (w)
+    wordstyle=$OPTARG
+    ;;
+
+    (s)
+    skip=$OPTARG
+    ;;
+
+    (c)
+    wordclass=$OPTARG
+    ;;
+
+    (C)
+    wordchars=$OPTARG
+    ;;
+
+    (*)
+    return 1
+    ;;
+  esac
+done
+
+[[ -z $wordstyle ]] && zstyle -s $curcontext word-style wordstyle
+[[ -z $skip ]] && zstyle -s $curcontext skip-chars skip
 [[ -z $skip ]] && skip=0
 
 case $wordstyle in
@@ -107,20 +136,24 @@ case $wordstyle in
 	   ;;
   (*) local wc
       # See if there is a character class.
-      if zstyle -s $curcontext word-class wc; then
-	  # Treat as a character class: do minimal quoting.
-	  wc=${wc//(#m)[\'\"\`\$\(\)\^]/\\$MATCH}
+      wc=$wordclass
+      if [[ -n $wc ]] || zstyle -s $curcontext word-class wc; then
+	# Treat as a character class: do minimal quoting.
+	wc=${wc//(#m)[\'\"\`\$\(\)\^]/\\$MATCH}
       else
-          # See if there is a local version of $WORDCHARS.
+	# See if there is a local version of $WORDCHARS.
+	wc=$wordchars
+	if [[ -z $wc ]]; then
 	  zstyle -s $curcontext word-chars wc ||
 	  wc=$WORDCHARS
-	  if [[ $wc = (#b)(?*)-(*) ]]; then
-              # We need to bring any `-' to the front to avoid confusing
-              # character classes... we get away with `]' since in zsh
-              # this isn't a pattern character if it's quoted.
-	      wc=-$match[1]$match[2]
-	  fi
-	  wc="${(q)wc}"
+	fi
+	if [[ $wc = (#b)(?*)-(*) ]]; then
+	  # We need to bring any `-' to the front to avoid confusing
+	  # character classes... we get away with `]' since in zsh
+          # this isn't a pattern character if it's quoted.
+	  wc=-$match[1]$match[2]
+	fi
+	wc="${(q)wc}"
       fi
       # Quote $wc where necessary, because we don't want those
       # characters to be considered as pattern characters later on.