zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: MBEGIN, MEND in #m when pattern has "|"
Date: Thu, 2 Jun 2016 19:41:33 +0200	[thread overview]
Message-ID: <CAKc7PVDXOUzJfhQMtCuW8mknM+OzyXQzafj9BKWPHDzkxAwXLA@mail.gmail.com> (raw)

Hello,
below is a code that uses indexes set by (#m) or (#b). Turns out the
indexes are set only when using (#b). For (#m) they are set when there
is no "|" in the pattern. Why?

Output is:
==========================

Text is: vim ~/.zshrc s, searching for: vim|s
|-1 0 fg=red,bold|
 ~/.z|-1 0 fg=red,bold|
hrc |-1 0 fg=red,bold|

Text is: vim ~/.zshrc s, searching for: vim|s
|0 3 fg=red,bold|
|8 9 fg=red,bold|
|13 14 fg=red,bold|

Code:
==========================

#!/usr/bin/env zsh

nl=$'\n'
text="vim ~/.zshrc s"
colsearch_pattern="vim|s"

harray=( "${(f)${text//(#mi)${~colsearch_pattern}/|$(( MBEGIN - 1 ))
$(( MEND )) fg=red,bold|$nl}%$nl*}" )
echo "Text is: $text, searching for: $colsearch_pattern"
print -rl -- "${harray[@]}"

print

harray=( "${(f)${(S)text//*(#bi)(${~colsearch_pattern})/|$(( mbegin[1]
- 1 )) $(( mend[1] )) fg=red,bold|$nl}%$nl*}" )
echo "Text is: $text, searching for: $colsearch_pattern"
print -rl -- "${harray[@]}"


             reply	other threads:[~2016-06-02 17:41 UTC|newest]

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