]> 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>
Sun, 28 Aug 2016 01:38:02 +0000 (02:38 +0100)
Syntax highlighting now provides the appropriate cue that the user preamble is
inside \makeatletter…\makeatother.

(cherry picked from commit 10f6eb2e7eeffc757b7f54059524441e90008240)

src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/LaTeXHighlighter.cpp
src/frontends/qt4/LaTeXHighlighter.h
status.22x

index e6d93faae565f84ad41ef962c15a5b42b3c024ce..aad62014e5990cc358591c167a43997caf9482a4 100644 (file)
@@ -452,7 +452,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 81e6f5769c8bc276173504dca0cb67d5453a4dc7..c655b364d9a86442ee325c2da1fe9ebc6fe8e7f9 100644 (file)
@@ -31,8 +31,8 @@ QColor blend(QColor color1, QColor color2) {
 }
 
 
-LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent)
-       : QSyntaxHighlighter(parent)
+LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent, bool at_letter)
+       : QSyntaxHighlighter(parent), at_letter_(at_letter)
 {
        QPalette palette = QPalette();
        QColor text_color = palette.color(QPalette::Active, QPalette::Text);
@@ -96,7 +96,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..c780b9ffb7f1d841df71a75a4e030e4356ee5ab0 100644 (file)
@@ -25,7 +25,7 @@ namespace frontend {
 class LaTeXHighlighter : public QSyntaxHighlighter
 {
 public:
-       LaTeXHighlighter(QTextDocument * parent);
+       explicit LaTeXHighlighter(QTextDocument * parent, bool at_letter = false);
 
 protected:
        void highlightBlock(QString const & text);
@@ -35,6 +35,8 @@ private:
        QTextCharFormat keywordFormat;
        QTextCharFormat mathFormat;
        QTextCharFormat warningFormat;
+       // is at a letter? (as in the preamble)
+       bool const at_letter_;
 };
 
 } // namespace frontend
index 6a0559786199ecfb32505e629b876166c47f218c..f4bc1bc68d319d9313f87f232005f1c38cbefdda 100644 (file)
@@ -21,9 +21,12 @@ What's new
 
 * USER INTERFACE
 
-* When changing zoom level, show current value in status bar (bug
+- When changing zoom level, show current value in status bar (bug
   10212).
 
+- Names containing @ are now recognised by the syntax highlighter in the
+  preamble.
+
 
 * DOCUMENTATION AND LOCALIZATION