From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23924 invoked by alias); 4 Nov 2017 16:57:31 -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: List-Unsubscribe: X-Seq: 41986 Received: (qmail 15427 invoked by uid 1010); 4 Nov 2017 16:57:31 -0000 X-Qmail-Scanner-Diagnostics: from aok120.rev.netart.pl by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(85.128.245.120):SA:0(-1.9/5.0):. Processed in 2.25197 secs); 04 Nov 2017 16:57:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: psprint@zdharma.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: by amavisd-new using ClamAV (17) Date: Sat, 4 Nov 2017 17:57:23 +0100 From: Sebastian Gniazdowski To: Phil Pennock Cc: zsh-workers@zsh.org Message-ID: In-Reply-To: References: Subject: Re: Localize MATCH, MBEGIN, etc. in _zstyle and _globquals X-Mailer: Airmail (442) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline On 2 listopada 2017 at 20:57:26, Phil Pennock (zsh-workers+phil.pennock@spodhuis.org) wrote: > If BASH_REMATCH is not set then various variables are set. I think > that _all_ of those should always be localized for the completion > system, but was asking if anyone has a convincing reason why not. > > The variables are documented in zshmisc(1) in CONDITIONAL EXPRESSIONS > under >> string =~ regexp <<. Thus: Interesting, didn't know it's possible to get full $match, $mbegin, $mend behavior with regular expressions. I'm always striving for (#m) then (#b). I'm just gonna share something that shows that / substitution could allow regex too, in ideal world. So for example I have an array: list=( 'href="/junegunn/fzf-bin/releases/download/0.17.1/fzf-0.17.1-darwin_386.tgz' 'href="/junegunn/fzf-bin/releases/download/0.17.1/fzf-0.17.1-darwin_amd64.tgz' 'href="/junegunn/fzf-bin/releases/download/0.17.1/fzf-0.17.1-freebsd_386.tgz' ) I get the version by: list=( "${(uOn)list[@]/(#b)href=?(\/[^\/]##)(#c4,4)\/([^\/]##)*/${match[2]}}" ) -> 0.17.1 I think it has a nice trick with the (#c4,4), to have 4 "/..." blocks, avoiding "awk -F/" etc. > local MATCH MBEGIN MEND match mbegin mend I agree on the variables. > Note re your other point (not quoted by me above): once a variable name > is localized, it's local, and you don't need to force it to be an array > as long as whatever sets it treats it as the right type: Yes I knew that, it's just maybe 'nicer' to have them array from the beginning.. I also localize MBEGIN and MEND as integers. Hard choice as either option is logical on its own behalf, but maybe there are some hidden reasons for choosing one of them. -- Sebastian Gniazdowski psprint /at/ zdharma.org