diff options
author | Weblate <noreply@weblate.org> | 2016-09-16 19:38:09 +0000 |
---|---|---|
committer | Weblate <noreply@weblate.org> | 2016-09-16 19:38:09 +0000 |
commit | 531690a5121ed0393127eaa7506e57ae5097c338 (patch) | |
tree | a4a1eb081ea417d0bdc768d2cabc50d91770f319 /src-qt5/desktop-utils/lumina-textedit | |
parent | Translated using Weblate (lumina_CONFIG@fa (generated)) (diff) | |
parent | Add syntax highlighting for "shell" files (.sh) (diff) | |
download | lumina-531690a5121ed0393127eaa7506e57ae5097c338.tar.gz lumina-531690a5121ed0393127eaa7506e57ae5097c338.tar.bz2 lumina-531690a5121ed0393127eaa7506e57ae5097c338.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src-qt5/desktop-utils/lumina-textedit')
4 files changed, 76 insertions, 1 deletions
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; i<keywords.length(); i++){ + rule.pattern = QRegExp("\\b"+keywords[i]+"\\b"); //turn each keyword into a QRegExp and insert the rule + rules << rule; + } + //Alternate Keywords (built-in functions) + /*keywords.clear(); + keywords << "for" << "while" << "switch" << "case" << "if" << "else" << "return" << "exit"; + rule.format.setForeground( QColor(settings->value("colors/altkeyword").toString()) ); + for(int i=0; i<keywords.length(); i++){ + rule.pattern = QRegExp("\\b"+keywords[i]+"\\b"); //turn each keyword into a QRegExp and insert the rule + rules << rule; + }*/ + //Variable Names + rule.format.setForeground( QColor(settings->value("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/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<start){ continue; } //skip this one - falls within a multi-line pattern above while(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" 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 |