2003-03-28 12:34:07 +01:00
|
|
|
emulate -L zsh
|
|
|
|
setopt extendedglob
|
|
|
|
|
|
|
|
local opt keys
|
|
|
|
integer stat
|
|
|
|
|
|
|
|
while getopts "k:" opt; do
|
2004-07-30 13:09:16 +02:00
|
|
|
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
|
2003-03-28 12:34:07 +01:00
|
|
|
done
|
|
|
|
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
|
|
|
|
|
2008-04-03 13:38:55 +02:00
|
|
|
local pretext="$PREDISPLAY$LBUFFER$RBUFFER$POSTDISPLAY
|
|
|
|
"
|
2008-04-07 11:44:33 +02:00
|
|
|
# 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[@]}")
|
2003-02-03 12:05:53 +01:00
|
|
|
|
2008-04-07 11:44:33 +02:00
|
|
|
{
|
|
|
|
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[@]}")
|
|
|
|
}
|
2003-02-03 12:05:53 +01:00
|
|
|
|
|
|
|
return $stat
|