summaryrefslogtreecommitdiff
path: root/Functions/Zle/match-words-by-style
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-12-09 17:26:35 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-12-09 17:26:35 +0000
commit6f5b07da730ada1de1104a3c830c90ea7e6a6541 (patch)
treeced7d5cfae88b631aa65dc374d779da82b7f7920 /Functions/Zle/match-words-by-style
parent4419b75dbc81eff685dcb2d812280b21e8d1e25e (diff)
downloadzsh-6f5b07da730ada1de1104a3c830c90ea7e6a6541.tar.gz
zsh-6f5b07da730ada1de1104a3c830c90ea7e6a6541.zip
20613: fix inconsistencies with embedded whitespace in match-words-by-style
Diffstat (limited to 'Functions/Zle/match-words-by-style')
-rw-r--r--Functions/Zle/match-words-by-style22
1 files changed, 20 insertions, 2 deletions
diff --git a/Functions/Zle/match-words-by-style b/Functions/Zle/match-words-by-style
index 9d637a587..277fe058f 100644
--- a/Functions/Zle/match-words-by-style
+++ b/Functions/Zle/match-words-by-style
@@ -69,13 +69,13 @@ setopt extendedglob
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
+local nwords MATCH MBEGIN MEND
if [[ -z $curcontext ]]; then
local curcontext=:zle:match-words-by-style
fi
-while getopts "w:s:c:C:" opt; do
+while getopts "w:s:c:C:tT" opt; do
case $opt in
(w)
wordstyle=$OPTARG
@@ -107,6 +107,7 @@ case $wordstyle in
(shell) local bufwords
# 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.
@@ -129,6 +130,23 @@ case $wordstyle in
wordpat2="${(q)wordpat2}"
fi
spacepat='[[:space:]]#'
+
+ # Assume the words are at the top level, i.e. if we are inside
+ # 'something with spaces' then we need to ignore the embedded
+ # spaces and consider the whole word.
+ bufwords=(${(z)BUFFER})
+ if (( ${#bufwords[$nwords]} > ${#wordpat1} )); then
+ # Yes, we're in the middle of a shell word.
+ # Find out what's in front.
+ eval pat1='${LBUFFER%%(#b)('${wordpat1}')('${spacepat}')}'
+ # Now everything from ${#pat1}+1 is wordy
+ wordpat1=${(q)LBUFFER[${#pat1}+1,-1]}
+
+ # Likewise at the end...
+ eval pat2='${RBUFFER##(#b)('${charskip}${spacepat}')('\
+${wordpat2}')('${spacepat}')}'
+ wordpat2=${(q)RBUFFER[1,-1-${#pat2}]}
+ fi
;;
(*space) spacepat='[[:space:]]#'
wordpat1='[^[:space:]]##'