> I wrote: > > > ATM, in the source view (eg in the preamble), the last character before > > a comment (ie percent sign) is greyed out as if part of the comment. The > > attached patch should fix this behavior. > > Makes me wonder whether we need a regexp (and not of the most readable > kind) for such a mundane task.
Agree, in principle. Still, I don't know if I could do it much more lucidly just using qt's string functions. > Also, the code does not get the case > \\%comment > right. See attached; it now does get even numbers of backslashes right. Bernhard Reiter
Index: src/frontends/qt4/LaTeXHighlighter.cpp =================================================================== --- src/frontends/qt4/LaTeXHighlighter.cpp (Revision 21664) +++ src/frontends/qt4/LaTeXHighlighter.cpp (Arbeitskopie) @@ -85,13 +85,21 @@ setFormat(index, length, keywordFormat); index = text.indexOf(exprKeyword, index + length); } - // comment - static const QRegExp exprComment("(^|[^\\\\])%.*$"); - index = text.indexOf(exprComment); + // %comment + // Treat a line as a comment starting at a percent sign + // * that is the first character in a line + // * that is preceded by + // ** an even number of backslashes + // ** any character other than a backslash + QRegExp exprComment("(?:^|[^\\\\])(?:\\\\\\\\)*(%).*$"); + text.indexOf(exprComment); + index = exprComment.pos(1); while (index >= 0) { - int const length = exprComment.matchedLength(); + int const length = exprComment.matchedLength() + - (index - exprComment.pos(0)); setFormat(index, length, commentFormat); - index = text.indexOf(exprComment, index + length); + text.indexOf(exprComment, index + length); + index = exprComment.pos(1); } }