diff options
author | nyamatongwe <devnull@localhost> | 2000-04-11 11:04:30 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2000-04-11 11:04:30 +0000 |
commit | b9acd7e4a1277833de0559cf92baad5957018b10 (patch) | |
tree | 8833b7f281cfc62deebc9599fd41f8a40cecaf0c /src/LexPython.cxx | |
parent | 0deaa9b95af06c01fa0e6714ad73b41ed22ae5c7 (diff) | |
download | scintilla-mirror-b9acd7e4a1277833de0559cf92baad5957018b10.tar.gz |
Fixed handling folding in of triple quoted strings.
Always lex the line before asked to ensure folding and tab timmy right.
Diffstat (limited to 'src/LexPython.cxx')
-rw-r--r-- | src/LexPython.cxx | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/LexPython.cxx b/src/LexPython.cxx index 1864412a6..9552c0da6 100644 --- a/src/LexPython.cxx +++ b/src/LexPython.cxx @@ -17,7 +17,7 @@ #include "Scintilla.h" #include "SciLexer.h" -static void classifyWordPy(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler, char *prevWord) { +static void ClassifyWordPy(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler, char *prevWord) { char s[100]; bool wordIsNumber = isdigit(styler[start]); for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) { @@ -44,31 +44,42 @@ static bool IsPyComment(Accessor &styler, int pos, int len) { static void ColourisePyDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor &styler) { + int endDoc = startPos + length; + + // Backtrack to previous line in case need to fix its fold status or tab whinging + int lineCurrent = styler.GetLine(startPos); + if (startPos > 0) { + if (lineCurrent > 0) { + lineCurrent--; + startPos = styler.LineStart(lineCurrent); + } + } + // Python uses a different mask because bad indentation is marked by oring with 32 styler.StartAt(startPos, 127); WordList &keywords = *keywordlists[0]; - //Platform::DebugPrintf("Python coloured\n"); bool fold = styler.GetPropSet().GetInt("fold"); int whingeLevel = styler.GetPropSet().GetInt("tab.timmy.whinge.level"); char prevWord[200]; prevWord[0] = '\0'; if (length == 0) return ; - int lineCurrent = styler.GetLine(startPos); int spaceFlags = 0; - // TODO: Need to check previous line for indentation for both folding and bad indentation - int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, IsPyComment); int state = initStyle & 31; + + int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, IsPyComment); + if ((state == SCE_P_TRIPLE) || (state == SCE_P_TRIPLEDOUBLE)) + indentCurrent |= SC_FOLDLEVELWHITEFLAG; + char chPrev = ' '; char chPrev2 = ' '; char chNext = styler[startPos]; styler.StartSegment(startPos); - int lengthDoc = startPos + length; bool atStartLine = true; - for (int i = startPos; i <= lengthDoc; i++) { + for (int i = startPos; i <= endDoc; i++) { if (atStartLine) { char chBad = static_cast<char>(64); @@ -91,7 +102,7 @@ static void ColourisePyDoc(unsigned int startPos, int length, int initStyle, chNext = styler.SafeGetCharAt(i + 1); char chNext2 = styler.SafeGetCharAt(i + 2); - if ((ch == '\r' && chNext != '\n') || (ch == '\n') || (i == lengthDoc)) { + if ((ch == '\r' && chNext != '\n') || (ch == '\n') || (i == endDoc)) { if ((state == SCE_P_DEFAULT) || (state == SCE_P_TRIPLE) || (state == SCE_P_TRIPLEDOUBLE)) { // Perform colourisation of white space and triple quoted strings at end of each line to allow // tab marking to work inside white space and triple quoted strings @@ -100,6 +111,8 @@ static void ColourisePyDoc(unsigned int startPos, int length, int initStyle, int lev = indentCurrent; int indentNext = styler.IndentAmount(lineCurrent + 1, &spaceFlags, IsPyComment); + if ((state == SCE_P_TRIPLE) || (state == SCE_P_TRIPLEDOUBLE)) + indentNext |= SC_FOLDLEVELWHITEFLAG; if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG)) { // Only non whitespace lines can be headers if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < (indentNext & SC_FOLDLEVELNUMBERMASK)) { @@ -170,7 +183,7 @@ static void ColourisePyDoc(unsigned int startPos, int length, int initStyle, } } else if (state == SCE_P_WORD) { if (!iswordchar(ch)) { - classifyWordPy(styler.GetStartSegment(), i - 1, keywords, styler, prevWord); + ClassifyWordPy(styler.GetStartSegment(), i - 1, keywords, styler, prevWord); state = SCE_P_DEFAULT; if (ch == '#') { state = chNext == '#' ? SCE_P_COMMENTBLOCK : SCE_P_COMMENTLINE; @@ -248,9 +261,9 @@ static void ColourisePyDoc(unsigned int startPos, int length, int initStyle, chPrev = ch; } if (state == SCE_P_WORD) { - classifyWordPy(styler.GetStartSegment(), lengthDoc, keywords, styler, prevWord); + ClassifyWordPy(styler.GetStartSegment(), endDoc, keywords, styler, prevWord); } else { - styler.ColourTo(lengthDoc, state); + styler.ColourTo(endDoc, state); } } |