diff options
-rw-r--r-- | src/LexPerl.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/LexPerl.cxx b/src/LexPerl.cxx index 6bac381d9..eff351151 100644 --- a/src/LexPerl.cxx +++ b/src/LexPerl.cxx @@ -925,19 +925,26 @@ static void FoldPerlDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) { bool foldComment = styler.GetPropertyInt("fold.comment") != 0; bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0; + // Custom folding of POD and packages + bool foldPOD = styler.GetPropertyInt("fold.perl.pod", 1) != 0; + bool foldPackage = styler.GetPropertyInt("fold.perl.package", 1) != 0; unsigned int endPos = startPos + length; int visibleChars = 0; int lineCurrent = styler.GetLine(startPos); int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; int levelCurrent = levelPrev; char chNext = styler[startPos]; + char chPrev = styler.SafeGetCharAt(startPos - 1); int styleNext = styler.StyleAt(startPos); + // Used at end of line to determine if the line was a package definition + bool isPackageLine = false; for (unsigned int i = startPos; i < endPos; i++) { char ch = chNext; chNext = styler.SafeGetCharAt(i + 1); int style = styleNext; styleNext = styler.StyleAt(i + 1); bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); + bool atLineStart = isEOLChar(chPrev) || i == 0; if (foldComment && (style == SCE_PL_COMMENTLINE)) { if ((ch == '/') && (chNext == '/')) { char chNext2 = styler.SafeGetCharAt(i + 2); @@ -955,6 +962,23 @@ static void FoldPerlDoc(unsigned int startPos, int length, int, WordList *[], levelCurrent--; } } + // Custom POD folding + if (foldPOD && atLineStart) { + int stylePrevCh = (i) ? styler.StyleAt(i - 1):SCE_PL_DEFAULT; + if (style == SCE_PL_POD) { + if (stylePrevCh != SCE_PL_POD) + levelCurrent++; + if (styler.Match(i, "=cut")) + levelCurrent--; + } + } + // Custom package folding + if (foldPackage && atLineStart) { + if (style == SCE_PL_WORD && styler.Match(i, "package")) { + isPackageLine = true; + } + } + if (atEOL) { int lev = levelPrev; if (visibleChars == 0 && foldCompact) @@ -964,12 +988,20 @@ static void FoldPerlDoc(unsigned int startPos, int length, int, WordList *[], if (lev != styler.LevelAt(lineCurrent)) { styler.SetLevel(lineCurrent, lev); } + // Check if line was a package declaration + // because packages need "special" treatment + if (isPackageLine) { + styler.SetLevel(lineCurrent, SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG); + levelCurrent = SC_FOLDLEVELBASE + 1; + isPackageLine = false; + } lineCurrent++; levelPrev = levelCurrent; visibleChars = 0; } if (!isspacechar(ch)) visibleChars++; + chPrev = ch; } // Fill in the real level of the next line, keeping the current flags as they will be filled in later int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; |