* UNDO_LIMIT_NO and its documentation
@ 2015-08-18 7:09 Bart Schaefer
2015-08-18 8:26 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2015-08-18 7:09 UTC (permalink / raw)
To: zsh-workers
The doc says:
A typical use of this variable in a widget function is as follows:
integer save_limit=$UNDO_LIMIT_NO
UNDO_LIMIT_NO=$UNDO_CHANGE_NO
{
# Perform some form of recursive edit.
} always {
UNDO_LIMIT_NO=save_limit
}
Firstly, why not just
local UNDO_LIMIT_NO=$UNDO_CHANGE_NO
and allow function scoping to restore it? It's not a special.
Secondly, declaring "integer save_limit" means that save_limit will have
a default of zero, but UNDO_LIMIT_NO has a default of unset. So when the
assignment back to UNDO_LIMIT_NO is done, it'll change state from unset
to zero. Does that matter?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: UNDO_LIMIT_NO and its documentation
2015-08-18 7:09 UNDO_LIMIT_NO and its documentation Bart Schaefer
@ 2015-08-18 8:26 ` Peter Stephenson
2015-08-18 9:17 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2015-08-18 8:26 UTC (permalink / raw)
To: zsh-workers
On Tue, 18 Aug 2015 00:09:16 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> The doc says:
>
> A typical use of this variable in a widget function is as follows:
>
> integer save_limit=$UNDO_LIMIT_NO
> UNDO_LIMIT_NO=$UNDO_CHANGE_NO
> {
> # Perform some form of recursive edit.
> } always {
> UNDO_LIMIT_NO=save_limit
> }
>
> 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.
> It's not a special.
All ZLE parameters are special, but removable. See makezleparams().
> Secondly, declaring "integer save_limit" means that save_limit will have
> a default of zero, but UNDO_LIMIT_NO has a default of unset. So when the
> assignment back to UNDO_LIMIT_NO is done, it'll change state from unset
> to zero. Does that matter?
It should work fine, but I can't find any evidence in zle_params.c that
UNDO_LIMIT_NO is unset; only NUMERIC has that behaviour at the moment.
Either it's present as an integer variable or it isn't.
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: UNDO_LIMIT_NO and its documentation
2015-08-18 8:26 ` Peter Stephenson
@ 2015-08-18 9:17 ` Peter Stephenson
0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2015-08-18 9:17 UTC (permalink / raw)
To: zsh-workers
On Tue, 18 Aug 2015 09:26:43 +0100
Peter Stephenson <p.stephenson@samsung.com> 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)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-18 9:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-18 7:09 UNDO_LIMIT_NO and its documentation Bart Schaefer
2015-08-18 8:26 ` Peter Stephenson
2015-08-18 9:17 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).