diff options
author | nyamatongwe <unknown> | 2011-03-22 14:20:58 +1100 |
---|---|---|
committer | nyamatongwe <unknown> | 2011-03-22 14:20:58 +1100 |
commit | 59a7e6a138648ceb391307ec531a5cda5893218c (patch) | |
tree | d49513e38c45d6c2e265275bc49e82a7b5e70f94 /lexers/LexPerl.cxx | |
parent | d9287400b1a01ccffeae58cc4cd5658bb19cea54 (diff) | |
download | scintilla-mirror-59a7e6a138648ceb391307ec531a5cda5893218c.tar.gz |
Folding for here docs and explicit folding comments. Feature #3116881.
From Jérôme LAFORGE. Also completes feature #3112671.
Diffstat (limited to 'lexers/LexPerl.cxx')
-rw-r--r-- | lexers/LexPerl.cxx | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/lexers/LexPerl.cxx b/lexers/LexPerl.cxx index 52a617d10..a7776ad3f 100644 --- a/lexers/LexPerl.cxx +++ b/lexers/LexPerl.cxx @@ -323,12 +323,16 @@ struct OptionsPerl { // Enable folding Pod blocks when using the Perl lexer. bool foldPackage; // property fold.perl.package // Enable folding packages when using the Perl lexer. + + bool foldCommentExplicit; + OptionsPerl() { fold = false; foldComment = false; foldCompact = true; foldPOD = true; foldPackage = true; + foldCommentExplicit = true; } }; @@ -351,6 +355,9 @@ struct OptionSetPerl : public OptionSet<OptionsPerl> { DefineProperty("fold.perl.package", &OptionsPerl::foldPackage, "Set to 0 to disable folding packages when using the Perl lexer."); + DefineProperty("fold.perl.comment.explicit", &OptionsPerl::foldCommentExplicit, + "Set to 0 to disable explicit folding."); + DefineWordListSets(perlWordListDesc); } }; @@ -1363,6 +1370,7 @@ void SCI_METHOD LexerPerl::Fold(unsigned int startPos, int length, int /* initSt chNext = styler.SafeGetCharAt(i + 1); int style = styleNext; styleNext = styler.StyleAt(i + 1); + int stylePrevCh = (i) ? styler.StyleAt(i - 1):SCE_PL_DEFAULT; bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); bool atLineStart = ((chPrev == '\r') || (chPrev == '\n')) || i == 0; // Comment folding @@ -1378,11 +1386,15 @@ void SCI_METHOD LexerPerl::Fold(unsigned int startPos, int length, int /* initSt // {} [] block folding if (style == SCE_PL_OPERATOR) { if (ch == '{') { + if (levelCurrent < levelPrev) + --levelPrev; levelCurrent++; } else if (ch == '}') { levelCurrent--; } if (ch == '[') { + if (levelCurrent < levelPrev) + --levelPrev; levelCurrent++; } else if (ch == ']') { levelCurrent--; @@ -1390,7 +1402,6 @@ void SCI_METHOD LexerPerl::Fold(unsigned int startPos, int length, int /* initSt } // POD folding if (options.foldPOD && atLineStart) { - int stylePrevCh = (i) ? styler.StyleAt(i - 1):SCE_PL_DEFAULT; if (style == SCE_PL_POD) { if (stylePrevCh != SCE_PL_POD && stylePrevCh != SCE_PL_POD_VERB) levelCurrent++; @@ -1418,6 +1429,45 @@ void SCI_METHOD LexerPerl::Fold(unsigned int startPos, int length, int /* initSt isPackageLine = true; } + //heredoc folding + switch (style) { + case SCE_PL_HERE_QQ : + case SCE_PL_HERE_Q : + case SCE_PL_HERE_QX : + switch (stylePrevCh) { + case SCE_PL_HERE_QQ : + case SCE_PL_HERE_Q : + case SCE_PL_HERE_QX : + //do nothing; + break; + default : + levelCurrent++; + break; + } + break; + default: + switch (stylePrevCh) { + case SCE_PL_HERE_QQ : + case SCE_PL_HERE_Q : + case SCE_PL_HERE_QX : + levelCurrent--; + break; + default : + //do nothing; + break; + } + break; + } + + //explicit folding + if (options.foldCommentExplicit && style == SCE_PL_COMMENTLINE && ch == '#') { + if (chNext == '{') { + levelCurrent++; + } else if (levelCurrent > SC_FOLDLEVELBASE && chNext == '}') { + levelCurrent--; + } + } + if (atEOL) { int lev = levelPrev; // POD headings occupy bits 7-4, leaving some breathing room for |