aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/LexPowerShell.cxx
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2008-02-25 00:37:37 +0000
committernyamatongwe <devnull@localhost>2008-02-25 00:37:37 +0000
commit0166dba6ccf4777d1daa763fb5cf09d64148d9d5 (patch)
tree3097197f810e5cd22d6fceb68999e7a5d0ee09d4 /src/LexPowerShell.cxx
parent53ba51a96d0923da63ea3fe65ae1a4f09d0df728 (diff)
downloadscintilla-mirror-0166dba6ccf4777d1daa763fb5cf09d64148d9d5.tar.gz
Folder added.
Diffstat (limited to 'src/LexPowerShell.cxx')
-rw-r--r--src/LexPowerShell.cxx66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/LexPowerShell.cxx b/src/LexPowerShell.cxx
index 77d192f7a..d16ba9842 100644
--- a/src/LexPowerShell.cxx
+++ b/src/LexPowerShell.cxx
@@ -106,6 +106,70 @@ static void ColourisePowerShellDoc(unsigned int startPos, int length, int initSt
sc.Complete();
}
+// Store both the current line's fold level and the next lines in the
+// level store to make it easy to pick up with each increment
+// and to make it possible to fiddle the current level for "} else {".
+static void FoldPowerShellDoc(unsigned int startPos, int length, int,
+ WordList *[], Accessor &styler) {
+ bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
+ bool foldAtElse = styler.GetPropertyInt("fold.at.else", 0) != 0;
+ unsigned int endPos = startPos + length;
+ int visibleChars = 0;
+ int lineCurrent = styler.GetLine(startPos);
+ int levelCurrent = SC_FOLDLEVELBASE;
+ if (lineCurrent > 0)
+ levelCurrent = styler.LevelAt(lineCurrent-1) >> 16;
+ int levelMinCurrent = levelCurrent;
+ int levelNext = levelCurrent;
+ char chNext = styler[startPos];
+ int styleNext = styler.StyleAt(startPos);
+ 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');
+ if (style == SCE_POWERSHELL_OPERATOR) {
+ if (ch == '{') {
+ // Measure the minimum before a '{' to allow
+ // folding on "} else {"
+ if (levelMinCurrent > levelNext) {
+ levelMinCurrent = levelNext;
+ }
+ levelNext++;
+ } else if (ch == '}') {
+ levelNext--;
+ }
+ }
+ if (!IsASpace(ch))
+ visibleChars++;
+ if (atEOL || (i == endPos-1)) {
+ int levelUse = levelCurrent;
+ if (foldAtElse) {
+ levelUse = levelMinCurrent;
+ }
+ int lev = levelUse | levelNext << 16;
+ if (visibleChars == 0 && foldCompact)
+ lev |= SC_FOLDLEVELWHITEFLAG;
+ if (levelUse < levelNext)
+ lev |= SC_FOLDLEVELHEADERFLAG;
+ if (lev != styler.LevelAt(lineCurrent)) {
+ styler.SetLevel(lineCurrent, lev);
+ }
+ lineCurrent++;
+ levelCurrent = levelNext;
+ levelMinCurrent = levelCurrent;
+ visibleChars = 0;
+ }
+ }
+}
+
+static const char * const powershellWordLists[] = {
+ "Commands",
+ "Cmdlets",
+ "Aliases",
+ 0
+};
-LexerModule lmPowerShell(SCLEX_POWERSHELL, ColourisePowerShellDoc, "powershell");
+LexerModule lmPowerShell(SCLEX_POWERSHELL, ColourisePowerShellDoc, "powershell", FoldPowerShellDoc, powershellWordLists);