From 09e1b2434d6c44d95d97c87d5e803e5f5e747b6e Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Sun, 21 Jun 2015 18:16:40 +0100
Subject: 35545: enhance narrow-to-region to return LBUFFER and RBUFFER
---
Functions/Zle/narrow-to-region | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
(limited to 'Functions/Zle/narrow-to-region')
diff --git a/Functions/Zle/narrow-to-region b/Functions/Zle/narrow-to-region
index 86fd7ac13..c65c80cb9 100644
--- a/Functions/Zle/narrow-to-region
+++ b/Functions/Zle/narrow-to-region
@@ -11,6 +11,8 @@
# Either or both may be empty.
# -n Only replace the text before or after the region with
# the -p or -P options if the text was not empty.
+# -l lbufvar ) $lbufvar and $rbufvar will contain the value of $LBUFFER and
+# -r rbufvar ) $RBUFFER resulting from any recursive edit (i.e. not with -S or -R)
# -S statevar
# -R statevar
# Save or restore the state in/from the parameter named statevar. In
@@ -28,16 +30,20 @@ integer _ntr_start _ntr_end _ntr_swap _ntr_cursor=$CURSOR _ntr_mark=$MARK
integer _ntr_stat
local _ntr_opt _ntr_pretext _ntr_posttext _ntr_usepretext _ntr_useposttext
-local _ntr_nonempty _ntr_save _ntr_restore
+local _ntr_nonempty _ntr_save _ntr_restore _ntr_lbuffer _ntr_rbuffer
-while getopts "np:P:R:S:" _ntr_opt; do
+while getopts "l:np:P:r:R:S:" _ntr_opt; do
case $_ntr_opt in
+ (l) _ntr_lbuffer=$OPTARG
+ ;;
(n) _ntr_nonempty=1
;;
(p) _ntr_pretext=$OPTARG _ntr_usepretext=1
;;
(P) _ntr_posttext=$OPTARG _ntr_useposttext=1
;;
+ (r) _ntr_rbuffer=$OPTARG
+ ;;
(R) _ntr_restore=$OPTARG
;;
(S) _ntr_save=$OPTARG
@@ -101,6 +107,9 @@ fi
if [[ -z $_ntr_save && -z $_ntr_restore ]]; then
zle recursive-edit
_ntr_stat=$?
+
+ [[ -n $_ntr_lbuffer ]] && eval "${_ntr_lbuffer}=\${LBUFFER}"
+ [[ -n $_ntr_rbuffer ]] && eval "${_ntr_rbuffer}=\${RBUFFER}"
fi
if [[ -n $_ntr_restore || -z $_ntr_save ]]; then
--
cgit 1.4.1