MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / FoldPyDoc

Function FoldPyDoc

scintilla/lexers/LexPython.cxx:428–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426
427
428static void FoldPyDoc(unsigned int startPos, int length, int /*initStyle - unused*/,
429 WordList *[], Accessor &styler) {
430 const int maxPos = startPos + length;
431 const int maxLines = (maxPos == styler.Length()) ? styler.GetLine(maxPos) : styler.GetLine(maxPos - 1); // Requested last line
432 const int docLines = styler.GetLine(styler.Length()); // Available last line
433
434 // property fold.quotes.python
435 // This option enables folding multi-line quoted strings when using the Python lexer.
436 const bool foldQuotes = styler.GetPropertyInt("fold.quotes.python") != 0;
437
438 const bool foldCompact = styler.GetPropertyInt("fold.compact") != 0;
439
440 // Backtrack to previous non-blank line so we can determine indent level
441 // for any white space lines (needed esp. within triple quoted strings)
442 // and so we can fix any preceding fold level (which is why we go back
443 // at least one line in all cases)
444 int spaceFlags = 0;
445 int lineCurrent = styler.GetLine(startPos);
446 int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, NULL);
447 while (lineCurrent > 0) {
448 lineCurrent--;
449 indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, NULL);
450 if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG) &&
451 (!IsCommentLine(lineCurrent, styler)) &&
452 (!IsQuoteLine(lineCurrent, styler)))
453 break;
454 }
455 int indentCurrentLevel = indentCurrent & SC_FOLDLEVELNUMBERMASK;
456
457 // Set up initial loop state
458 startPos = styler.LineStart(lineCurrent);
459 int prev_state = SCE_P_DEFAULT & 31;
460 if (lineCurrent >= 1)
461 prev_state = styler.StyleAt(startPos - 1) & 31;
462 int prevQuote = foldQuotes && ((prev_state == SCE_P_TRIPLE) || (prev_state == SCE_P_TRIPLEDOUBLE));
463
464 // Process all characters to end of requested range or end of any triple quote
465 //that hangs over the end of the range. Cap processing in all cases
466 // to end of document (in case of unclosed quote at end).
467 while ((lineCurrent <= docLines) && ((lineCurrent <= maxLines) || prevQuote)) {
468
469 // Gather info
470 int lev = indentCurrent;
471 int lineNext = lineCurrent + 1;
472 int indentNext = indentCurrent;
473 int quote = false;
474 if (lineNext <= docLines) {
475 // Information about next line is only available if not at end of document
476 indentNext = styler.IndentAmount(lineNext, &spaceFlags, NULL);
477 int lookAtPos = (styler.LineStart(lineNext) == styler.Length()) ? styler.Length() - 1 : styler.LineStart(lineNext);
478 int style = styler.StyleAt(lookAtPos) & 31;
479 quote = foldQuotes && ((style == SCE_P_TRIPLE) || (style == SCE_P_TRIPLEDOUBLE));
480 }
481 const int quote_start = (quote && !prevQuote);
482 const int quote_continue = (quote && prevQuote);
483 if (!quote || !prevQuote)
484 indentCurrentLevel = indentCurrent & SC_FOLDLEVELNUMBERMASK;
485 if (quote)

Callers

nothing calls this directly

Calls 10

MaximumFunction · 0.85
GetLineMethod · 0.80
GetPropertyIntMethod · 0.80
IndentAmountMethod · 0.80
IsCommentLineFunction · 0.70
IsQuoteLineFunction · 0.70
LengthMethod · 0.45
LineStartMethod · 0.45
StyleAtMethod · 0.45
SetLevelMethod · 0.45

Tested by

no test coverage detected