From e06e7c881753caff472550cf744d5ce10594fe9f Mon Sep 17 00:00:00 2001 From: darmar Date: Tue, 18 Apr 2017 10:02:00 +1000 Subject: Bug [#1936]. Implement comment folding. --- doc/ScintillaHistory.html | 4 + lexers/LexFortran.cxx | 220 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 215 insertions(+), 9 deletions(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 47ab6305d..6001a4802 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -541,6 +541,10 @@ Bug #1935.
  • + The Fortran folder can fold comments. + Bug #1936. +
  • +
  • The PowerShell lexer recognizes escaped quotes in strings. Bug #1929.
  • diff --git a/lexers/LexFortran.cxx b/lexers/LexFortran.cxx index 641702893..495b00215 100644 --- a/lexers/LexFortran.cxx +++ b/lexers/LexFortran.cxx @@ -227,7 +227,7 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int if (sc.state == SCE_F_DEFAULT) { if (sc.ch == '!') { if (sc.MatchIgnoreCase("!dec$") || sc.MatchIgnoreCase("!dir$") || - sc.MatchIgnoreCase("!ms$") || sc.chNext == '$') { + sc.MatchIgnoreCase("!ms$") || sc.chNext == '$') { sc.SetState(SCE_F_PREPROCESSOR); } else { sc.SetState(SCE_F_COMMENT); @@ -237,7 +237,7 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int } else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) { sc.SetState(SCE_F_NUMBER); } else if ((tolower(sc.ch) == 'b' || tolower(sc.ch) == 'o' || - tolower(sc.ch) == 'z') && (sc.chNext == '\"' || sc.chNext == '\'')) { + tolower(sc.ch) == 'z') && (sc.chNext == '\"' || sc.chNext == '\'')) { sc.SetState(SCE_F_NUMBER); sc.Forward(); } else if (sc.ch == '.' && isalpha(sc.chNext)) { @@ -256,6 +256,165 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int sc.Complete(); } /***************************************/ +static void CheckLevelCommentLine(const unsigned int nComL, + int nComColB[], int nComColF[], int &nComCur, + bool comLineB[], bool comLineF[], bool &comLineCur, + int &levelDeltaNext) { + levelDeltaNext = 0; + if (!comLineCur) { + return; + } + + if (!comLineF[0] || nComColF[0] != nComCur) { + unsigned int i=0; + for (; i= nLineTotal) { + return; + } + + for (int i=nComL-2; i>=0; i--) { + nComColB[i+1] = nComColB[i]; + comLineB[i+1] = comLineB[i]; + } + nComColB[0] = nComCur; + comLineB[0] = comLineCur; + nComCur = nComColF[0]; + comLineCur = comLineF[0]; + for (unsigned int i=0; i+1 0) { lineCurrent--; startPos = styler.LineStart(lineCurrent); - levelCurrent = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; isPrevLine = true; } else { - levelCurrent = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; isPrevLine = false; } char chNext = styler[startPos]; int styleNext = styler.StyleAt(startPos); int style = initStyle; int levelDeltaNext = 0; + + const unsigned int nComL = 3; // defines how many comment lines should be before they are folded + Sci_Position nComColB[nComL]; + Sci_Position nComColF[nComL] = {}; + Sci_Position nComCur; + bool comLineB[nComL]; + bool comLineF[nComL]; + bool comLineCur; + Sci_Position nLineTotal = styler.GetLine(styler.Length()-1) + 1; + if (foldComment) { + for (unsigned int i=0; i= nLineTotal) { + comLineF[i] = false; + break; + } + GetIfLineComment(styler, isFixFormat, chL, comLineF[i], nComColF[i]); + } + GetIfLineComment(styler, isFixFormat, lineCurrent, comLineCur, nComCur); + CheckBackComLines(styler, isFixFormat, lineCurrent, nComL, nComColB, nComColF, nComCur, + comLineB, comLineF, comLineCur); + } + int levelCurrent = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; + /***************************************/ Sci_Position lastStart = 0; char prevWord[32] = ""; @@ -467,6 +659,11 @@ static void FoldFortranDoc(Sci_PositionU startPos, Sci_Position length, int init } } if (atEOL) { + if (foldComment) { + int ldNext; + CheckLevelCommentLine(nComL, nComColB, nComColF, nComCur, comLineB, comLineF, comLineCur, ldNext); + levelDeltaNext += ldNext; + } int lev = levelCurrent; if (visibleChars == 0 && foldCompact) lev |= SC_FOLDLEVELWHITEFLAG; @@ -481,6 +678,11 @@ static void FoldFortranDoc(Sci_PositionU startPos, Sci_Position length, int init visibleChars = 0; strcpy(prevWord, ""); isPrevLine = false; + + if (foldComment) { + StepCommentLine(styler, isFixFormat, lineCurrent, nComL, nComColB, nComColF, nComCur, + comLineB, comLineF, comLineCur); + } } /***************************************/ if (!isspacechar(ch)) visibleChars++; -- cgit v1.2.3