From 0fa7dd5c71638eb5329c6b2aabeffd2a2857f909 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 14 Nov 2021 17:10:27 -0800 Subject: [PATCH] fix b1255 - improved cutoff limit for -lp formatting --- lib/Perl/Tidy/Formatter.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 7eff258b..953092cd 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -19532,6 +19532,7 @@ sub get_available_spaces_to_go { my @gnu_item_list; my @gnu_stack; my $rGS; + my $lp_cutoff_level; BEGIN { @@ -19575,6 +19576,22 @@ sub get_available_spaces_to_go { $rGS->[$max_gnu_stack_index]->[_gs_space_count_] = 0; @gnu_item_list = (); + + $lp_cutoff_level = $stress_level + 2; + + # use an alternative criterion if more restrictive (case b1255) + # This allows the cutoff level to go down to 0 in extreme cases. + foreach my $level_test ( 0 .. $lp_cutoff_level ) { + my $max_len = $maximum_text_length_at_level[ $level_test + 1 ]; + my $excess_inside_space = + $max_len - + $rOpts_continuation_indentation - + $rOpts_indent_columns - 8; + if ( $excess_inside_space <= 0 ) { + $lp_cutoff_level = $level_test; + last; + } + } return; } @@ -20002,7 +20019,7 @@ EOM } # do not start -lp under stress .. fixes b1244 - elsif ( !$in_lp_mode && $level > $stress_level + 1 ) { + elsif ( !$in_lp_mode && $level >= $lp_cutoff_level ) { $space_count += $standard_increment; } -- 2.39.5