]> git.donarmstrong.com Git - perltidy.git/commitdiff
Modify line length test for the -vtc=2 option
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 15 Feb 2021 04:59:43 +0000 (20:59 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 15 Feb 2021 04:59:43 +0000 (20:59 -0800)
lib/Perl/Tidy/VerticalAligner.pm
lib/Perl/Tidy/VerticalAligner/Line.pm
local-docs/BugLog.pod

index 47268f42f73fbd91ecf4513ab4157ef6df6dd0dc..8308264332b3de15423ed25dc360ba00178b4c12 100644 (file)
@@ -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);
 
index 9aa4b007c11c6182c0c27c9085a0a5bdebfc6e41..4edb41542d203ad8e5c3ad03a13ff9b88c9286a3 100644 (file)
@@ -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_] }
index 4fc0f827d0a4e9f443da93a8b2fd3e541bfbdd58..486e7191f327ae400a24eb8de42e5cd51863086d 100644 (file)
@@ -2,6 +2,16 @@
 
 =over 4
 
+=item B<Modify line length test for the -vtc=2 option>
+
+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<Use increased line length tolerance if ci exceeds i>
 
 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<Keep space between binary plus or minus and a bareword>