1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-20 11:51:24 +01:00

restore read-from-minibuffer save/restore

This commit is contained in:
Peter Stephenson 2008-04-07 09:44:33 +00:00
parent 71e5f09d58
commit 84e1cb93ad
3 changed files with 48 additions and 17 deletions

View file

@ -1,3 +1,10 @@
2008-04-07 Peter Stephenson <pws@csr.com>
* 24797: Doc/Zsh/zle.yo, Functions/Zle/read-from-minibuffer:
document POSTDISPLAY highlighting; restore read-from-minibuffer
save/restore mechanism using variables to avoid problems with
not restoring special ZLE variables when they go out of scope.
2008-04-05 Peter Stephenson <p.w.stephenson@ntlworld.com>
* İsmail Dönmez <ismail@namtrac.org>: 24793: Doc/Zsh/zle.yo:

View file

@ -778,8 +778,12 @@ vindex(region_highlight)
item(tt(region_highlight) (array))(
Each element of this array may be set to a string that describes
highlighting for an arbitrary region of the command line that will
take effect the next time the command line is redisplayed. Each
string consists of the following parts:
take effect the next time the command line is redisplayed. Highlighting
of the non-editable parts of the command line in tt(PREDISPLAY)
and tt(POSTDISPLAY) are possible, but note that the tt(P) flag
is needed for character indexing to include tt(PREDISPLAY).
Each string consists of the following parts:
startlist()
list(Optionally, a `tt(P)' to signify that the start and end offset that

View file

@ -21,21 +21,41 @@ done
local pretext="$PREDISPLAY$LBUFFER$RBUFFER$POSTDISPLAY
"
local LBUFFER="$2"
local RBUFFER="$3"
local PREDISPLAY="$pretext${1:-? }"
local POSTDISPLAY=
local -a region_highlight
region_highlight=("P${#pretext} ${#PREDISPLAY} bold")
# 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[@]}")
if [[ -n $keys ]]; then
zle -R
read -k $keys
stat=$?
else
zle recursive-edit -K main
stat=$?
(( stat )) || REPLY=$BUFFER
fi
{
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