mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-21 00:01:26 +01:00
22573: smooth interface to history-beginning-search-menu
document how to quote metacharacters for reverse array subscript
This commit is contained in:
parent
1e7c19eca3
commit
ba22472b7f
3 changed files with 51 additions and 11 deletions
|
@ -1,5 +1,10 @@
|
|||
2006-08-01 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 22573: Functions/Zle/history-beginning-search-menu,
|
||||
Doc/Zsh/params.yo: smooth the interface to the widget and
|
||||
document how to quote metacharacters for reverse array
|
||||
subscripting.
|
||||
|
||||
* 22572: Src/pattern.c, Test/D04parameter.ztst: use of (#m)
|
||||
was broken with pure strings.
|
||||
|
||||
|
|
|
@ -211,6 +211,18 @@ example (assuming the option tt(KSH_ARRAYS) is not in effect):
|
|||
example([[ ${array[(i)pattern]} -le ${#array} ]])
|
||||
|
||||
If tt(KSH_ARRAYS) is in effect, the tt(-le) should be replaced by tt(-lt).
|
||||
|
||||
Note that in subscripts with both `tt(r)' and `tt(R)' pattern characters
|
||||
are active even if they were substituted for a parameter (regardless
|
||||
of the setting of tt(GLOB_SUBST) which controls this feature in normal
|
||||
pattern matching). It is therefore necessary to quote pattern characters
|
||||
for an exact string match. Given a string in tt($key), and assuming
|
||||
the tt(EXTENDED_GLOB) option is set, the following is sufficient to
|
||||
match an element of an array tt($array) containing exactly the value of
|
||||
tt($key):
|
||||
|
||||
example(key2=${key//(#m)[\][+LPAR()+RPAR()\\*?#<>]/\\$MATCH}
|
||||
print ${array[(R)$key2]})
|
||||
)
|
||||
item(tt(R))(
|
||||
Like `tt(r)', but gives the last match. For associative arrays, gives
|
||||
|
|
|
@ -45,7 +45,7 @@ if [[ $WIDGET = *-space* ]]; then
|
|||
# since they are otherwise active in the reverse subscript.
|
||||
# We need to avoid quoting other characters since they aren't
|
||||
# and just stay quoted, rather annoyingly.
|
||||
search=${search//(#m)[*?#<>]/\\$MATCH/}
|
||||
search=${search//(#m)[\][()\\*?#<>]/\\$MATCH/}
|
||||
search=${search// /*}
|
||||
fi
|
||||
|
||||
|
@ -69,8 +69,19 @@ integer i
|
|||
display=(${matches/(#m)*/${(l.$width..0.):-$((++i))} $MATCH})
|
||||
zle -R "Enter digit${${width##1}:+s}:" $display
|
||||
|
||||
local chars
|
||||
read -k$width chars
|
||||
integer i
|
||||
local char chars
|
||||
|
||||
# Abort on first non-digit entry instead of requiring all
|
||||
# characters to be typed (as "read -k$width chars" would do).
|
||||
for (( i = 0; i < $width; i++ )); do
|
||||
read -k char
|
||||
if [[ $char != [[:digit:]] ]]; then
|
||||
zle -R '' $display
|
||||
return 1
|
||||
fi
|
||||
chars+=$char
|
||||
done
|
||||
|
||||
# Hmmm... this isn't great. The only way of clearing the display
|
||||
# appears to be to overwrite it completely. I think that's because
|
||||
|
@ -78,25 +89,37 @@ read -k$width chars
|
|||
# properly.
|
||||
display=(${display//?/ })
|
||||
|
||||
if [[ $chars != [[:digit:]]## || $chars -eq 0 || $chars -gt $n ]]; then
|
||||
if [[ $chars -eq 0 || $chars -gt $n ]]; then
|
||||
zle -R '' $display
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $WIDGET = *-end* ]]; then
|
||||
LBUFFER=${matches[$chars]} RBUFFER=
|
||||
else
|
||||
integer newcursor
|
||||
integer newcursor
|
||||
if [[ $WIDGET != *-end* ]]; then
|
||||
if (( ${+NUMERIC} )); then
|
||||
# Advance cursor so that it's still after the string typed
|
||||
local -a match mbegin mend
|
||||
if [[ $matches[$chars] = (#b)(*${LBUFFER})* ]]; then
|
||||
newcursor=${#match[1]}
|
||||
newcursor=${#match[1]}
|
||||
fi
|
||||
else
|
||||
# Maintain cursor
|
||||
newcursor=$CURSOR
|
||||
fi
|
||||
fi
|
||||
|
||||
BUFFER=${matches[$chars]}
|
||||
(( newcursor )) && CURSOR=$newcursor
|
||||
# Find the history lines that contain the matched string and
|
||||
# go to the last one. This allows accept-line-and-down-history etc.
|
||||
# to work.
|
||||
local -a lines
|
||||
local matchq=${matches[$chars]//(#m)[\][()\\*?#<>]/\\$MATCH}
|
||||
lines=(${(kon)history[(R)$matchq]})
|
||||
HISTNO=$lines[-1]
|
||||
|
||||
if (( newcursor )); then
|
||||
CURSOR=$newcursor
|
||||
elif [[ $WIDGET = *-end* ]]; then
|
||||
CURSOR=${#BUFFER}
|
||||
fi
|
||||
|
||||
zle -R '' $display
|
||||
|
|
Loading…
Reference in a new issue