help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regexp-opt for all kinds of strings


From: Tim X
Subject: Re: regexp-opt for all kinds of strings
Date: Fri, 20 Jul 2007 13:04:14 +1000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

Nordlöw <per.nordlow@gmail.com> writes:

> Hey there!
>
> Why aren't all kinds of characters allowed in regexp-opt()? I am doing
> syntax highlighting of operators in c-mode and would like regexp-opt
> to work for lists such:
>   '("+" "-" "*" "/" "++" "--")
>
> Have I missed something. Or is the feature a TODO?
>
>

As far as I know, the restrictions you reference don't exist. However, it is
possible you are trying to use the wrong tool. In what way did you find it
didn't work? The problem could be with boundry situations i.e. only matches
' ++ ' and not the ++ in ++foo or foo++ etc.

The regexp-opt is really best applied when you have sets of distinct "words"
that you want to match. From your description, I suspect that what you want is
just a fairly simple regexp. (One restriction of regexp-opt is that you cannot
have regexps in the list). 

If you just want to match the operators like ++, * and - etc, I suspect you
would be better off with just a normal regexp. While regexp-opt is really handy
when you have quite long lists of words to match and is pretty good at
optimizing the resulting regexp, for simpler patterns, it really is overkill. 

Maybe if you explain exactly what you are trying to achieve people on this list
may be able to provide useful examples/suggestions.

regards,

Tim

-- 
tcross (at) rapttech dot com dot au


reply via email to

[Prev in Thread] Current Thread [Next in Thread]