• Login
Community
  • Login

Python Multiline Comment/String Folding

Scheduled Pinned Locked Moved General Discussion
7 Posts 2 Posters 5.2k Views
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.
  • J
    Jimmy Devine
    last edited by Feb 16, 2017, 6:43 PM

    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.

    C 1 Reply Last reply Feb 17, 2017, 2:12 PM Reply Quote 0
    • C
      Claudia Frank @Jimmy Devine
      last edited by Feb 17, 2017, 2:12 PM

      @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
      • J
        Jimmy Devine
        last edited by Feb 17, 2017, 2:42 PM

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

        C 1 Reply Last reply Feb 17, 2017, 2:51 PM Reply Quote 0
        • C
          Claudia Frank @Jimmy Devine
          last edited by Feb 17, 2017, 2:51 PM

          @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
          • J
            Jimmy Devine
            last edited by Feb 21, 2017, 12:46 AM

            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"));
            };
            
            C 1 Reply Last reply Feb 21, 2017, 3:56 PM Reply Quote 1
            • C
              Claudia Frank @Jimmy Devine
              last edited by Feb 21, 2017, 3:56 PM

              @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
              • J
                Jimmy Devine
                last edited by Feb 22, 2017, 12:23 AM

                Good deal, thanks Claudia

                1 Reply Last reply Reply Quote 0
                5 out of 7
                • First post
                  5/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors