zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <psprint@zdharma.org>
To: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
Cc: zsh-workers@zsh.org
Subject: Re: Localize MATCH, MBEGIN, etc. in _zstyle and _globquals
Date: Sat, 4 Nov 2017 17:57:23 +0100	[thread overview]
Message-ID: <etPan.59fdf173.2b80f469.98a8@zdharma.org> (raw)
In-Reply-To: <etPan.59fb7aea.497d9379.98a8@AirmailxGenerated.am>

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


  parent reply	other threads:[~2017-11-04 16:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-29 11:40 Sebastian Gniazdowski
2017-10-29 22:07 ` Phil Pennock
     [not found] ` <etPan.59f655ed.1f659851.98a8@AirmailxGenerated.am>
2017-11-02 19:09   ` Sebastian Gniazdowski
2017-11-02 19:57     ` Phil Pennock
     [not found]     ` <etPan.59fb7aea.497d9379.98a8@AirmailxGenerated.am>
2017-11-04 16:57       ` Sebastian Gniazdowski [this message]
2017-11-04 19:03         ` Bart Schaefer
2017-11-05 16:20           ` Sebastian Gniazdowski

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=etPan.59fdf173.2b80f469.98a8@zdharma.org \
    --to=psprint@zdharma.org \
    --cc=zsh-workers+phil.pennock@spodhuis.org \
    --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).