Perl folding fails on comment with right curley brace "#}"
-
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 -
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; seeing0x3FF
in the margin is a red flag; the minimum sane value is0x400
:The editor shown above is SciTE, a Scintilla container like Notepad++; the hexadecimal margin numbers are explained in this topic.
-
@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. -
@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.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 of402 401
which means it is closing a fold. The next frame with that same line shows fold flags as402 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.