Python Multiline Comment/String Folding
-
I seem to be having a problem with the python language and folding when there are multiline comments or strings present. For instance:
def func(): str = ''' '''
Folding this method will fold up the line defining str = ’ ’ ', but the two lines below it are left unfolded. If I put something other than spaces on the second line, it will fold the first two lines (assuming the second line doesn’t start with a space). If I put a space before the trailing ’ ’ ’ it will fold all lines.
-
python lexer is based on indentation, so yes you have to add spaces in front to make it work correctly.
Cheers
Claudia -
Well this isn’t a very good solution because it affects the contents of the multiline string
-
As the python lexer is part of the scintilla component you might think opening
a feature request at https://sourceforge.net/p/scintilla/feature-requests/ .
Maybe search first if not already addressed.Cheers
Claudia -
So messing with the notepad++ code it looks like the scintilla source already present does this, it just isn’t being used, adding this execute line to ScintillaEditView::setPythonLexer adds is
void setPythonLexer() { setLexer(SCLEX_PYTHON, L_PYTHON, LIST_0 | LIST_1); execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.quotes.python"), reinterpret_cast<LPARAM>("1")); };
-
nice finding - thx for sharing this info.
For all who don’t want or can’t recompile npp, the same can be achieved when using
python script plugin and the following calleditor.setProperty("fold.quotes.python", 1)
But this needs to be called for every python document once so it makes sense
to call it from within the notepad bufferactivated callback.I have opened a feature request at github to ask for implementing this.
Cheers
Claudia -
Good deal, thanks Claudia