1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-27 04:40:59 +01:00

24781: enhance word-context to use next or previous word

This commit is contained in:
Peter Stephenson 2008-04-02 13:02:47 +00:00
parent 93fce8372d
commit 374b31616b
3 changed files with 19 additions and 17 deletions

View file

@ -1,5 +1,9 @@
2008-04-02 Peter Stephenson <pws@csr.com> 2008-04-02 Peter Stephenson <pws@csr.com>
* 24781: Doc/Zsh/contrib.yo, Functions/Zle/match-word-context:
make word-context style more useful by using previous or next word
depending on widget name.
* unposted: README: minor tweaks. * unposted: README: minor tweaks.
* unposted: NEWS, Config/version.mk: Release 4.3.6. * unposted: NEWS, Config/version.mk: Release 4.3.6.

View file

@ -494,9 +494,10 @@ var(pattern) and a var(subcontext). The shell argument the cursor is on is
matched against each var(pattern) in turn until one matches; if it does, matched against each var(pattern) in turn until one matches; if it does,
the context is extended by a colon and the corresponding var(subcontext). the context is extended by a colon and the corresponding var(subcontext).
Note that the test is made against the original word on the line, with no Note that the test is made against the original word on the line, with no
stripping of quotes. If the cursor is at the end of the line the test is stripping of quotes. Special handling is done between words: the current
performed against an empty string; if it is on whitespace between words the context is examined and if it contains the string tt(back), the word before
test is made against a single space. Some examples are given below. the cursor is considered, else the word after cursor is considered. Some
examples are given below.
Here are some examples of use of the styles, actually taken from the Here are some examples of use of the styles, actually taken from the
simplified interface in tt(select-word-style): simplified interface in tt(select-word-style):

View file

@ -6,7 +6,7 @@ emulate -L zsh
setopt extendedglob setopt extendedglob
local -a worcon bufwords local -a worcon bufwords
local pat tag lastword word local pat tag lastword word backword forword
integer iword integer iword
zstyle -a $curcontext word-context worcon || return 0 zstyle -a $curcontext word-context worcon || return 0
@ -23,21 +23,18 @@ bufwords=(${(z)BUFFER})
if [[ $lastword = ${bufwords[iword]} ]]; then if [[ $lastword = ${bufwords[iword]} ]]; then
# If the word immediately left of the cursor is complete, # If the word immediately left of the cursor is complete,
# we're not on it. Either we're on unquoted whitespace, or # we're not on it for forward operations.
# the start of a new word. Test the latter. forword=${bufwords[iword+1]}
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 else
# We're on a word. # We're on a word.
word=${bufwords[iword]} forword=${bufwords[iword]}
fi
backword=${bufwords[iword]}
if [[ $curcontext = *back* ]]; then
word=$backword
else
word=$forword
fi fi
for pat tag in "${worcon[@]}"; do for pat tag in "${worcon[@]}"; do