zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: MBEGIN, MEND in #m when pattern has "|"
Date: Fri, 3 Jun 2016 22:58:21 -0700	[thread overview]
Message-ID: <160603225821.ZM25900@torch.brasslantern.com> (raw)
In-Reply-To: <CAKc7PVDXPRSUxF_Uwgv1FLqQ7W65Nps0nDj8Jk5T_iV9bsvxrg@mail.gmail.com>

On Jun 3,  6:47am, Sebastian Gniazdowski wrote:
} Subject: Re: MBEGIN, MEND in #m when pattern has "|"
}
} On 3 June 2016 at 00:11, Bart Schaefer <schaefer@brasslantern.com> wrote:
} > MATCH MBEGIN and MEND are set only if there is a single possible match
} > (more precisely, when the string can be matched with only a combination
} > of strcmp() and simple wildcards).  In //pat/repl/, there are multiple
} > possible match positions; which begin and end do you want?
} 
} The ones that are substituted, i.e. if #m knows that it will replace
} "vim", it should give indexes for that substring, and if it knows it
} will replace "s", then should give indexes for it, etc.

On closer inspection, your problem isn't what I thought it was.  Note
this bit of the doc:

m
     Set references to the match data for the entire string matched;
     this is similar to backreferencing and does not work in filename
     generation.  The flag must be in effect at the end of the pattern,
     i.e. not local to a group.

When you do

    (#mi)this|that

The #m ends at the "|", and so is not "in effect at the end of the
pattern" which is after "that".  So if you change your expression to be
one of

    harray=( "${(f)${text//(#mi)(${~colsearch_pattern})/|$(( MBEGIN - 1 )) $((
MEND )) fg=red,bold|$nl}%$nl*}" )

[added parens around the alternates] or

    harray=( "${(f)${text//(#i)${~colsearch_pattern}(#m)/|$(( MBEGIN - 1 )) $((
MEND )) fg=red,bold|$nl}%$nl*}" )

[moved (#m) to the end] then $MBEGIN et al. work as you desire.  I suspect
you actually want the first with the parens because otherwise the (#i) also
ends at the "|".


  reply	other threads:[~2016-06-04  5:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-02 17:41 Sebastian Gniazdowski
2016-06-02 22:11 ` Bart Schaefer
2016-06-03  4:47   ` Sebastian Gniazdowski
2016-06-04  5:58     ` Bart Schaefer [this message]
2016-06-04  6:41       ` 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=160603225821.ZM25900@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).