From a6effa34b2f95b0e296f19b155ba2e9749ce7948 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 8 Apr 2021 15:44:33 -0700 Subject: [PATCH] Improve treatment of -vmll with -wn --- lib/Perl/Tidy/Formatter.pm | 49 ++++++++++++++++++++------------------ local-docs/BugLog.pod | 15 +++++++++--- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 2eeeb4ef..5134f053 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7224,33 +7224,36 @@ EOM my $level = $rLL->[$Kref]->[_LEVEL_]; my $ci_level = $rLL->[$Kref]->[_CI_LEVEL_]; - if ( !$rOpts_variable_maximum_line_length ) { + $starting_indent = $rOpts_indent_columns * $level + + $ci_level * $rOpts_continuation_indentation; - $starting_indent = $rOpts_indent_columns * $level + - $ci_level * $rOpts_continuation_indentation; - - # Switch to using the outer opening token as the reference - # point if a line break before it would make a longer line. - # Fixes case b1055 and is also an alternate fix for b1065. - my $level_oo = $rLL->[$Kouter_opening]->[_LEVEL_]; - if ( $Kref < $Kouter_opening ) { - my $ci_level_oo = $rLL->[$Kouter_opening]->[_CI_LEVEL_]; - my $lentot_oo = - $rLL->[ $Kouter_opening - 1 ]->[_CUMULATIVE_LENGTH_]; - my $starting_indent_oo = $rOpts_indent_columns * $level_oo + - $ci_level_oo * $rOpts_continuation_indentation; - if ( $lentot_oo - $starting_lentot < - $starting_indent_oo - $starting_indent ) - { - $Kref = $Kouter_opening; - $level = $level_oo; - $ci_level = $ci_level_oo; - $starting_lentot = $lentot_oo; - $starting_indent = $starting_indent_oo; - } + # Switch to using the outer opening token as the reference + # point if a line break before it would make a longer line. + # Fixes case b1055 and is also an alternate fix for b1065. + my $level_oo = $rLL->[$Kouter_opening]->[_LEVEL_]; + if ( $Kref < $Kouter_opening ) { + my $ci_level_oo = $rLL->[$Kouter_opening]->[_CI_LEVEL_]; + my $lentot_oo = + $rLL->[ $Kouter_opening - 1 ]->[_CUMULATIVE_LENGTH_]; + my $starting_indent_oo = $rOpts_indent_columns * $level_oo + + $ci_level_oo * $rOpts_continuation_indentation; + if ( $lentot_oo - $starting_lentot < + $starting_indent_oo - $starting_indent ) + { + $Kref = $Kouter_opening; + $level = $level_oo; + $ci_level = $ci_level_oo; + $starting_lentot = $lentot_oo; + $starting_indent = $starting_indent_oo; } } + # Revised -vmll treatment to fix cases b866 b1074 b1075 b1084 b1086 + # b1087 b1088 + if ($rOpts_variable_maximum_line_length) { + $starting_indent -= $level * $rOpts_indent_columns; + } + # Avoid problem areas with the -wn -lp combination. # The combination -wn -lp -dws -naws does not work well and can # cause blinkers. See case b1020. It will probably only occur diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 8afb381c..5911c94d 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -3,6 +3,15 @@ =over 4 +=item B + +Random testing showed a weakness in the treatment of the -vmll flag +in combination with the -wn flag. This has been fixed. + +This fixes cases b866 b1074 b1075 b1084 b1086 b1087 b1088 + +8 Apr 2021. + =item B One of the welding rules, RULE 6, has been merged into RULE 3 for @@ -11,7 +20,7 @@ followed by a bare word, which can cause instability in some cases. The updated code is less restrictive and fixes some cases recently found with random testing, b1078 b1091. -8 Apr 2021. +8 Apr 2021, f28ab55. =item B @@ -19,7 +28,7 @@ The previous update regarding blank line generation was not sufficiently general to handle all possible parameter combinations. The problem was solved and simplified by moving the logic to a lower level, in the FileWriter module. -6 Apr 2021. +6 Apr 2021, 756e930. =item B @@ -41,7 +50,7 @@ and the following parameters When run, blank lines keep getting generated until the maximum is reached. This has been fixed. -6 Apr 2021. +6 Apr 2021, 9216298. =item B -- 2.39.5