From 4673fdd4c4f4eddc08177544c308431c36b1c8d9 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 14 Feb 2021 20:59:43 -0800 Subject: [PATCH] Modify line length test for the -vtc=2 option --- lib/Perl/Tidy/VerticalAligner.pm | 40 ++++++++++++++++----------- lib/Perl/Tidy/VerticalAligner/Line.pm | 6 ++++ local-docs/BugLog.pod | 12 +++++++- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index 47268f42..83082643 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -641,6 +641,7 @@ sub valign_input { outdent_long_lines => $outdent_long_lines, rvertical_tightness_flags => $rvertical_tightness_flags, level => $level, + level_end => $level_end, Kend => $Kend, } ); @@ -703,6 +704,8 @@ EOM end_group => $break_alignment_after, Kend => $Kend, ci_level => $ci_level, + level => $level, + level_end => $level_end, imax_pair => -1, } ); @@ -1365,16 +1368,17 @@ sub _flush_comment_lines { my $outdent_long_lines = 0; foreach my $item ( @{$rgroup_lines} ) { - my ( $line, $line_len, $Kend ) = @{$item}; + my ( $str, $str_len, $Kend ) = @{$item}; $self->valign_output_step_B( { leading_space_count => $leading_space_count, - line => $line, - line_length => $line_len, + line => $str, + line_length => $str_len, side_comment_length => 0, outdent_long_lines => $outdent_long_lines, rvertical_tightness_flags => "", level => $group_level, + level_end => $group_level, Kend => $Kend, } ); @@ -4538,6 +4542,7 @@ sub valign_output_step_A { my $maximum_field_index = $line->get_jmax(); my $rvertical_tightness_flags = $line->get_rvertical_tightness_flags(); my $Kend = $line->get_Kend(); + my $level_end = $line->get_level_end(); # add any extra spaces if ( $leading_space_count > $group_leader_length ) { @@ -4610,6 +4615,7 @@ sub valign_output_step_A { outdent_long_lines => $outdent_long_lines, rvertical_tightness_flags => $rvertical_tightness_flags, level => $level, + level_end => $level_end, Kend => $Kend, } ); @@ -4772,6 +4778,7 @@ sub get_output_line_number { my $outdent_long_lines = $rinput->{outdent_long_lines}; my $rvertical_tightness_flags = $rinput->{rvertical_tightness_flags}; my $level = $rinput->{level}; + my $level_end = $rinput->{level_end}; my $Kend = $rinput->{Kend}; my $last_level_written = $self->[_last_level_written_]; @@ -4831,12 +4838,12 @@ sub get_output_line_number { $seqno_string = $seqno_end; - # handle any cached line .. - # either append this line to it or write it out - # Note: the function length() is used in this next test out of caution. - # All testing has shown that the variable $cached_line_text_length is - # correct, but its calculation is complex and a loss of cached text would - # be a disaster. + # handle any cached line .. + # either append this line to it or write it out + # Note: the function length() is used in this next test out of caution. + # All testing has shown that the variable $cached_line_text_length is + # correct, but its calculation is complex and a loss of cached text + # would be a disaster. if ( length($cached_line_text) ) { # Dump an invalid cached line @@ -4859,14 +4866,15 @@ sub get_output_line_number { } } - # Do not join the lines if this produces a line too long. - # This prevents blinking caused by the combination -xci -pvt=2 - # in which a one-line block alternately forms and breaks, - # causing -xci to alternately turn on and off (case b765). - # This does not normally happen but can during stress testing. - if ( $gap > 0 ) { + # Do not join the lines if this might produce a one-line + # container which exceeds the maximum line length. This is + # necessary prevent blinking, particularly with the combination + # -xci -pvt=2. In that case a one-line block alternately forms + # and breaks, causing -xci to alternately turn on and off (case + # b765). + if ( $gap >= 0 && defined($level_end) && $level > $level_end ) { my $test_line_length = - $cached_line_text_length + $gap + $str_length; + $cached_line_text_length + $gap + $str_length; my $maximum_line_length = $self->maximum_line_length_for_level($last_level_written); diff --git a/lib/Perl/Tidy/VerticalAligner/Line.pm b/lib/Perl/Tidy/VerticalAligner/Line.pm index 9aa4b007..4edb4154 100644 --- a/lib/Perl/Tidy/VerticalAligner/Line.pm +++ b/lib/Perl/Tidy/VerticalAligner/Line.pm @@ -32,6 +32,8 @@ BEGIN { _end_group_ => $i++, _Kend_ => $i++, _ci_level_ => $i++, + _level_ => $i++, + _level_end_ => $i++, _imax_pair_ => $i++, }; } @@ -84,6 +86,8 @@ EOM $self->[_end_group_] = $ri->{end_group}; $self->[_Kend_] = $ri->{Kend}; $self->[_ci_level_] = $ri->{ci_level}; + $self->[_level_] = $ri->{level}; + $self->[_level_end_] = $ri->{level_end}; $self->[_imax_pair_] = $ri->{imax_pair}; $self->[_ralignments_] = []; @@ -100,6 +104,8 @@ EOM sub get_indentation { return $_[0]->[_indentation_] } sub get_Kend { return $_[0]->[_Kend_] } sub get_ci_level { return $_[0]->[_ci_level_] } + sub get_level { return $_[0]->[_level_] } + sub get_level_end { return $_[0]->[_level_end_] } sub get_list_seqno { return $_[0]->[_list_seqno_] } sub get_imax_pair { return $_[0]->[_imax_pair_] } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 4fc0f827..486e7191 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,16 @@ =over 4 +=item B + +The line length test which was added Feb 13 2021 turns out to be more restrictive +than necessary. A modification was made to only apply it if a new one-line block +would be formed. This prevents it from needlessly changing existing formatting. + +The following cases were re-activated after this update: b654 b655 b656 b862 + +15 Feb 2021. + =item B In testing perltidy with random input parameters, some blinking states occurred @@ -12,7 +22,7 @@ following cases b775 b776 b826 b908 b910 b911 b923 b925 b926 b927 -14 Feb 2021. +14 Feb 2021, 8451f2f. =item B -- 2.39.5