summaryrefslogtreecommitdiff
path: root/Functions/Zle/match-words-by-style
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-06-24 16:09:28 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-06-24 16:09:28 +0000
commit46c8127e939e9102f27c5a10733cb444bf898a30 (patch)
tree0feedbf4a1f20c2e54209f3010ae11b820542f21 /Functions/Zle/match-words-by-style
parentc52864df2fd9fbf786ecd176a21eb34763993e05 (diff)
downloadzsh-46c8127e939e9102f27c5a10733cb444bf898a30.tar.gz
zsh-46c8127e939e9102f27c5a10733cb444bf898a30.zip
25244: add subword-range style
Diffstat (limited to 'Functions/Zle/match-words-by-style')
-rw-r--r--Functions/Zle/match-words-by-style21
1 files changed, 15 insertions, 6 deletions
diff --git a/Functions/Zle/match-words-by-style b/Functions/Zle/match-words-by-style
index 1597aa694..2cbc35469 100644
--- a/Functions/Zle/match-words-by-style
+++ b/Functions/Zle/match-words-by-style
@@ -69,14 +69,14 @@ setopt extendedglob
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
+local nwords MATCH MBEGIN MEND subwordrange
local curcontext=${curcontext:-:zle:match-words-by-style}
autoload -U match-word-context
match-word-context
-while getopts "w:s:c:C:" opt; do
+while getopts "w:s:c:C:r:" opt; do
case $opt in
(w)
wordstyle=$OPTARG
@@ -94,6 +94,10 @@ while getopts "w:s:c:C:" opt; do
wordchars=$OPTARG
;;
+ (r)
+ subwordrange=$OPTARG
+ ;;
+
(*)
return 1
;;
@@ -190,6 +194,10 @@ word1=$match[1]
ws1=$match[2]
if [[ $wordstyle = *subword* ]]; then
+ if [[ -z $subwordrange ]] &&
+ ! zstyle -s $curcontext subword-range subwordrange; then
+ subwordrange='[:upper:]'
+ fi
# The rule here is that a word boundary may be an upper case letter
# followed by a lower case letter, or an upper case letter at
# the start of a group of upper case letters. To make
@@ -199,10 +207,10 @@ if [[ $wordstyle = *subword* ]]; then
# Here the initial "*" will match greedily, so we get the
# last such match, as we want.
integer epos
- if [[ $word1 = (#b)(*)([[:upper:]][^[:upper:]]*) ]]; then
+ if [[ $word1 = (#b)(*)([${~subwordrange}][^${~subwordrange}]*) ]]; then
(( epos = ${#match[1]} ))
fi
- if [[ $word1 = (#b)(*[^[:upper:]])([[:upper:]]*) ]]; then
+ if [[ $word1 = (#b)(*[^${~subwordrange}])([${~subwordrange}]*) ]]; then
(( ${#match[1]} > epos )) && (( epos = ${#match[1]} ))
fi
if (( epos > 0 )); then
@@ -226,14 +234,15 @@ if [[ $wordstyle = *subword* ]]; then
# Do we have a group of upper case characters at the start
# of word2 (that don't form the entire word)?
# Again, rely on greedy matching of first pattern.
- if [[ $word2 = (#b)([[:upper:]][[:upper:]]##)(*) && -n $match[2] ]]; then
+ if [[ $word2 = (#b)([${~subwordrange}][${~subwordrange}]##)(*) &&
+ -n $match[2] ]]; then
# Yes, so the last one is new word boundary.
(( epos = ${#match[1]} - 1 ))
# Otherwise, do we have upper followed by non-upper not
# at the start? Ignore the initial character, we already
# know it's a word boundary so it can be an upper case character
# if it wants.
- elif [[ $word2 = (#b)(?[^[:upper:]]##)[[:upper:]]* ]]; then
+ elif [[ $word2 = (#b)(?[^${~subwordrange}]##)[${~subwordrange}]* ]]; then
(( epos = ${#match[1]} ))
else
(( epos = 0 ))