about summary refs log tree commit diff
path: root/Functions/Zle/match-word-context
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-08-14 16:14:41 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-08-14 16:14:41 +0000
commit3a97920199accf4f63b622645ea208ccad42d07b (patch)
treec3232175e212b0c2c07e8c628d9eed757666a7a9 /Functions/Zle/match-word-context
parentf2dbedcc4f878e4eb35f72899feec7593d920c5a (diff)
downloadzsh-3a97920199accf4f63b622645ea208ccad42d07b.tar.gz
zsh-3a97920199accf4f63b622645ea208ccad42d07b.tar.xz
zsh-3a97920199accf4f63b622645ea208ccad42d07b.zip
22606: add match-word-context.
Remove workaround from match-words-by-style
Diffstat (limited to 'Functions/Zle/match-word-context')
-rw-r--r--Functions/Zle/match-word-context48
1 files changed, 48 insertions, 0 deletions
diff --git a/Functions/Zle/match-word-context b/Functions/Zle/match-word-context
new file mode 100644
index 000000000..da68b6c75
--- /dev/null
+++ b/Functions/Zle/match-word-context
@@ -0,0 +1,48 @@
+# See if we can extend the word context to something more specific.
+# curcontext must be set to the base context by this point; it
+# will be appended to directly.
+
+emulate -L zsh
+setopt extendedglob
+
+local -a worcon bufwords
+local pat tag lastword word
+integer iword
+
+zstyle -a $curcontext word-context worcon || return 0
+
+if (( ${#worcon} % 2 )); then
+  zle -M "Bad word-context style in context $curcontext"
+  return
+fi
+
+bufwords=(${(z)LBUFFER})
+iword=${#bufwords}
+lastword=${bufwords[-1]}
+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
+else
+  # We're on a word.
+  word=${bufwords[iword]}
+fi
+
+for pat tag in "${worcon[@]}"; do
+  if [[ $word = ${~pat} ]]; then
+    curcontext+=":$tag"
+    return
+  fi
+done