1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-03 10:21:46 +02:00
zsh/Functions/Zle/read-from-minibuffer
Peter Stephenson a6e039e12e 29892: fix regular expression replacements in replace-string
improve variable save and restore in read-from-minibuffer
2011-11-04 14:31:23 +00:00

48 lines
996 B
Text

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 readprompt="$1" lbuf_init="$2" rbuf_init="$3"
# Use anonymous function to make sure special values get restored,
# even if this function is called as a widget.
# local +h ensures special parameters stay special.
() {
local pretext="$PREDISPLAY$LBUFFER$RBUFFER$POSTDISPLAY
"
local +h LBUFFER="$lbuf_init"
local +h RBUFFER="$rbuf_init"
local +h PREDISPLAY="$pretext${readprompt:-? }"
local +h POSTDISPLAY=
local +h -a region_highlight
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
}
return $stat