unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* does emacs regular expression support (?!expression)
@ 2012-02-02 14:02 土星五号
  2012-02-02 18:56 ` Tassilo Horn
  0 siblings, 1 reply; 16+ messages in thread
From: 土星五号 @ 2012-02-02 14:02 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 56 bytes --]

does emacs regular expression support (?!expression)  ?

[-- Attachment #2: Type: text/html, Size: 61 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-02 14:02 does emacs regular expression support (?!expression) 土星五号
@ 2012-02-02 18:56 ` Tassilo Horn
  2012-02-02 21:14   ` Tim Landscheidt
  0 siblings, 1 reply; 16+ messages in thread
From: Tassilo Horn @ 2012-02-02 18:56 UTC (permalink / raw)
  To: help-gnu-emacs

土星五号 <laf163@gmail.com> writes:

> does emacs regular expression support (?!expression) ?

It would be more helpful if you'd tell us what (?!expression) would
match, preferably with some examples.  Syntactically, emacs regexp's shy
groups look similar.  The regular expression

  "\\(:?foo\\|bar\\)\\([0-9]+\\)"

matches "foo19" or "bar23", but doesn't capture foo or bar, so that
(match-string 1) is the number.

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-02 18:56 ` Tassilo Horn
@ 2012-02-02 21:14   ` Tim Landscheidt
  2012-02-02 21:45     ` Tassilo Horn
  2012-02-02 22:09     ` Glenn Morris
  0 siblings, 2 replies; 16+ messages in thread
From: Tim Landscheidt @ 2012-02-02 21:14 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn <tassilo@member.fsf.org> wrote:

>> does emacs regular expression support (?!expression) ?

> It would be more helpful if you'd tell us what (?!expression) would
> match, preferably with some examples.  Syntactically, emacs regexp's shy
> groups look similar.  The regular expression

>   "\\(:?foo\\|bar\\)\\([0-9]+\\)"

> matches "foo19" or "bar23", but doesn't capture foo or bar, so that
> (match-string 1) is the number.

In Perl, "(?!pattern)" is a zero-width negative look-ahead
assertion.  Emacs does not support these AFAIK.

Tim




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-02 21:14   ` Tim Landscheidt
@ 2012-02-02 21:45     ` Tassilo Horn
  2012-02-02 22:11       ` Tim Landscheidt
  2012-02-03  0:37       ` Kevin Rodgers
  2012-02-02 22:09     ` Glenn Morris
  1 sibling, 2 replies; 16+ messages in thread
From: Tassilo Horn @ 2012-02-02 21:45 UTC (permalink / raw)
  To: help-gnu-emacs

Tim Landscheidt <tim@tim-landscheidt.de> writes:

Hi Tim,

>> It would be more helpful if you'd tell us what (?!expression) would
>> match, preferably with some examples.  Syntactically, emacs regexp's shy
>> groups look similar.  The regular expression
>
>>   "\\(:?foo\\|bar\\)\\([0-9]+\\)"

BTW, that should have been (?:...).

>> matches "foo19" or "bar23", but doesn't capture foo or bar, so that
>> (match-string 1) is the number.
>
> In Perl, "(?!pattern)" is a zero-width negative look-ahead
> assertion.  Emacs does not support these AFAIK.

I see.  So when you do /foo(?!bar)/ in Perl, you'd need to do
"foo\\(?:[^b][^a][^r]\\)" in elisp.

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-02 21:14   ` Tim Landscheidt
  2012-02-02 21:45     ` Tassilo Horn
@ 2012-02-02 22:09     ` Glenn Morris
  1 sibling, 0 replies; 16+ messages in thread
From: Glenn Morris @ 2012-02-02 22:09 UTC (permalink / raw)
  To: help-gnu-emacs

Tim Landscheidt wrote:

> In Perl, "(?!pattern)" is a zero-width negative look-ahead
> assertion.  Emacs does not support these AFAIK.

http://debbugs.gnu.org/cgi/bugreport.cgi?bug=5393
(to date, not applied)

See also the linked
http://lists.gnu.org/archive/html/emacs-devel/2012-01/msg00732.html




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-02 21:45     ` Tassilo Horn
@ 2012-02-02 22:11       ` Tim Landscheidt
  2012-02-02 22:17         ` Tim Landscheidt
  2012-02-03  0:37       ` Kevin Rodgers
  1 sibling, 1 reply; 16+ messages in thread
From: Tim Landscheidt @ 2012-02-02 22:11 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn <tassilo@member.fsf.org> wrote:

> [...]

>>> matches "foo19" or "bar23", but doesn't capture foo or bar, so that
>>> (match-string 1) is the number.

>> In Perl, "(?!pattern)" is a zero-width negative look-ahead
>> assertion.  Emacs does not support these AFAIK.

> I see.  So when you do /foo(?!bar)/ in Perl, you'd need to do
> "foo\\(?:[^b][^a][^r]\\)" in elisp.

You have to account for possible end-of-buffer as well so
usually it's "easier" to use two matches ('(while (and
(search-forward-regexp "foo") (not (looking-at "bar"))))'
(untested)) - that's why I (still :-)) think these features
should be implemented in Emacs as well.

Tim




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-02 22:11       ` Tim Landscheidt
@ 2012-02-02 22:17         ` Tim Landscheidt
  0 siblings, 0 replies; 16+ messages in thread
From: Tim Landscheidt @ 2012-02-02 22:17 UTC (permalink / raw)
  To: help-gnu-emacs

I wrote:

>> [...]

>>>> matches "foo19" or "bar23", but doesn't capture foo or bar, so that
>>>> (match-string 1) is the number.

>>> In Perl, "(?!pattern)" is a zero-width negative look-ahead
>>> assertion.  Emacs does not support these AFAIK.

>> I see.  So when you do /foo(?!bar)/ in Perl, you'd need to do
>> "foo\\(?:[^b][^a][^r]\\)" in elisp.

> You have to account for possible end-of-buffer as well so
> usually it's "easier" to use two matches ('(while (and
> (search-forward-regexp "foo") (not (looking-at "bar"))))'
> (untested)) - [...]

Eh, yes, there is an "(untested)", but still the logic is
obviously plain wrong.  But you get the idea.

Tim




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-02 21:45     ` Tassilo Horn
  2012-02-02 22:11       ` Tim Landscheidt
@ 2012-02-03  0:37       ` Kevin Rodgers
  2012-02-03  2:12         ` 土星五号
  1 sibling, 1 reply; 16+ messages in thread
From: Kevin Rodgers @ 2012-02-03  0:37 UTC (permalink / raw)
  To: help-gnu-emacs

On 2/2/12 2:45 PM, Tassilo Horn wrote:
> Tim Landscheidt<tim@tim-landscheidt.de>  writes:

>> In Perl, "(?!pattern)" is a zero-width negative look-ahead
>> assertion.  Emacs does not support these AFAIK.
>
> I see.  So when you do /foo(?!bar)/ in Perl, you'd need to do
> "foo\\(?:[^b][^a][^r]\\)" in elisp.

IIUC, the Perl regex would successfully match "foo" if it were followed by
"far", but the Emacs regexp would not.

Maybe \(?:[^b][^a][^r]\) should be \(?:[^b]\|b[^a]\|ba[^r]\)

-- 
Kevin Rodgers
Denver, Colorado, USA




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-03  0:37       ` Kevin Rodgers
@ 2012-02-03  2:12         ` 土星五号
  2012-02-03  8:30           ` Thien-Thi Nguyen
  0 siblings, 1 reply; 16+ messages in thread
From: 土星五号 @ 2012-02-03  2:12 UTC (permalink / raw)
  To: Kevin Rodgers; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2247 bytes --]

I would like match Err in any words(e.g. LastError), but not ErrorMode.
(defvar txt-mode-font-lock-keywords
  `(
    ;; 文件名
    ("\\\\\\(\\w+\\.exe\\)" 1 font-lock-keyword-face)
    ;; IP和版本

("[^0-9]\\([0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\)"
1 font-lock-keyword-face)
    ;; Error
    ("\\<\\([Dd][Bb][Ee][Rr][Rr][Oo][Rr]\\)\\>" 1 font-lock-warning-face)
    ("\\<\\([Dd][Bb][Ee][Rr][Rr]\\)\\>" 1 font-lock-warning-face)
    ("\\<\\([Ee][Rr][Rr][Oo][Rr]\\)\\>" 1 font-lock-warning-face)
    ("\\([Ee][Rr][Rr]\\)\\(?!orMode\\)" 1 font-lock-warning-face)
    ("\\(错误\\)" 1 font-lock-warning-face)
    ("\\(失败\\)" 1 font-lock-warning-face)
    ("\\(严重\\)" 1 font-lock-warning-face)
    ("\\<\\([Ff][Aa][Ii][Ll][Ee][Dd]\\)\\>" 1 font-lock-warning-face)
    ("\\<\\([Ff][Aa][Ii][Ll]\\)\\>" 1 font-lock-warning-face)
    ("\\<\\([Cc][Aa][Nn]\\s+[Nn][Oo][Tt]\\)\\>" 1 font-lock-warning-face)
    ("\\<\\([Cc][Aa][Nn]'[Tt]\\)\\>" 1 font-lock-warning-face)
    ("\\<\\([Ww][Rr][Oo][Nn][Gg]\\)\\>" 1 font-lock-warning-face)
    ;; Warning
    ("\\<\\([Ww][Aa][Rr][Nn][Ii][Nn][Gg]\\)\\>" 1 font-lock-warning-face)
    ("\\<\\([Ww][Aa][Rr][Nn]\\)\\>" 1 font-lock-warning-face)
    ("\\(警告\\)" 1 font-lock-warning-face)
    ;; Exception
    ("\\<\\([Ee][Xx][Cc][Ee][Pp][Tt][Ii][Oo][Nn]\\)\\>" 1
font-lock-warning-face)
    ("\\<\\([Ee][Xx][Cc][Ee][Pp][Tt]\\)\\>" 1 font-lock-warning-face)
    ("\\(异常\\)" 1 font-lock-warning-face)
    )
  "Basic font lock keywords for txt mode.  Highlights keywords.")

2012/2/3 Kevin Rodgers <kevin.d.rodgers@gmail.com>

> On 2/2/12 2:45 PM, Tassilo Horn wrote:
>
>> Tim Landscheidt<tim@tim-**landscheidt.de <tim@tim-landscheidt.de>>
>>  writes:
>>
>
>  In Perl, "(?!pattern)" is a zero-width negative look-ahead
>>> assertion.  Emacs does not support these AFAIK.
>>>
>>
>> I see.  So when you do /foo(?!bar)/ in Perl, you'd need to do
>> "foo\\(?:[^b][^a][^r]\\)" in elisp.
>>
>
> IIUC, the Perl regex would successfully match "foo" if it were followed by
> "far", but the Emacs regexp would not.
>
> Maybe \(?:[^b][^a][^r]\) should be \(?:[^b]\|b[^a]\|ba[^r]\)
>
> --
> Kevin Rodgers
> Denver, Colorado, USA
>
>
>

[-- Attachment #2: Type: text/html, Size: 3855 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-03  2:12         ` 土星五号
@ 2012-02-03  8:30           ` Thien-Thi Nguyen
  2012-02-03 11:17             ` Tim Landscheidt
  0 siblings, 1 reply; 16+ messages in thread
From: Thien-Thi Nguyen @ 2012-02-03  8:30 UTC (permalink / raw)
  To: 土星五号; +Cc: help-gnu-emacs

() 土星五号 <laf163@gmail.com>
() Fri, 3 Feb 2012 10:12:27 +0800

   I would like match Err in any words(e.g. LastError), but not ErrorMode.

       ("\\([Ee][Rr][Rr]\\)\\(?!orMode\\)" 1 font-lock-warning-face)

You can add a spec for ‘ErrorMode’, with default face, prior to this one.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-03  8:30           ` Thien-Thi Nguyen
@ 2012-02-03 11:17             ` Tim Landscheidt
  2012-02-03 11:48               ` Thien-Thi Nguyen
  0 siblings, 1 reply; 16+ messages in thread
From: Tim Landscheidt @ 2012-02-03 11:17 UTC (permalink / raw)
  To: help-gnu-emacs

Thien-Thi Nguyen <ttn@gnuvola.org> wrote:

>    I would like match Err in any words(e.g. LastError), but not ErrorMode.

>        ("\\([Ee][Rr][Rr]\\)\\(?!orMode\\)" 1 font-lock-warning-face)

> You can add a spec for ‘ErrorMode’, with default face, prior to this one.

Which Emacs version does support that?

Tim




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-03 11:17             ` Tim Landscheidt
@ 2012-02-03 11:48               ` Thien-Thi Nguyen
  2012-02-04 10:12                 ` Tim Landscheidt
  0 siblings, 1 reply; 16+ messages in thread
From: Thien-Thi Nguyen @ 2012-02-03 11:48 UTC (permalink / raw)
  To: help-gnu-emacs

() Tim Landscheidt <tim@tim-landscheidt.de>
() Fri, 03 Feb 2012 11:17:25 +0000

   > You can add a spec for ‘ErrorMode’, with default face, prior to this one.

   Which Emacs version does support that?

Any that processes these specs in the given order, with
"masking semantics", i suppose.  (I haven't tried.)



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-03 11:48               ` Thien-Thi Nguyen
@ 2012-02-04 10:12                 ` Tim Landscheidt
  2012-02-04 12:16                   ` 土星五号
  2012-02-04 15:26                   ` Thien-Thi Nguyen
  0 siblings, 2 replies; 16+ messages in thread
From: Tim Landscheidt @ 2012-02-04 10:12 UTC (permalink / raw)
  To: help-gnu-emacs

Thien-Thi Nguyen <ttn@gnuvola.org> wrote:

>    > You can add a spec for ‘ErrorMode’, with default face, prior to this one.

>    Which Emacs version does support that?

> Any that processes these specs in the given order, with
> "masking semantics", i suppose.  (I haven't tried.)

What does:

| (search-forward-regexp "\\([Ee][Rr][Rr]\\)\\(?!orMode\\)")

give on your Emacs?

Tim




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-04 10:12                 ` Tim Landscheidt
@ 2012-02-04 12:16                   ` 土星五号
  2012-02-04 15:26                   ` Thien-Thi Nguyen
  1 sibling, 0 replies; 16+ messages in thread
From: 土星五号 @ 2012-02-04 12:16 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 567 bytes --]

No, i put it in txt-mode-load.el.

 .emacs:
(require 'txt-mode-load)



2012/2/4 Tim Landscheidt <tim@tim-landscheidt.de>

> Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
>
> >    > You can add a spec for ‘ErrorMode’, with default face, prior to
> this one.
>
> >    Which Emacs version does support that?
>
> > Any that processes these specs in the given order, with
> > "masking semantics", i suppose.  (I haven't tried.)
>
> What does:
>
> | (search-forward-regexp "\\([Ee][Rr][Rr]\\)\\(?!orMode\\)")
>
> give on your Emacs?
>
> Tim
>
>
>

[-- Attachment #2: Type: text/html, Size: 1014 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-04 10:12                 ` Tim Landscheidt
  2012-02-04 12:16                   ` 土星五号
@ 2012-02-04 15:26                   ` Thien-Thi Nguyen
  2012-02-05 11:57                     ` Tim Landscheidt
  1 sibling, 1 reply; 16+ messages in thread
From: Thien-Thi Nguyen @ 2012-02-04 15:26 UTC (permalink / raw)
  To: help-gnu-emacs

() Tim Landscheidt <tim@tim-landscheidt.de>
() Sat, 04 Feb 2012 10:12:33 +0000

   Thien-Thi Nguyen <ttn@gnuvola.org> wrote:

   >    > You can add a spec for ‘ErrorMode’, with default face, prior to this one.

   >    Which Emacs version does support that?

   > Any that processes these specs in the given order, with
   > "masking semantics", i suppose.  (I haven't tried.)

   What does:

   | (search-forward-regexp "\\([Ee][Rr][Rr]\\)\\(?!orMode\\)")

   give on your Emacs?

It throws an error "Invalid regular expression".
Sorry for being unclear.  Here is a reformulation:

"Presuming that Emacs processes the user-specified font-lock specs
in the order given and that once a piece of text is marked as 
fontified, it no longer qualifies for further processing,
one way to "not match ErrorMode but match "Err" is to specify first
"ErrorMode" with the default face (thus simulating "not matching"
and simultaneously making that text unavailable for...), and second
the "Err" with the warning face."

That is, two entries in the list, neither of which use ‘?:’.

So, instead of asking Emacs to look ahead on "Err" and decline to
match if the trailing text is "orMode", you ask Emacs to explicitly
find "ErrorMode" and (quietly) exclude it from future hits when
looking for "Err".  This is like sweeping the path with a glue gun.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: does emacs regular expression support (?!expression)
  2012-02-04 15:26                   ` Thien-Thi Nguyen
@ 2012-02-05 11:57                     ` Tim Landscheidt
  0 siblings, 0 replies; 16+ messages in thread
From: Tim Landscheidt @ 2012-02-05 11:57 UTC (permalink / raw)
  To: help-gnu-emacs

Thien-Thi Nguyen <ttn@gnuvola.org> wrote:

> [...]
> It throws an error "Invalid regular expression".
> Sorry for being unclear.  [...]

Thanks.

Tim




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-02-05 11:57 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-02 14:02 does emacs regular expression support (?!expression) 土星五号
2012-02-02 18:56 ` Tassilo Horn
2012-02-02 21:14   ` Tim Landscheidt
2012-02-02 21:45     ` Tassilo Horn
2012-02-02 22:11       ` Tim Landscheidt
2012-02-02 22:17         ` Tim Landscheidt
2012-02-03  0:37       ` Kevin Rodgers
2012-02-03  2:12         ` 土星五号
2012-02-03  8:30           ` Thien-Thi Nguyen
2012-02-03 11:17             ` Tim Landscheidt
2012-02-03 11:48               ` Thien-Thi Nguyen
2012-02-04 10:12                 ` Tim Landscheidt
2012-02-04 12:16                   ` 土星五号
2012-02-04 15:26                   ` Thien-Thi Nguyen
2012-02-05 11:57                     ` Tim Landscheidt
2012-02-02 22:09     ` Glenn Morris

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 read-only IMAP folder(s) and NNTP newsgroup(s).