1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-19 05:24:23 +01:00

20612: add options to match-words-by-style widget

This commit is contained in:
Peter Stephenson 2004-12-09 14:44:42 +00:00
parent 69b4b8bdde
commit 4419b75dbc
3 changed files with 65 additions and 15 deletions

@ -1,3 +1,8 @@
2004-12-09 Peter Stephenson <pws@csr.com>
* 20612: Doc/Zsh/contrib.yo, Functions/Zle/match-words-by-style:
options to match-words-by-style can override styles.
2004-12-07 Peter Stephenson <pws@csr.com>
* 20605: Doc/Zsh/builtins.yo, Src/builtin.c, Src/exec.c,

@ -513,6 +513,18 @@ tt(skip-chars) style, (5) the word at or following the cursor (6) any
non-word characters following that word (7) the remainder of the line. Any
of the elements may be an empty string; the calling function should test
for this to decide whether it can perform its function.
It is possible to pass options with arguments to tt(match-words-by-style)
to override the use of styles. The options are:
startsitem()
sitem(tt(-w))(var(word-style))
sitem(tt(-s))(var(skip-chars))
sitem(tt(-c))(var(word-class))
sitem(tt(-C))(var(word-chars))
endsitem()
For example, tt(match-words-by-style -w shell -c 0) may be used to
extract the command argument around the cursor.
)
tindex(delete-whole-word-match)
item(tt(delete-whole-word-match))(

@ -57,12 +57,17 @@
# will appear in <whitespace-after-cursor> if it is whitespace, else in
# <word-after-cursor>. This style is mostly useful for forcing
# transposition to ignore the current character.
#
# The values of the styles can be overridden by options to the function:
# -w <word-style>
# -s <skip-chars>
# -c <word-class>
# -C <word-chars>
emulate -L zsh
setopt extendedglob
local wordstyle spacepat wordpat1 wordpat2 opt charskip
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
@ -70,8 +75,32 @@ if [[ -z $curcontext ]]; then
local curcontext=:zle:match-words-by-style
fi
zstyle -s $curcontext word-style wordstyle
zstyle -s $curcontext skip-chars skip
while getopts "w:s:c:C:" opt; do
case $opt in
(w)
wordstyle=$OPTARG
;;
(s)
skip=$OPTARG
;;
(c)
wordclass=$OPTARG
;;
(C)
wordchars=$OPTARG
;;
(*)
return 1
;;
esac
done
[[ -z $wordstyle ]] && zstyle -s $curcontext word-style wordstyle
[[ -z $skip ]] && zstyle -s $curcontext skip-chars skip
[[ -z $skip ]] && skip=0
case $wordstyle in
@ -107,20 +136,24 @@ case $wordstyle in
;;
(*) local wc
# See if there is a character class.
if zstyle -s $curcontext word-class wc; then
# Treat as a character class: do minimal quoting.
wc=${wc//(#m)[\'\"\`\$\(\)\^]/\\$MATCH}
wc=$wordclass
if [[ -n $wc ]] || zstyle -s $curcontext word-class wc; then
# Treat as a character class: do minimal quoting.
wc=${wc//(#m)[\'\"\`\$\(\)\^]/\\$MATCH}
else
# See if there is a local version of $WORDCHARS.
# See if there is a local version of $WORDCHARS.
wc=$wordchars
if [[ -z $wc ]]; then
zstyle -s $curcontext word-chars wc ||
wc=$WORDCHARS
if [[ $wc = (#b)(?*)-(*) ]]; then
# We need to bring any `-' to the front to avoid confusing
# character classes... we get away with `]' since in zsh
# this isn't a pattern character if it's quoted.
wc=-$match[1]$match[2]
fi
wc="${(q)wc}"
fi
if [[ $wc = (#b)(?*)-(*) ]]; then
# We need to bring any `-' to the front to avoid confusing
# character classes... we get away with `]' since in zsh
# this isn't a pattern character if it's quoted.
wc=-$match[1]$match[2]
fi
wc="${(q)wc}"
fi
# Quote $wc where necessary, because we don't want those
# characters to be considered as pattern characters later on.