From 2c2e23b4f48b7c631e00e774c01ec73c49ef5039 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 16 Sep 2016 09:00:09 -0400 Subject: Fix up the highlighting of characters where the start character is already within a different highlight block (do not stack them - that start char was already handled and is off limits). --- src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h | 2 +- src-qt5/desktop-utils/lumina-textedit/tests/test.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h index 781ff65d..f834e275 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h @@ -101,7 +101,7 @@ protected: if(splitactive>=0 || index=0){ int len = patt.matchedLength(); - setFormat(index, len, rules[i].format); + if(format(index)==currentBlock().charFormat()){ setFormat(index, len, rules[i].format); } //only apply highlighting if not within a section already index = patt.indexIn(text, index+len); //go to the next match } }//end loop over normal (single-line) patterns diff --git a/src-qt5/desktop-utils/lumina-textedit/tests/test.cpp b/src-qt5/desktop-utils/lumina-textedit/tests/test.cpp index 1b50e302..e135227d 100644 --- a/src-qt5/desktop-utils/lumina-textedit/tests/test.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/tests/test.cpp @@ -13,3 +13,6 @@ comment */ stuff some /*single line comment with multi-line tags */ + +"some text" +"some text with url: http://sample.com" -- cgit From 088eebf68aa06de3e9ec34ed9bbcc08625d44a9e Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 16 Sep 2016 09:42:50 -0400 Subject: Add syntax highlighting for "shell" files (.sh) --- .../lumina-textedit/syntaxSupport.cpp | 62 ++++++++++++++++++++++ .../desktop-utils/lumina-textedit/tests/test.sh | 10 ++++ 2 files changed, 72 insertions(+) create mode 100644 src-qt5/desktop-utils/lumina-textedit/tests/test.sh (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp index 7dcad6c3..0edb2160 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp @@ -10,6 +10,7 @@ QStringList Custom_Syntax::availableRules(){ QStringList avail; avail << "C++"; //avail << "Python"; + avail << "Shell"; avail << "reST"; return avail; } @@ -40,6 +41,7 @@ QString Custom_Syntax::ruleForFile(QString filename){ QString suffix = filename.section(".",-1); if(suffix=="cpp" || suffix=="hpp" || suffix=="c" || suffix=="h"){ return "C++"; } //else if(suffix=="py" || suffix=="pyc"){ return "Python"; } + else if(suffix=="sh"){ return "Shell"; } else if(suffix=="rst"){ return "reST"; } return ""; } @@ -101,6 +103,66 @@ void Custom_Syntax::loadRules(QString type){ srule.endPattern = QRegExp("\\*/"); splitrules << srule; + }else if(type=="Shell"){ + //Keywords (standard Shell definitions) + QStringList keywords; + keywords << "alias" << "alloc" << "bg" << "bind" << " bindkey" << "break" \ + << "breaksw"<<"builtins"<<"case"<<"cd"<<"chdir"<<"command"<<"complete"<<"continue"<<"default" \ + <<"dirs"<<"do"<<"done"<<"echo"<<"echotc"<<"elif"<<"else"<<"end"<<"endif"<<"endsw"<<"esac"<<"eval" \ + <<"exec"<<"exit"<<"export"<<"false"<<"fc"<<"fg"<<"filetest"<<"fi"<<"for"<<"foreach"<<"getopts" \ + <<"glob"<<"goto"<<"hash"<<"hashstat"<<"history"<<"hup"<<"if"<<"jobid"<<"jobs"<<"kill"<<"limit" \ + <<"local"<<"log"<<"login"<<"logout"<<"ls-F"<<"nice"<<"nohup"<<"notify"<<"onintr"<<"popd" \ + <<"printenv"<<"printf"<<"pushd"<<"pwd"<<"read"<<"readonly"<<"rehash"<<"repeat"<<"return" \ + <<"sched"<<"set"<<"setenv"<<"settc"<<"setty"<<"setvar"<<"shift"<<"source"<<"stop"<<"suspend" \ + <<"switch"<<"telltc"<<"test"<<"then"<<"time"<<"times"<<"trap"<<"true"<<"type"<<"ulimit"<<"umask" \ + <<"unalias"<<"uncomplete"<<"unhash"<<"unlimit"<<"unset"<<"unsetenv"<<"until"<<"wait" \ + <<"where"<<"which"<<"while"; + + SyntaxRule rule; + rule.format.setForeground( QColor(settings->value("colors/keyword").toString()) ); + rule.format.setFontWeight(QFont::Bold); + for(int i=0; ivalue("colors/altkeyword").toString()) ); + for(int i=0; ivalue("colors/class").toString()) ); + rule.pattern = QRegExp("\\$\\{[^\\n\\}]+\\}"); + rules << rule; + rule.pattern = QRegExp("\\$[^\\s$]+(?=\\s|$)"); + rules << rule; + //Quotes + rule.format.setForeground( QColor(settings->value("colors/text").toString()) ); + rule.format.setFontWeight(QFont::Normal); + rule.pattern = QRegExp( "\"[^\"\\\\]*(\\\\(.|\\n)[^\"\\\\]*)*\"|'[^'\\\\]*(\\\\(.|\\n)[^'\\\\]*)*'"); + rules << rule; + //Functions + rule.format.setForeground( QColor(settings->value("colors/function").toString()) ); + rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()"); + rules << rule; + //Proprocessor commands + rule.format.setForeground( QColor(settings->value("colors/preprocessor").toString()) ); + rule.pattern = QRegExp("^#![^\n]*"); + rules << rule; + //Comment (single line) + rule.format.setForeground( QColor(settings->value("colors/comment").toString()) ); + rule.pattern = QRegExp("#[^\n]*"); + rules << rule; + //Comment (multi-line) + //SyntaxRuleSplit srule; + //srule.format = rule.format; //re-use the single-line comment format + //srule.startPattern = QRegExp("/\\*"); + //srule.endPattern = QRegExp("\\*/"); + //splitrules << srule; + }else if(type=="Python"){ //Keywords QStringList keywords; diff --git a/src-qt5/desktop-utils/lumina-textedit/tests/test.sh b/src-qt5/desktop-utils/lumina-textedit/tests/test.sh new file mode 100644 index 00000000..8eb7450c --- /dev/null +++ b/src-qt5/desktop-utils/lumina-textedit/tests/test.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +echo "some text" #with a comment +for i in ["a","b","c"] +do +echo ${i}withsometext +done + +variable$variable sdfgbuj +variable${variable}satoibnsoin -- cgit