about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-04-02 13:02:47 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-04-02 13:02:47 +0000
commit374b31616bbfad23f980f35d79a4202afb7367e8 (patch)
tree440f48096773d8383d1be6bda37d2821ccb03127
parent93fce8372d8a7fd0423f9683c443bf05cecd6378 (diff)
downloadzsh-374b31616bbfad23f980f35d79a4202afb7367e8.tar.gz
zsh-374b31616bbfad23f980f35d79a4202afb7367e8.tar.xz
zsh-374b31616bbfad23f980f35d79a4202afb7367e8.zip
24781: enhance word-context to use next or previous word
-rw-r--r--ChangeLog4
-rw-r--r--Doc/Zsh/contrib.yo7
-rw-r--r--Functions/Zle/match-word-context25
3 files changed, 19 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index edcde3579..28b4d8f87 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-04-02  Peter Stephenson  <pws@csr.com>
 
+	* 24781: Doc/Zsh/contrib.yo, Functions/Zle/match-word-context:
+	make word-context style more useful by using previous or next word
+	depending on widget name.
+
 	* unposted: README: minor tweaks.
 
 	* unposted: NEWS, Config/version.mk: Release 4.3.6.
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index e7ce978f6..d3dc2ac1e 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -494,9 +494,10 @@ var(pattern) and a var(subcontext).  The shell argument the cursor is on is
 matched against each var(pattern) in turn until one matches; if it does,
 the context is extended by a colon and the corresponding var(subcontext).
 Note that the test is made against the original word on the line, with no
-stripping of quotes.  If the cursor is at the end of the line the test is
-performed against an empty string; if it is on whitespace between words the
-test is made against a single space.  Some examples are given below.
+stripping of quotes.  Special handling is done between words: the current
+context is examined and if it contains the string tt(back), the word before
+the cursor is considered, else the word after cursor is considered. Some
+examples are given below.
 
 Here are some examples of use of the styles, actually taken from the
 simplified interface in tt(select-word-style):
diff --git a/Functions/Zle/match-word-context b/Functions/Zle/match-word-context
index da68b6c75..7f1154498 100644
--- a/Functions/Zle/match-word-context
+++ b/Functions/Zle/match-word-context
@@ -6,7 +6,7 @@ emulate -L zsh
 setopt extendedglob
 
 local -a worcon bufwords
-local pat tag lastword word
+local pat tag lastword word backword forword
 integer iword
 
 zstyle -a $curcontext word-context worcon || return 0
@@ -23,21 +23,18 @@ bufwords=(${(z)BUFFER})
 
 if [[ $lastword = ${bufwords[iword]} ]]; then
   # If the word immediately left of the cursor is complete,
-  # we're not on it.  Either we're on unquoted whitespace, or
-  # the start of a new word.  Test the latter.
-  if [[ -z $RBUFFER ]]; then
-    # Nothing there, so not in a word.
-      word=''
-  elif [[ $RBUFFER[1] = [[:space:]] ]]; then
-    # Whitespace, so not in a word.
-    word=' '
-  else
-    # We want the next word along.
-    word=${bufwords[iword+1]}
-  fi
+  # we're not on it for forward operations.
+  forword=${bufwords[iword+1]}
 else
   # We're on a word.
-  word=${bufwords[iword]}
+  forword=${bufwords[iword]}
+fi
+backword=${bufwords[iword]}
+
+if [[ $curcontext = *back* ]]; then
+  word=$backword
+else
+  word=$forword
 fi
 
 for pat tag in "${worcon[@]}"; do