From 10f6eb2e7eeffc757b7f54059524441e90008240 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Fri, 15 Jul 2016 17:45:47 +0100 Subject: [PATCH] LaTeX highlighter: make at a letter in the user preamble MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Syntax highlighting now provides the appropriate cue that the user preamble is inside \makeatletter…\makeatother. --- src/frontends/qt4/GuiDocument.cpp | 3 ++- src/frontends/qt4/LaTeXHighlighter.cpp | 11 ++++++++--- src/frontends/qt4/LaTeXHighlighter.h | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 6f87dff11f..3faa902936 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -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); diff --git a/src/frontends/qt4/LaTeXHighlighter.cpp b/src/frontends/qt4/LaTeXHighlighter.cpp index fa949a6e62..ee32cd002a 100644 --- a/src/frontends/qt4/LaTeXHighlighter.cpp +++ b/src/frontends/qt4/LaTeXHighlighter.cpp @@ -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(); diff --git a/src/frontends/qt4/LaTeXHighlighter.h b/src/frontends/qt4/LaTeXHighlighter.h index 51da3672c1..21621bba5c 100644 --- a/src/frontends/qt4/LaTeXHighlighter.h +++ b/src/frontends/qt4/LaTeXHighlighter.h @@ -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 -- 2.39.5