]> git.lyx.org Git - features.git/commitdiff
Source highlighting of comments (by Bernhard Reiter)
authorPavel Sanda <sanda@lyx.org>
Mon, 26 Nov 2007 21:48:41 +0000 (21:48 +0000)
committerPavel Sanda <sanda@lyx.org>
Mon, 26 Nov 2007 21:48:41 +0000 (21:48 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21803 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/LaTeXHighlighter.cpp

index 38715471f7bf4a02f75f0d0119020db0cc18e079..30a50f8123dc487b8b853833fa660420e32bd0aa 100644 (file)
@@ -85,13 +85,21 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
                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);
        }
 }