• Login
Community
  • Login

Perl folding fails on comment with right curley brace "#}"

Scheduled Pinned Locked Moved General Discussion
4 Posts 3 Posters 500 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.
  • C
    CodeBiene
    last edited by Feb 18, 2024, 7:37 AM

    Hi,
    Folding works quite fine unless there’s a line of Perl code commented including the right curly braces “#}” just after the hash character.
    Below some lines of sample Perl code.
    Folding for “sub b” works if line 10 (including the elsif condition) is uncommented and fails if that line is commented.
    Folding also works when removing the right curley brace “}” like “# elsif …” or there’s a space before that right curley brace “# } elsif …”.
    I guess this is a bug.

    #!/usr/bin/perl
    
    	my sub a {
    		# my code
    	}
    
    	my sub b {
    		if ( $x eq '' ) {
    			# do something
    		#} elsif ( $x eq ',' ) {   # line 10
    			# do something
    		} else {
    			# do something
    		}
    		# do something
    	}
    
    	my sub c {
    		# my code
    	}
    
    	exit 1;
    
    

    Best regards,
    Willy

    R 1 Reply Last reply Feb 18, 2024, 11:28 AM Reply Quote 0
    • R
      rdipardo @CodeBiene
      last edited by Feb 18, 2024, 11:28 AM

      TL;DR Known issue, or at least another example of a common issue that Lexilla’s Bash script lexer also has (or had); see the bug report and the eventual patch .


      The Perl lexer folds consecutive line comments, e.g.,

      + # comment starts
      | # comment continues
      | # . . .
      

      When you comment-out the elsif line, you create a folded group of 3 comments; when this group ends, it restores the fold level to where it was before the opening brace of the containing block, which is wrong. The fold level is decreased below the reasonable range; seeing 0x3FF in the margin is a red flag; the minimum sane value is 0x400:

      perl-nested-line-comment.png

      The editor shown above is SciTE , a Scintilla container like Notepad++; the hexadecimal margin numbers are explained in this topic.

      C 1 Reply Last reply Feb 18, 2024, 12:19 PM Reply Quote 0
      • C
        CodeBiene @rdipardo
        last edited by Feb 18, 2024, 12:19 PM

        @rdipardo
        Thanks for your reply.
        In my example code I replaced all comments “# do something” by “print $x;”.
        The folding still fails.
        So it has nothing to do with the fact that there are several consecutive comment lines.

        M 1 Reply Last reply Feb 19, 2024, 2:22 AM Reply Quote 0
        • M
          mpheath @CodeBiene
          last edited by Feb 19, 2024, 2:22 AM

          @CodeBiene said in Perl folding fails on comment with right curley brace "#}":

          So it has nothing to do with the fact that there are several consecutive comment lines.

          I agree that It is something that has not been mentioned yet.

          The hexadecimal 3FF displayed in the margin is negative folding caused by unbalanced braces.

          perl_fold4.gif

          2 frames alternate every 4 seconds displaying the default lexer property value of

          fold.perl.comment.explicit=1
          

          and the changed value of

          fold.perl.comment.explicit=0
          

          Comment explicit enabled for the lexer is usually the leading comment character(s) followed with a brace. Perl comment explicit is #{ as a open fold and #} as a close fold.

          Notice the line with #} { shows fold flags of 402 401 which means it is closing a fold. The next frame with that same line shows fold flags as 402 402 which means that there is no change in the folding state.

          The Ctrl+Q key sequence changes } { to # } { which is not recognized as a fold by comment explicit as to the space after the # symbol.

          PythonScript can be used to disable the comment explicit option which is enabled with the value of 1 by default:

          editor.setProperty('fold.perl.comment.explicit', 0)
          

          This setting will not survive changing buffers so may need a callback to be setup.

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