Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Python Multiline Comment/String Folding

    General Discussion
    2
    7
    3603
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Jimmy Devine
      Jimmy Devine last edited by

      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.

      Claudia Frank 1 Reply Last reply Reply Quote 0
      • Claudia Frank
        Claudia Frank @Jimmy Devine last edited by

        @Jimmy-Devine

        python lexer is based on indentation, so yes you have to add spaces in front to make it work correctly.

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • Jimmy Devine
          Jimmy Devine last edited by

          Well this isn’t a very good solution because it affects the contents of the multiline string

          Claudia Frank 1 Reply Last reply Reply Quote 0
          • Claudia Frank
            Claudia Frank @Jimmy Devine last edited by

            @Jimmy-Devine

            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

            1 Reply Last reply Reply Quote 0
            • Jimmy Devine
              Jimmy Devine last edited by

              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"));
              };
              
              Claudia Frank 1 Reply Last reply Reply Quote 1
              • Claudia Frank
                Claudia Frank @Jimmy Devine last edited by

                @Jimmy-Devine

                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 call

                editor.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

                1 Reply Last reply Reply Quote 0
                • Jimmy Devine
                  Jimmy Devine last edited by

                  Good deal, thanks Claudia

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors