]> git.lyx.org Git - features.git/commitdiff
LaTeX highlighter: make at a letter in the user preamble
authorGuillaume Munch <gm@lyx.org>
Fri, 15 Jul 2016 16:45:47 +0000 (17:45 +0100)
committerGuillaume Munch <gm@lyx.org>
Fri, 15 Jul 2016 16:51:18 +0000 (17:51 +0100)
Syntax highlighting now provides the appropriate cue that the user preamble is
inside \makeatletter…\makeatother.

src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/LaTeXHighlighter.cpp
src/frontends/qt4/LaTeXHighlighter.h

index 6f87dff11f5582b646359b9652f89c3d1d55ac0a..3faa902936b801c01968145267c3b0c134b7c9ad 100644 (file)
@@ -453,7 +453,8 @@ PreambleModule::PreambleModule() : current_id_(0)
 {
        // This is not a memory leak. The object will be destroyed
        // with this.
-       (void) new LaTeXHighlighter(preambleTE->document());
+       // @ is letter in the LyX user preamble
+       (void) new LaTeXHighlighter(preambleTE->document(), true);
        preambleTE->setFont(guiApp->typewriterSystemFont());
        preambleTE->setWordWrapMode(QTextOption::NoWrap);
        setFocusProxy(preambleTE);
index fa949a6e625540bb053d6c31da47f6090f3d1392..ee32cd002a14ab7ae7f5a14af21566f026475c0b 100644 (file)
@@ -20,8 +20,9 @@ namespace lyx {
 namespace frontend {
 
 
-LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent)
-       : QSyntaxHighlighter(parent)
+LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent,
+                                   bool const at_letter)
+       : QSyntaxHighlighter(parent), at_letter_(at_letter)
 {
        auto blend = [](QColor color1, QColor color2) {
                int r = 0.5 * (color1.red() + color2.red());
@@ -91,7 +92,11 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
                startIndex = exprStartDispMath.indexIn(text, startIndex + length);
        }
        // \whatever
-       static const QRegExp exprKeyword("\\\\[A-Za-z]+");
+       static const QRegExp exprKeywordAtOther("\\\\[A-Za-z]+");
+       // \wh@tever
+       static const QRegExp exprKeywordAtLetter("\\\\[A-Za-z@]+");
+       QRegExp const & exprKeyword = at_letter_ ? exprKeywordAtLetter
+                                                : exprKeywordAtOther;
        index = exprKeyword.indexIn(text);
        while (index >= 0) {
                int length = exprKeyword.matchedLength();
index 51da3672c1899a757ef1ca805b9c42190d297ac1..21621bba5cb150404690548ff5538d0e097fa06c 100644 (file)
@@ -25,7 +25,8 @@ namespace frontend {
 class LaTeXHighlighter : public QSyntaxHighlighter
 {
 public:
-       LaTeXHighlighter(QTextDocument * parent);
+       explicit LaTeXHighlighter(QTextDocument * parent,
+                                 bool const at_letter = false);
 
 protected:
        void highlightBlock(QString const & text);
@@ -35,6 +36,8 @@ private:
        QTextCharFormat keywordFormat;
        QTextCharFormat mathFormat;
        QTextCharFormat warningFormat;
+       // is at a letter (as in the preamble)
+       bool const at_letter_;
 };
 
 } // namespace frontend