From 1701687494bc466a60c6ef0a0703ea6927483a75 Mon Sep 17 00:00:00 2001 From: Ernie Pasveer Date: Sat, 18 Oct 2025 11:24:20 -0500 Subject: [PATCH] Show syntax highlighing for C/C++, Rust and Odin. --- CHANGELOG.md | 1 + src/QHistoryLineEdit.cpp | 7 ++ src/QHistoryLineEdit.h | 2 + src/SeerEditorConfigPage.cpp | 95 ++++++++++++++++++++----- src/SeerEditorConfigPage.h | 3 + src/SeerEditorConfigPage.ui | 120 +++++++++++++++++++++++--------- src/SeerHighlighterSettings.cpp | 38 ++++++++-- src/SeerHighlighterSettings.h | 8 ++- src/SeerMainWindow.cpp | 10 +-- src/SeerSourceHighlighter.cpp | 7 +- 10 files changed, 227 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4736b1e..f93f2f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * SyntaxHighlighting: Refactored syntax highlighting code. Supports C/C++/Rust/Odin. (Thanks RaphGL!) * VariableTracker: Add 'deleteselect' and 'deleteall' to RMB context menu. * VariableLogger: Add 'deleteselect' and 'deleteall' to RMB context menu. +* EditorConfig: Show syntax highlighting for C/C++, Rust, and Odin. ## [2.6] - 2025-10-07 * Watchpoints: Fixed regression when adding commands to a watchpoint. diff --git a/src/QHistoryLineEdit.cpp b/src/QHistoryLineEdit.cpp index 1114841..c513c55 100644 --- a/src/QHistoryLineEdit.cpp +++ b/src/QHistoryLineEdit.cpp @@ -250,6 +250,13 @@ void QHistoryLineEdit::focusOutEvent (QFocusEvent* ev) { emit lostFocus(); } +void QHistoryLineEdit::focusInEvent (QFocusEvent* ev) { + + QLineEdit::focusInEvent(ev); + + emit gainedFocus(); +} + void QHistoryLineEdit::previousLine () { if ( _lines.empty() ) { diff --git a/src/QHistoryLineEdit.h b/src/QHistoryLineEdit.h index 62fdcf7..c62d815 100644 --- a/src/QHistoryLineEdit.h +++ b/src/QHistoryLineEdit.h @@ -52,11 +52,13 @@ class QHistoryLineEdit : public QLineEdit { signals: void lineExecuted (QString text); void lostFocus (); + void gainedFocus (); protected: void keyPressEvent (QKeyEvent* event) Q_DECL_OVERRIDE; void wheelEvent (QWheelEvent* event) Q_DECL_OVERRIDE; void focusOutEvent (QFocusEvent* event) Q_DECL_OVERRIDE; + void focusInEvent (QFocusEvent* event) Q_DECL_OVERRIDE; void previousLine (); void nextLine (); diff --git a/src/SeerEditorConfigPage.cpp b/src/SeerEditorConfigPage.cpp index c7a24f4..fb251e6 100644 --- a/src/SeerEditorConfigPage.cpp +++ b/src/SeerEditorConfigPage.cpp @@ -20,25 +20,17 @@ SeerEditorConfigPage::SeerEditorConfigPage(QWidget* parent) : QWidget(parent) { // Setup the widgets // - // Set example text. - editorWidget->sourceArea()->openText("/*\n" - " * Seer, Copyright 2021 (c)\n" - " * Ernie Pasveer (epasveer@att.net)\n" - " */\n" - "int main(int argc, char* argv[]) {\n" - "\n" - " std::cout << \"Hello, Seer!\"; // Greetings\n" - "\n" - " return 0;\n" - "}", - "sample.cpp"); - // Connect things. QObject::connect(fontSizeComboBox, &QComboBox::currentTextChanged, this, &SeerEditorConfigPage::handleFontSizeChanged); QObject::connect(fontNameComboBox, &QFontComboBox::currentFontChanged, this, &SeerEditorConfigPage::handleFontChanged); QObject::connect(fontDialogButton, &QToolButton::clicked, this, &SeerEditorConfigPage::handleFontDialog); QObject::connect(highlighterEnabledCheckBox, &QToolButton::clicked, this, &SeerEditorConfigPage::handleEnabledChanged); - QObject::connect(highlighterSuffixesLineEdit, &QHistoryLineEdit::lostFocus, this, &SeerEditorConfigPage::handleHighlighterChanged); + QObject::connect(cppSuffixesLineEdit, &QHistoryLineEdit::lostFocus, this, &SeerEditorConfigPage::handleHighlighterChanged); + QObject::connect(rustSuffixesLineEdit, &QHistoryLineEdit::lostFocus, this, &SeerEditorConfigPage::handleHighlighterChanged); + QObject::connect(odinSuffixesLineEdit, &QHistoryLineEdit::lostFocus, this, &SeerEditorConfigPage::handleHighlighterChanged); + QObject::connect(cppSuffixesLineEdit, &QHistoryLineEdit::gainedFocus, this, &SeerEditorConfigPage::handleCppSuffixFocusIn); + QObject::connect(rustSuffixesLineEdit, &QHistoryLineEdit::gainedFocus, this, &SeerEditorConfigPage::handleRustSuffixFocusIn); + QObject::connect(odinSuffixesLineEdit, &QHistoryLineEdit::gainedFocus, this, &SeerEditorConfigPage::handleOdinSuffixFocusIn); QObject::connect(themeApplyToolButton, &QToolButton::clicked, this, &SeerEditorConfigPage::handleApplyTheme); // Set the defaults. @@ -46,6 +38,9 @@ SeerEditorConfigPage::SeerEditorConfigPage(QWidget* parent) : QWidget(parent) { // Fill in the available theme names. themeComboBox->addItems(SeerHighlighterSettings::themeNames()); + + // Set example text. + handleCppSuffixFocusIn(); } SeerEditorConfigPage::~SeerEditorConfigPage() { @@ -145,12 +140,16 @@ void SeerEditorConfigPage::setHighlighterSettings (const SeerHighlighterSettings highlighterTableWidget->resizeColumnToContents(2); // Foreground color highlighterTableWidget->resizeColumnToContents(3); // Background color - highlighterSuffixesLineEdit->setText(_highlighterSettings.cppSourceSuffixes()); - highlighterSuffixesLineEdit->setCursorPosition(0); + cppSuffixesLineEdit->setText(_highlighterSettings.cppSourceSuffixes()); + cppSuffixesLineEdit->setCursorPosition(0); + rustSuffixesLineEdit->setText(_highlighterSettings.rustSourceSuffixes()); + rustSuffixesLineEdit->setCursorPosition(0); + odinSuffixesLineEdit->setText(_highlighterSettings.odinSourceSuffixes()); + odinSuffixesLineEdit->setCursorPosition(0); // Update our sample editor. editorWidget->sourceArea()->setHighlighterSettings(highlighterSettings()); - editorWidget->sourceArea()->setCurrentLine(9); + editorWidget->sourceArea()->setCurrentLine(0); } const SeerHighlighterSettings& SeerEditorConfigPage::highlighterSettings() const { @@ -288,7 +287,9 @@ void SeerEditorConfigPage::handleHighlighterChanged () { } // Get list of source suffixes. - languageSettings.setSourceSuffixes(highlighterSuffixesLineEdit->text()); + languageSettings.setCppSourceSuffixes(cppSuffixesLineEdit->text()); + languageSettings.setRustSourceSuffixes(rustSuffixesLineEdit->text()); + languageSettings.setOdinSourceSuffixes(odinSuffixesLineEdit->text()); // Update our view. setHighlighterSettings(languageSettings); @@ -304,3 +305,61 @@ void SeerEditorConfigPage::handleApplyTheme () { setHighlighterSettings(SeerHighlighterSettings::populate(themeComboBox->currentText())); } +void SeerEditorConfigPage::handleCppSuffixFocusIn () { + + // Set example text. + editorWidget->sourceArea()->openText("/*\n" + " * Seer, Copyright 2021 (c)\n" + " * Ernie Pasveer (epasveer@att.net)\n" + " * C/C++ example\n" + " */\n" + "\n" + "// This is the main function.\n" + "int main(int argc, char* argv[]) {\n" + "\n" + " std::cout << \"Hello, Seer!\"; // Greetings\n" + "\n" + " return 0;\n" + "}", + "sample.cpp"); + editorWidget->sourceArea()->setCurrentLine(0); +} + +void SeerEditorConfigPage::handleRustSuffixFocusIn () { + + // Set example text. + editorWidget->sourceArea()->openText("/*\n" + " * Seer, Copyright 2021 (c)\n" + " * Ernie Pasveer (epasveer@att.net)\n" + " * Rust example\n" + " */\n" + "\n" + "// This is the main function.\n" + "fn main() {\n" + " // Print text to the console.\n" + " println!(\"Hello World!\");\n" + "}", + "sample.rs"); + editorWidget->sourceArea()->setCurrentLine(0); +} + +void SeerEditorConfigPage::handleOdinSuffixFocusIn () { + + // Set example text. + editorWidget->sourceArea()->openText("/*\n" + " * Seer, Copyright 2021 (c)\n" + " * Ernie Pasveer (epasveer@att.net)\n" + " * Odin example\n" + " */\n" + "package main\n" + "\n" + "import \"core:fmt\"\n" + "\n" + "// This is the main function.\n" + "main :: proc() {\n" + " fmt.println(\"Hello, World!\")\n" + "}", + "sample.odin"); + editorWidget->sourceArea()->setCurrentLine(0); +} + diff --git a/src/SeerEditorConfigPage.h b/src/SeerEditorConfigPage.h index 0e87a3a..e772e04 100644 --- a/src/SeerEditorConfigPage.h +++ b/src/SeerEditorConfigPage.h @@ -42,6 +42,9 @@ class SeerEditorConfigPage : public QWidget, public Ui::SeerEditorConfigPage { void handleHighlighterChanged (); void handleEnabledChanged (); void handleApplyTheme (); + void handleCppSuffixFocusIn (); + void handleRustSuffixFocusIn (); + void handleOdinSuffixFocusIn (); private: QFont _font; diff --git a/src/SeerEditorConfigPage.ui b/src/SeerEditorConfigPage.ui index e105a12..f50164e 100644 --- a/src/SeerEditorConfigPage.ui +++ b/src/SeerEditorConfigPage.ui @@ -6,14 +6,14 @@ 0 0 - 728 - 876 + 660 + 703 SeerEditorConfigPage - + @@ -47,33 +47,6 @@ - - - - Enable or disable highlighting for supported languages' files. - - - Enable Syntax highlighting. - - - - - - - C/C++ source suffixes. Separated by '|'. - - - C/C++ source suffixes. - - - true - - - - - - - @@ -131,6 +104,23 @@ + + + + Qt::Vertical + + + + + + + Enable or disable highlighting for supported languages' files. + + + Syntax highlighting. + + + @@ -146,6 +136,70 @@ + + + + + + C/C++ + + + + + + + C/C++ source suffixes. Separated by '|'. + + + C/C++ source suffixes. + + + true + + + + + + + Rust + + + + + + + Rust source suffixes. Separated by '|'. + + + Rust source suffixes. + + + true + + + + + + + Odin + + + + + + + Odin source suffixes. Separated by '|'. + + + Odin source suffixes. + + + true + + + + + @@ -251,7 +305,7 @@ li.unchecked::marker { content: "\2610"; } li.checked::marker { content: "\2612"; } </style></head><body style=" font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;"> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Specify font and syntax highlighting colors for the code editor.</span></p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">These formats apply only when highlighting is enabled and if the file is C or C++.</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">These formats apply only when highlighting is enabled and if the file is one of the listed source suffixes.</p> <ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Class</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Comment</li> @@ -265,11 +319,11 @@ li.checked::marker { content: "\2612"; } <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Text</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Assembly Text</li> <li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Current Line</li></ul> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Syntax highlighting can be enabled or disabled. The list of suffixes for C/C++ source files can be changed. Example:</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Syntax highlighting can be enabled or disabled. The list of suffixes for supported source files can be changed. For example, C/C++ source files:</p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&quot;.h|.cpp|.c&quot;</p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The tab size, in spaces, can be set to properly display source files that contain tab characters.</p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">You can specify a command to launch an external editor. While in a source window, you can use the RMB menu to launch the external editor on the current file. However, these changes are not recognized by Seer. When specifying the command, you have these two variables. One for the name of the source file, and one for the line number to tell the editor to go to. Here are a few examples:</p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace'; ">geany &quot;%{file}&quot;:%{line}</span><span style=" font-family:'monospace'; "><br /></span><span style=" font-family:'monospace'; ">kate --line %{line} &quot;%{file}&quot;</span><span style=" font-family:'monospace'; "><br /></span><span style=" font-family:'monospace'; ">gedit &quot;%{file}&quot; +%{line}</span><span style=" font-family:'monospace'; "><br /></span><span style=" font-family:'monospace'; ">konsole -e vim &quot;%{file}&quot; +%{line}</span><span style=" font-family:'monospace';"><br /><br /></span>You may need to close and reopen the source files for changes to take effect.</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'monospace';">geany &quot;%{file}&quot;:%{line}<br />kate --line %{line} &quot;%{file}&quot;<br />gedit &quot;%{file}&quot; +%{line}<br />konsole -e vim &quot;%{file}&quot; +%{line}<br /><br /></span>You may need to close and reopen the source files for changes to take effect.</p> <p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> diff --git a/src/SeerHighlighterSettings.cpp b/src/SeerHighlighterSettings.cpp index 9b1fb24..7f37517 100644 --- a/src/SeerHighlighterSettings.cpp +++ b/src/SeerHighlighterSettings.cpp @@ -17,9 +17,11 @@ SeerHighlighterSettings::~SeerHighlighterSettings () { SeerHighlighterSettings& SeerHighlighterSettings::operator= (const SeerHighlighterSettings& rhs) { - _keys = rhs._keys; - _formats = rhs._formats; - _cppSourceSuffixes = rhs._cppSourceSuffixes; + _keys = rhs._keys; + _formats = rhs._formats; + _cppSourceSuffixes = rhs._cppSourceSuffixes; + _rustSourceSuffixes = rhs._rustSourceSuffixes; + _odinSourceSuffixes = rhs._odinSourceSuffixes; return *this; } @@ -70,16 +72,36 @@ int SeerHighlighterSettings::count () const { return _keys.size(); } -void SeerHighlighterSettings::setSourceSuffixes (const QString& suffixes) { +void SeerHighlighterSettings::setCppSourceSuffixes (const QString& suffixes) { _cppSourceSuffixes = suffixes; } +void SeerHighlighterSettings::setOdinSourceSuffixes (const QString& suffixes) { + + _odinSourceSuffixes = suffixes; +} + +void SeerHighlighterSettings::setRustSourceSuffixes (const QString& suffixes) { + + _rustSourceSuffixes = suffixes; +} + const QString& SeerHighlighterSettings::cppSourceSuffixes () { return _cppSourceSuffixes; } +const QString& SeerHighlighterSettings::odinSourceSuffixes () { + + return _odinSourceSuffixes; +} + +const QString& SeerHighlighterSettings::rustSourceSuffixes () { + + return _rustSourceSuffixes; +} + QStringList SeerHighlighterSettings::themeNames() { QStringList names; @@ -190,7 +212,9 @@ SeerHighlighterSettings SeerHighlighterSettings::populate_light () { f.setBackground(QColor("#ffffff")); languageSettings.add("Keyword", f); - languageSettings.setSourceSuffixes(".c|.C|.cpp|.CPP|.cxx|.CXX|.h|.H|.hpp|.hxx|.Hxx|.HXX"); + languageSettings.setCppSourceSuffixes(".c|.C|.cpp|.CPP|.cxx|.CXX|.h|.H|.hpp|.hxx|.Hxx|.HXX"); + languageSettings.setOdinSourceSuffixes(".odin"); + languageSettings.setRustSourceSuffixes(".rs"); return languageSettings; } @@ -285,7 +309,9 @@ SeerHighlighterSettings SeerHighlighterSettings::populate_dark () { f.setBackground(QColor("#232629")); languageSettings.add("Keyword", f); - languageSettings.setSourceSuffixes(".c|.C|.cpp|.CPP|.cxx|.CXX|.h|.H|.hpp|.hxx|.Hxx|.HXX"); + languageSettings.setCppSourceSuffixes(".c|.C|.cpp|.CPP|.cxx|.CXX|.h|.H|.hpp|.hxx|.Hxx|.HXX"); + languageSettings.setOdinSourceSuffixes(".odin"); + languageSettings.setRustSourceSuffixes(".rs"); return languageSettings; } diff --git a/src/SeerHighlighterSettings.h b/src/SeerHighlighterSettings.h index 0783ce4..9be12f1 100644 --- a/src/SeerHighlighterSettings.h +++ b/src/SeerHighlighterSettings.h @@ -23,8 +23,12 @@ class SeerHighlighterSettings { QTextCharFormat get (const QString& name) const; void add (const QString& name, QTextCharFormat& format); int count () const; - void setSourceSuffixes (const QString& suffixes); + void setCppSourceSuffixes (const QString& suffixes); + void setOdinSourceSuffixes (const QString& suffixes); + void setRustSourceSuffixes (const QString& suffixes); const QString& cppSourceSuffixes (); + const QString& odinSourceSuffixes (); + const QString& rustSourceSuffixes (); static QStringList themeNames (); static SeerHighlighterSettings populate (const QString& themeName); @@ -35,5 +39,7 @@ class SeerHighlighterSettings { QList _keys; QList _formats; QString _cppSourceSuffixes; + QString _odinSourceSuffixes; + QString _rustSourceSuffixes; }; diff --git a/src/SeerMainWindow.cpp b/src/SeerMainWindow.cpp index 66807cd..6e7745d 100644 --- a/src/SeerMainWindow.cpp +++ b/src/SeerMainWindow.cpp @@ -1552,7 +1552,9 @@ void SeerMainWindow::writeConfigSettings () { } settings.endGroup(); } - settings.setValue("suffixes", highlighter.cppSourceSuffixes()); + settings.setValue("cppsuffixes", highlighter.cppSourceSuffixes()); + settings.setValue("odinsuffixes", highlighter.odinSourceSuffixes()); + settings.setValue("rustsuffixes", highlighter.rustSourceSuffixes()); } settings.endGroup(); } settings.endGroup(); @@ -1651,9 +1653,9 @@ void SeerMainWindow::readConfigSettings () { } settings.endGroup(); } - if (settings.contains("suffixes")) { - highlighter.setSourceSuffixes(settings.value("suffixes").toString()); - } + if (settings.contains("cppsuffixes")) highlighter.setCppSourceSuffixes(settings.value("cppsuffixes").toString()); + if (settings.contains("odinsuffixes")) highlighter.setOdinSourceSuffixes(settings.value("odinsuffixes").toString()); + if (settings.contains("rustsuffixes")) highlighter.setRustSourceSuffixes(settings.value("rustsuffixes").toString()); gdbWidget->editorManager()->setEditorHighlighterSettings(highlighter); diff --git a/src/SeerSourceHighlighter.cpp b/src/SeerSourceHighlighter.cpp index a8cdca4..e3a8ec0 100644 --- a/src/SeerSourceHighlighter.cpp +++ b/src/SeerSourceHighlighter.cpp @@ -14,16 +14,19 @@ const SeerHighlighterSettings& SeerSourceHighlighter::highlighterSettings() { } SeerSourceHighlighter* SeerSourceHighlighter::getSourceHighlighter(QString const& file, SeerHighlighterSettings settings) { + QRegularExpression cpp_re("(?:" + settings.cppSourceSuffixes() + ")$"); if (file.contains(cpp_re)) { return new SeerCppSourceHighlighter(0); } - if (file.endsWith(".odin")) { + QRegularExpression odin_re("(?:" + settings.odinSourceSuffixes() + ")$"); + if (file.contains(odin_re)) { return new SeerOdinSourceHighlighter(0); } - if (file.endsWith(".rs")) { + QRegularExpression rust_re("(?:" + settings.rustSourceSuffixes() + ")$"); + if (file.contains(rust_re)) { return new SeerRustSourceHighlighter(0); }