Community
    • Login

    Python Multiline Comment/String Folding

    Scheduled Pinned Locked Moved General Discussion
    7 Posts 2 Posters 5.9k Views 2 Watching
    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 DevineJ Offline
      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 FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC Offline
        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 DevineJ Offline
          Jimmy Devine
          last edited by

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

          Claudia FrankC 1 Reply Last reply Reply Quote 0
          • Claudia FrankC Offline
            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 DevineJ Offline
              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 FrankC 1 Reply Last reply Reply Quote 1
              • Claudia FrankC Offline
                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 DevineJ Offline
                  Jimmy Devine
                  last edited by

                  Good deal, thanks Claudia

                  1 Reply Last reply Reply Quote 0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors