Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: UNDO_LIMIT_NO and its documentation



On Tue, 18 Aug 2015 09:26:43 +0100
Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> > Firstly, why not just
> > 
> > 	local UNDO_LIMIT_NO=$UNDO_CHANGE_NO
> > 
> > and allow function scoping to restore it?
> 
> As noted in the comments when the patch appeared, you'd need double
> function scope because of the way ZLE widgets work.  I couldn't be
> bothered to explain, but surrounding the code with (){ ... } should be
> OK in principle.

I think this works.

pws

diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 697b636..c06e226 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -971,14 +971,12 @@ to use `tt(zle undo) var(change)' in a widget to undo beyond
 that point; in that case, it will not be possible to undo at
 all until tt(UNDO_LIMIT_NO) is reduced.  Set to 0 to disable the limit.
 
-A typical use of this variable in a widget function is as follows:
+A typical use of this variable in a widget function is as follows (note
+the additional function scope is required):
 
-example(integer save_limit=$UNDO_LIMIT_NO
-UNDO_LIMIT_NO=$UNDO_CHANGE_NO
-{
+example(LPAR()RPAR() {
+  local UNDO_LIMIT_NO=$UNDO_CHANGE_NO
   # Perform some form of recursive edit.
-} always {
-  UNDO_LIMIT_NO=save_limit
 })
 )
 vindex(WIDGET)



Messages sorted by: Reverse Date, Date, Thread, Author