Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Localize MATCH, MBEGIN, etc. in _zstyle and _globquals



On 2 listopada 2017 at 20:57:26, Phil Pennock (zsh-workers+phil.pennock@xxxxxxxxxxxx) 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



Messages sorted by: Reverse Date, Date, Thread, Author