From 84e1cb93ad1364800bddbd1f71cb142beaa4c100 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 7 Apr 2008 09:44:33 +0000 Subject: restore read-from-minibuffer save/restore --- Functions/Zle/read-from-minibuffer | 50 ++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'Functions/Zle') diff --git a/Functions/Zle/read-from-minibuffer b/Functions/Zle/read-from-minibuffer index 8c9051551..fce6b5319 100644 --- a/Functions/Zle/read-from-minibuffer +++ b/Functions/Zle/read-from-minibuffer @@ -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 -- cgit 1.4.1