From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: PATCH: Don't define internal params directly in hook function scope
Date: Thu, 30 Apr 2015 12:18:49 +0100 [thread overview]
Message-ID: <20150430121849.4a5f30c6@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20150430094404.3e45b6b7@pwslap01u.europe.root.pri>
On Thu, 30 Apr 2015 09:44:04 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> > (I believe the answer about adding a new level of scope around the
> > "local -h" has appeared on zsh-users before, though I can't think of
> > a good search term to find it.)
>
> Documenting this is probably a reasonable approach. Adding a nested
> function in the odd case where you need it probably isn't a big issue,
> as long as people know.
For example.
pws
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index ffce54c..653678e 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -743,6 +743,21 @@ local scope, like parameters created in a function using tt(local).
Inside completion widgets and traps called while ZLE is active, these
parameters are available read-only.
+Note that the parameters appear as local to any ZLE widget in
+which they appear. Hence if it is desired to override them this needs
+to be done within a nested function:
+
+example(widget-function+LPAR()+RPAR() {
+ # $WIDGET here refers to the special variable
+ # that is local inside widget-function
+ +LPAR()+RPAR() {
+ # This anonymous nested function allows WIDGET
+ # to be used as a local variable. The -h
+ # removes the special status of the variable.
+ local -h WIDGET
+ }
+})
+
startitem()
vindex(BUFFER)
item(tt(BUFFER) (scalar))(
next prev parent reply other threads:[~2015-04-30 11:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-29 6:35 [BUG] Can't mark unset variables as read-only Martijn Dekker
2015-04-29 10:36 ` Peter Stephenson
2015-04-29 10:57 ` Mikael Magnusson
2015-04-29 11:01 ` Mikael Magnusson
2015-04-30 0:08 ` PATCH: Don't define internal params directly in hook function scope Mikael Magnusson
2015-04-30 4:01 ` Bart Schaefer
2015-04-30 8:44 ` Peter Stephenson
2015-04-30 11:18 ` Peter Stephenson [this message]
2015-04-29 11:09 ` Local readonly specials (was: Can't mark unset variables as read-only) Peter Stephenson
2015-04-29 13:46 ` [BUG] Can't mark unset variables as read-only Martijn Dekker
2015-04-29 13:55 ` Bart Schaefer
2015-04-29 14:41 ` Peter Stephenson
2015-04-29 15:33 ` Chet Ramey
2015-04-29 19:09 ` Stephane Chazelas
2015-04-29 23:22 ` Chet Ramey
2015-04-30 3:57 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150430121849.4a5f30c6@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).