[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX-devel] Regex best practice
From: |
Mosè Giordano |
Subject: |
Re: [AUCTeX-devel] Regex best practice |
Date: |
Tue, 24 Nov 2015 21:58:22 +0100 |
Hi Arash,
2015-11-24 21:13 GMT+01:00 Arash Esbati <address@hidden>:
> Hi Mosè,
>
> Mosè Giordano <address@hidden> writes:
>
>> Probably yes: so you want to match the whole \declaretheoremstyle
>> macro, but saving only the mandatory argument, right?
>
> Yes, exactly.
The problem of your regex is that will match *everything* until the
last closing bracket. This is good when you test your regex in a
simple case, but will fail in a real document with other commands
taking optional and mandatory arguments. Consider for example
--8<---------------cut here---------------start------------->8---
\declaresomething[%
key = value ,
name = {[Optional]Value} ,
anothername = {valu-es[]}]{} ,
colframe = red!75!black ,
fonttitle = \bfseries ,
enhanced ,
attach boxed = {yshift=-2mm} ,
title = #2
]
{
some1thing
}
\othercommand[optional]{mandatory}
--8<---------------cut here---------------end--------------->8---
`re-builder' highlights "mandatory", with your regex. In addition, it
doesn't seem to work at all with XEmacs, but I don't know why.
Is the non paired "]" in
anothername = {valu-es[]}]{} ,
intended? If so, I don't have a solution at hand, otherwise, if
you're sure you have always paired brackets, you can use something
like
"\\\\declaresomething\\[\\(?:[^][]*\\(?:\\[[^][]*\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\][^][]*\\)*\\][^][]*\\)*\\)\\][
\t\n\r]*{[ \t\n\r]*\\(.*\\)[ \t\n\r]*}"
(I'm sorry for the hard-wrapping, replace the newline with a space)
which is inspired by `LaTeX-auto-index-regexp-list'.
Bye,
Mosè