From: Steve Hancock Date: Sat, 26 Nov 2022 23:34:05 +0000 (-0800) Subject: fix b1432 X-Git-Tag: 20221112.01~10 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=8580790821e26b9cb80bd6ab38a64598a5cd405c;p=perltidy.git fix b1432 --- diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 1ec73c9b..05994e4d 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -11055,6 +11055,28 @@ my$sem=sub --maximum-line-length=42 --variable-maximum-line-length +==> b1432.in <== +$last = after ( 7, + sub { print "not ok 3\n"; }, ); + +$last = after ( + 7, + sub { print "not ok 3\n"; }, +); + + +==> b1432.par <== +--add-trailing-commas +--continuation-indentation=8 +--delete-trailing-commas +--extended-continuation-indentation +--ignore-old-breakpoints +--indent-columns=8 +--line-up-parentheses +--maximum-line-length=45 +--space-function-paren +--want-trailing-commas='b' + ==> b146.in <== # State 1 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 55e4a9a7..84344bd5 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -23720,12 +23720,26 @@ EOM # nothing can be done if no stack items defined for this line return if ( $max_lp_object_list < 0 ); - # see if we have exceeded the maximum desired line length + # See if we have exceeded the maximum desired line length .. # keep 2 extra free because they are needed in some cases # (result of trial-and-error testing) + my $tol = 2; + + # But reduce tol to 0 at a terminal comma; fixes b1432 + if ( $tokens_to_go[$mx_index_to_go] eq ',' + && $mx_index_to_go < $max_index_to_go ) + { + my $in = $mx_index_to_go + 1; + if ( $types_to_go[$in] eq 'b' && $in < $max_index_to_go ) { $in++ } + if ( $is_closing_token{ $tokens_to_go[$in] } ) { + $tol = 0; + } + } + my $spaces_needed = $lp_position_predictor - - $maximum_line_length_at_level[ $levels_to_go[$mx_index_to_go] ] + 2; + $maximum_line_length_at_level[ $levels_to_go[$mx_index_to_go] ] + + $tol; return if ( $spaces_needed <= 0 );