summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Zle/.distfiles1
-rw-r--r--Functions/Zle/match-word-context48
-rw-r--r--Functions/Zle/match-words-by-style26
3 files changed, 55 insertions, 20 deletions
diff --git a/Functions/Zle/.distfiles b/Functions/Zle/.distfiles
index fdf282ab5..276f17b33 100644
--- a/Functions/Zle/.distfiles
+++ b/Functions/Zle/.distfiles
@@ -11,6 +11,7 @@ incarg                         incremental-complete-word
 insert-composed-char           insert-files                   
 insert-unicode-char            keeper                         
 keymap+widget                  kill-word-match                
+match-word-context
 match-words-by-style           narrow-to-region               
 narrow-to-region-invisible     predict-on                     
 quote-and-complete-word        read-from-minibuffer           
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
diff --git a/Functions/Zle/match-words-by-style b/Functions/Zle/match-words-by-style
index def43f2e9..ad74a984f 100644
--- a/Functions/Zle/match-words-by-style
+++ b/Functions/Zle/match-words-by-style
@@ -71,9 +71,10 @@ local wordstyle spacepat wordpat1 wordpat2 opt charskip wordchars wordclass
 local match mbegin mend pat1 pat2 word1 word2 ws1 ws2 ws3 skip
 local nwords MATCH MBEGIN MEND
 
-if [[ -z $curcontext ]]; then
-    local curcontext=:zle:match-words-by-style
-fi
+local curcontext=${curcontext:-:zle:match-words-by-style}
+
+autoload -U match-word-context
+match-word-context
 
 while getopts "w:s:c:C:" opt; do
   case $opt in
@@ -108,27 +109,12 @@ case $wordstyle in
 	  # This splits the line into words as the shell understands them.
 	  bufwords=(${(z)LBUFFER})
 	  nwords=${#bufwords}
-	  # Work around bug: if stripping quotes failed, a bogus
-	  # space is appended.  Not a good test, since this may
-	  # be a quoted space, but it's hard to get right.
-	  wordpat1=${bufwords[-1]}
-	  if [[ ${wordpat1[-1]} = ' ' ]]; then
-	    wordpat1=${(q)wordpat1[1,-2]}
-	  else
-	    wordpat1="${(q)wordpat1}"
-	  fi
+	  wordpat1="${(q)bufwords[-1]}"
 
 	  # Take substring of RBUFFER to skip over $skip characters
 	  # from the cursor position.
 	  bufwords=(${(z)RBUFFER[1+$skip,-1]})
-	  # Work around bug again.
-	  wordpat2=${bufwords[1]}
-	  if [[ ${wordpat2[-1]} = ' ' ]]
-	  then
-	    wordpat2=${(q)wordpat2[1,-2]}
-	  else
-	    wordpat2="${(q)wordpat2}"
-	  fi
+	  wordpat2="${(q)bufwords[1]}"
 	  spacepat='[[:space:]]#'
 
 	  # Assume the words are at the top level, i.e. if we are inside