blob: fce6b53191aab906ef424ac37a1f23ac0c3a9043 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
emulate -L zsh
setopt extendedglob
local opt keys
integer stat
while getopts "k:" opt; do
case $opt in
# Read the given number of keys. This is a bit
# ropey for more than a single key.
(k)
keys=$OPTARG
;;
(*)
return 1
;;
esac
done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
local pretext="$PREDISPLAY$LBUFFER$RBUFFER$POSTDISPLAY
"
# We could use the local variables mechanism to save these
# values, but if read-from-minibuffer is called as a widget
# (which isn't actually all that useful) the values won't be
# restored because the variables are already local at the current
# level and don't get restored when they go out of scope.
# We could do it with an additional function level.
local save_lbuffer=$LBUFFER
local save_rbuffer=$RBUFFER
local save_predisplay=$PREDISPLAY
local save_postdisplay=$POSTDISPLAY
local -a save_region_highlight
save_region_highlight=("${region_highlight[@]}")
{
LBUFFER="$2"
RBUFFER="$3"
PREDISPLAY="$pretext${1:-? }"
POSTDISPLAY=
region_highlight=("P${#pretext} ${#PREDISPLAY} bold")
if [[ -n $keys ]]; then
zle -R
read -k $keys
stat=$?
else
zle recursive-edit -K main
stat=$?
(( stat )) || REPLY=$BUFFER
fi
} always {
LBUFFER=$save_lbuffer
RBUFFER=$save_rbuffer
PREDISPLAY=$save_predisplay
POSTDISPLAY=$save_postdisplay
region_highlight=("${save_region_highlight[@]}")
}
return $stat
|