]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix rare problem with combination -lp -wn -naws
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 19 Mar 2021 00:59:14 +0000 (17:59 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 19 Mar 2021 00:59:14 +0000 (17:59 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 021b6f4e2b858890f64d9bb02ea8ba7cff91d6b1..d1cda18515c018b97ab7fce4a8d6d0795ee7dec8 100644 (file)
@@ -7026,17 +7026,28 @@ EOM
             # The combination -wn -lp -dws -naws does not work well and can
             # cause blinkers. See case b1020. It will probably only occur
             # in stress testing.  For this situation we will only weld if we
-            # start at a 'good' location.
+            # start at a 'good' location.  Added 'if' to fix case b1032.
             if (   $ci_level
                 && $rOpts_line_up_parentheses
                 && $rOpts_delete_old_whitespace
                 && !$rOpts_add_whitespace )
             {
-                my $type_first = $rLL->[$Kfirst]->[_TYPE_];
-                my $type_prev  = $rLL->[$Kprev]->[_TYPE_];
-                unless ( $type_prev =~ /^[=\,\.\{\[\(\L]/
-                    || $type_first =~ /^[=\,\.\{\[\(\L]/ )
+                my $type_first  = $rLL->[$Kfirst]->[_TYPE_];
+                my $type_prev   = $rLL->[$Kprev]->[_TYPE_];
+                my $token_first = $rLL->[$Kfirst]->[_TOKEN_];
+                unless (
+                       $type_prev  =~ /^[=\,\.\{\[\(\L]/
+                    || $type_first =~ /^[=\,\.\{\[\(\L]/
+                    || $type_first eq '||'
+                    || (   $type_first eq 'k' && $token_first eq 'if'
+                        || $token_first eq 'or' )
+                  )
                 {
+                    if (DEBUG_WELD) {
+                        $Msg .=
+"Skipping weld: poor break with -lp and ci at type_first='$type_first' type_prev='$type_prev'\n";
+                        print $Msg;
+                    }
                     next;
                 }
             }
@@ -8215,6 +8226,7 @@ sub extended_ci {
     my $rLL = $self->[_rLL_];
     return unless ( defined($rLL) && @{$rLL} );
 
+    my $ris_list_by_seqno        = $self->[_ris_list_by_seqno_];
     my $ris_seqno_controlling_ci = $self->[_ris_seqno_controlling_ci_];
     my $rseqno_controlling_my_ci = $self->[_rseqno_controlling_my_ci_];
     my $rlines                   = $self->[_rlines_];
@@ -8244,18 +8256,21 @@ sub extended_ci {
         # Fix all tokens up to the next sequence item if we are changing CI
         if ($seqno_top) {
 
-            my $space  = $available_space{$seqno_top};
-            my $length = $rLL->[$KLAST]->[_CUMULATIVE_LENGTH_];
-            my $count  = 0;
+            my $is_list = $ris_list_by_seqno->{$seqno_top};
+            my $space   = $available_space{$seqno_top};
+            my $length  = $rLL->[$KLAST]->[_CUMULATIVE_LENGTH_];
+            my $count   = 0;
             for ( my $Kt = $KLAST + 1 ; $Kt < $KNEXT ; $Kt++ ) {
 
-                # but do not include tokens which might exceed the line length
+                # But do not include tokens which might exceed the line length
+                # and are not in a list.
                 # ... This fixes case b1031
                 my $length_before = $length;
                 $length = $rLL->[$Kt]->[_CUMULATIVE_LENGTH_];
                 if (
                     !$rLL->[$Kt]->[_CI_LEVEL_]
-                    && (   $length - $length_before < $space
+                    && (   $is_list
+                        || $length - $length_before < $space
                         || $rLL->[$Kt]->[_TYPE_] eq '#' )
                   )
                 {
index 4720c406b2fdaf6992a5de92ca373926fcf1944b..dc134cf14a4865bf6e4d275b14210388e523e5c2 100644 (file)
@@ -2,6 +2,18 @@
 
 =over 4
 
+=item B<Fix rare problem with combination -lp -wn -naws>
+
+This update fixes case b1032 by includeing lines starting with 'if', 'or', and
+|| among the stable breakpoints for welding when -lp -naws flags are also
+set.
+
+This update also modifies update 7a6be43 of 16 Mar 2021 to exclude list items
+when checking token lengths.  This reduces changes to existing formatting
+while still fixing the problem in case b1031. 
+
+18 Mar 2021.
+
 =item B<Fix definition of list within list for -bbx flags>
 
 Testing produced a blinking state involving a -bbx=2 flag with an unusual
@@ -9,7 +21,7 @@ combination of other parameters.  The problem was traced to the definition of a
 list containg another list being too restrictive.  This update fixes case
 1024.
 
-17 Mar 2021.
+17 Mar 2021, 7f5da0a.
 
 =item B<Fix problem with -xci and long tokens>