unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* font-lock regexp for complementary keywords
@ 2006-07-24 16:53 Dieter Wilhelm
  2006-07-25 16:15 ` Kevin Rodgers
       [not found] ` <mailman.4451.1153844221.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Dieter Wilhelm @ 2006-07-24 16:53 UTC (permalink / raw)


Hi

I'd like to fontify Ansys keywords.  The solver accepts unique short
forms of the command keywords, the rest is ignored.  For example the
uniqe part of `/filname' is `/fil' and I'd like to fontify

/fil and
/filn and
/filna and
/filnam and
/filname and

as well.  The only idea I got so far is to do it in 5 separate
font-lock statements:

\\(/fil\\) 1 font-lock...
/fil\\(n\\) 1 fon...
/filn\\(a\\) 1 ...
/filna\\(m\\) 1 ...
/filnam\\(e\\) 1 ...

Very ugly and inefficient, isn't it?
Originally I thought that something like this

/fil\\(n\\|na\\|nam\\|name\\)

would work but rexexp-bulider doesn't show any matches for the
complementing alternatives.

-- 
    Best wishes

    H. Dieter Wilhelm
    Darmstadt, Germany

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

* Re: font-lock regexp for complementary keywords
       [not found] <mailman.4440.1153819115.9609.help-gnu-emacs@gnu.org>
@ 2006-07-25 12:45 ` Johan Bockgård
  2006-07-27  8:21   ` Dieter Wilhelm
  0 siblings, 1 reply; 6+ messages in thread
From: Johan Bockgård @ 2006-07-25 12:45 UTC (permalink / raw)


Dieter Wilhelm <dieter@duenenhof-wilhelm.de> writes:

> I'd like to fontify Ansys keywords. The solver accepts unique short
> forms of the command keywords, the rest is ignored. For example the
> uniqe part of `/filname' is `/fil' and I'd like to fontify
>
> /fil and
> /filn and
> /filna and
> /filnam and
> /filname and

(regexp-opt
 '("fil"
   "filn"
   "filna"
   "filnam"
   "filname"))

=>

"fil\\(?:n\\(?:a\\(?:me?\\)?\\)?\\)?"

-- 
Johan Bockgård

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

* Re: font-lock regexp for complementary keywords
  2006-07-24 16:53 font-lock regexp for complementary keywords Dieter Wilhelm
@ 2006-07-25 16:15 ` Kevin Rodgers
       [not found] ` <mailman.4451.1153844221.9609.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2006-07-25 16:15 UTC (permalink / raw)


Dieter Wilhelm wrote:
> Hi
> 
> I'd like to fontify Ansys keywords.  The solver accepts unique short
> forms of the command keywords, the rest is ignored.  For example the
> uniqe part of `/filname' is `/fil' and I'd like to fontify
> 
> /fil and
> /filn and
> /filna and
> /filnam and
> /filname and
> 
> as well.  The only idea I got so far is to do it in 5 separate
> font-lock statements:
> 
> \\(/fil\\) 1 font-lock...
> /fil\\(n\\) 1 fon...
> /filn\\(a\\) 1 ...
> /filna\\(m\\) 1 ...
> /filnam\\(e\\) 1 ...

Why are you grouping and highlighting either "/fil" or the last letter?

> Very ugly and inefficient, isn't it?
> Originally I thought that something like this
> 
> /fil\\(n\\|na\\|nam\\|name\\)
> 
> would work but rexexp-bulider doesn't show any matches for the
> complementing alternatives.

"/fil\\(n\\(a\\(me?\\)?\\)?\\)?\\>" 0 font-lock...

-- 
Kevin

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

* Re: font-lock regexp for complementary keywords
  2006-07-25 12:45 ` Johan Bockgård
@ 2006-07-27  8:21   ` Dieter Wilhelm
  0 siblings, 0 replies; 6+ messages in thread
From: Dieter Wilhelm @ 2006-07-27  8:21 UTC (permalink / raw)
  Cc: ihs_4664


Thanks to Kevin and Johan

with your help I ended up having 3 working regexps to choose from ;-).

"fil\\(?:n\\(?:a\\(?:me?\\)?\\)?\\)?"
"/fil\\(n\\(a\\(me?\\)?\\)?\\)?"
"/fil\\(name\\|nam\\|na\\|a\\)"

I'll choose the first because it is supposed to be optimised (even
though it looks the most complicated).

bojohan+news@dd.chalmers.se (Johan Bockgård) writes:

> Dieter Wilhelm <dieter@duenenhof-wilhelm.de> writes:
>>
>> /fil and
>> /filn and
>> /filna and
>> /filnam and
>> /filname and

>
> (regexp-opt
>  '("fil"
>    "filn"
>    "filna"
>    "filnam"
>    "filname"))
>
> =>
>
> "fil\\(?:n\\(?:a\\(?:me?\\)?\\)?\\)?"

Emacs never ceases to astonish, I didn't know  regexp-opt exists.

> Kevin Rogers wrote:

> > \\(/fil\\) 1 font-lock...
> > /fil\\(n\\) 1 fon...
> > /filn\\(a\\) 1 ...
> > /filna\\(m\\) 1 ...
> > /filnam\\(e\\) 1 ...

> Why are you grouping and highlighting either "/fil" or the last letter?

because a previous font-lock regexp fontifies already the letters in
between, somehow I thought this more efficient than overwriting the
previous fontifications.

> "/fil\\(n\\(a\\(me?\\)?\\)?\\)?\\>" 0 font-lock...

I see, 0 means then all levels of groupings, good to know, thanks.

> > Originally I thought that something like this
> >
> > /fil\\(n\\|na\\|nam\\|name\\)

interesting enough, just the order was wrong not the principle

/fil\\(name\\|nam\\|na\\|a\\)

does the trick and for my brain it looks the easiest.

-- 
    Best wishes

    H. Dieter Wilhelm
    Darmstadt, Germany

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

* Re: font-lock regexp for complementary keywords
       [not found] ` <mailman.4451.1153844221.9609.help-gnu-emacs@gnu.org>
@ 2006-08-13 18:37   ` David Combs
  2006-08-16 12:18     ` Miles Bader
  0 siblings, 1 reply; 6+ messages in thread
From: David Combs @ 2006-08-13 18:37 UTC (permalink / raw)


In article <mailman.4451.1153844221.9609.help-gnu-emacs@gnu.org>,
Kevin Rodgers  <ihs_4664@yahoo.com> wrote:
>Dieter Wilhelm wrote:
>> Hi
>> 
>> I'd like to fontify Ansys keywords.  The solver accepts unique short
>> forms of the command keywords, the rest is ignored.  For example the
>> uniqe part of `/filname' is `/fil' and I'd like to fontify
>> 
>> /fil and
>> /filn and
>> /filna and
>> /filnam and
>> /filname and
>> 
>> as well.  The only idea I got so far is to do it in 5 separate
>> font-lock statements:
>> 
>> \\(/fil\\) 1 font-lock...
>> /fil\\(n\\) 1 fon...
>> /filn\\(a\\) 1 ...
>> /filna\\(m\\) 1 ...
>> /filnam\\(e\\) 1 ...
>
>Why are you grouping and highlighting either "/fil" or the last letter?
>
>> Very ugly and inefficient, isn't it?
>> Originally I thought that something like this
>> 
>> /fil\\(n\\|na\\|nam\\|name\\)
>> 
>> would work but rexexp-bulider doesn't show any matches for the
>> complementing alternatives.
>
>"/fil\\(n\\(a\\(me?\\)?\\)?\\)?\\>" 0 font-lock...

A really-stupid question:

That last line -- were it not elisp but eg postscript (or reverse polish),
I'd at least understand the syntax:  font-lock would (likely) take at least 
two args (would get stacked) and then font-lock (op) would would run.

But this *is* elisp, so just what is that expression?  It clearly
must be some part of a bigger expression, form, whatever.  Perhaps
you could show an example?

Thanks!

David

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

* Re: font-lock regexp for complementary keywords
  2006-08-13 18:37   ` David Combs
@ 2006-08-16 12:18     ` Miles Bader
  0 siblings, 0 replies; 6+ messages in thread
From: Miles Bader @ 2006-08-16 12:18 UTC (permalink / raw)


dkcombs@panix.com (David Combs) writes:
>>"/fil\\(n\\(a\\(me?\\)?\\)?\\)?\\>" 0 font-lock...
>
> But this *is* elisp, so just what is that expression?  It clearly
> must be some part of a bigger expression, form, whatever.  Perhaps
> you could show an example?

I presume it's an element of a font-lock keywords list.  See the
documentation of the variable `font-lock-keywords' for details.

-Miles

-- 
/\ /\
(^.^)
(")")
*This is the cute kitty virus, please copy this into your sig so it can spread.

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

end of thread, other threads:[~2006-08-16 12:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-24 16:53 font-lock regexp for complementary keywords Dieter Wilhelm
2006-07-25 16:15 ` Kevin Rodgers
     [not found] ` <mailman.4451.1153844221.9609.help-gnu-emacs@gnu.org>
2006-08-13 18:37   ` David Combs
2006-08-16 12:18     ` Miles Bader
     [not found] <mailman.4440.1153819115.9609.help-gnu-emacs@gnu.org>
2006-07-25 12:45 ` Johan Bockgård
2006-07-27  8:21   ` Dieter Wilhelm

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).