diff -r bfd53a376839 lexers/LexPython.cxx --- a/lexers/LexPython.cxx Thu Mar 09 12:13:16 2017 -0500 +++ b/lexers/LexPython.cxx Thu Apr 20 13:32:58 2017 -0400 @@ -897,18 +897,24 @@ // Skip past any blank lines for next indent level info; we skip also // comments (all comments, not just those starting in column 0) // which effectively folds them into surrounding code rather - // than screwing up folding. + // than screwing up folding. If comments end file, use the min + // comment indent as the level after + int minCommentLevel = indentCurrentLevel; while (!quote && (lineNext < docLines) && ((indentNext & SC_FOLDLEVELWHITEFLAG) || (lineNext <= docLines && IsCommentLine(lineNext, styler)))) { + + if (IsCommentLine(lineNext, styler) && indentNext < minCommentLevel) { + minCommentLevel = indentNext; + } lineNext++; indentNext = styler.IndentAmount(lineNext, &spaceFlags, NULL); } - const int levelAfterComments = indentNext & SC_FOLDLEVELNUMBERMASK; + const int levelAfterComments = ((lineNext < docLines) ? indentNext & SC_FOLDLEVELNUMBERMASK : minCommentLevel); const int levelBeforeComments = Maximum(indentCurrentLevel,levelAfterComments); // Now set all the indent levels on the lines we skipped