From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5040 invoked by alias); 30 Apr 2015 11:19:14 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35007 Received: (qmail 29721 invoked from network); 30 Apr 2015 11:19:02 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-f794b6d000001495-04-55420fa89960 Date: Thu, 30 Apr 2015 12:18:49 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: PATCH: Don't define internal params directly in hook function scope Message-id: <20150430121849.4a5f30c6@pwslap01u.europe.root.pri> In-reply-to: <20150430094404.3e45b6b7@pwslap01u.europe.root.pri> References: <1430352483-30739-1-git-send-email-mikachu@gmail.com> <150429210140.ZM31974@torch.brasslantern.com> <20150430094404.3e45b6b7@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrELMWRmVeSWpSXmKPExsVy+t/xq7or+J1CDc7u0rM42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGbcf7mIveMlVsaxtKmsD4xGOLkZODgkBE4lLX8+yQNhiEhfu rWfrYuTiEBJYyijxofU1I4Qzg0ni8et7zCBVQgLbGCVediWD2CwCqhJzPr1iBbHZBAwlpm6a zQhiiwiIS5xdex5sqrBAgMSJed1ANgcHr4C9xNH7HiAmp4CDxJ8LohDjPzBKzLjznR2knF9A X+Lq309MEAfZS8y8cgZsJK+AoMSPyffARjILaEls3tbECmHLS2xe8xbqNHWJG3d3s09gFJqF pGUWkpZZSFoWMDKvYhRNLU0uKE5KzzXSK07MLS7NS9dLzs/dxAgJ2a87GJceszrEKMDBqMTD e2GbY6gQa2JZcWXuIUYJDmYlEV6T/0Ah3pTEyqrUovz4otKc1OJDjNIcLErivDN3vQ8REkhP LEnNTk0tSC2CyTJxcEo1MLrNqBWqFkya0Opqv5F9Z9+0lfyMrH88j3+eXrbhetXZa0xRVcK/ mB3OaRgtqt6o2Jc5c5N1robVLw6/qU8Nd1fonZad/PSSVX35AcU7VRsvZRwQelNtI/X+yNRM ZluJy8JW7D9/JB9demDlBInZO7WOhXiq+dr4dxRN4XgpmXpo4fXftm917iuxFGckGmoxFxUn AgDfWckfVQIAAA== On Thu, 30 Apr 2015 09:44:04 +0100 Peter Stephenson 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))(