]> git.donarmstrong.com Git - perltidy.git/commitdiff
Improve previous patch of -wn tolerance
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 5 Apr 2021 14:36:52 +0000 (07:36 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 5 Apr 2021 14:36:52 +0000 (07:36 -0700)
bin/perltidy
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod
t/snippets/expect/wn6.wn
t/snippets12.t

index 990f46d85ce8833f60f764810d7a4004f3cf5523..ffa7c52791353a9cbcdd3c39470b8be954a0c122 100755 (executable)
@@ -2654,10 +2654,12 @@ Here are some additional example strings and their meanings:
 
     '^('   - the weld must not start with a paren
     '.('   - the second and later tokens may not be parens
+    '.w('  - the second and later tokens may not keyword or function call parens
     '('    - no parens in a weld
     '^K('  - exclude a leading paren preceded by a non-keyword
     '.k('  - exclude a secondary paren preceded by a keyword
     '[ {'  - exclude all brackets and braces
+    '[ ( ^K{' - exclude everthing except nested structures like do {{  ... }}
 
 =item B<Vertical tightness> of non-block curly braces, parentheses, and square brackets.
 
index 1f09c210f791c9f94bafceb0d6d88d0efb2100ba..905f0b968472bbdacb3113bc8740afa54aac9a86 100644 (file)
@@ -7035,7 +7035,6 @@ sub weld_nested_containers {
     # Variables needed for estimating line lengths
     my $starting_indent;
     my $starting_lentot;
-    my $starting_level;
     my $iline_outer_opening   = -1;
     my $weld_count_this_start = 0;
 
@@ -7051,17 +7050,7 @@ sub weld_nested_containers {
 
         # Add a tolerance for welds over multiple lines to avoid blinkers
         my $iline_K = $rLL->[$K]->[_LINE_INDEX_];
-        my $level_K = $rLL->[$K]->[_LEVEL_];
-        my $tol     = 0;
-        if (
-            $iline_K > $iline_outer_opening
-
-            # fix for cases b1041 b1055:
-            || $level_K > $starting_level
-          )
-        {
-            $tol = $multiline_tol;
-        }
+        my $tol     = ( $iline_K > $iline_outer_opening ) ? $multiline_tol : 0;
 
         my $excess_length =
           $starting_indent + $length + $tol - $rOpts_maximum_line_length;
@@ -7218,12 +7207,34 @@ EOM
               $Kref <= 0 ? 0 : $rLL->[ $Kref - 1 ]->[_CUMULATIVE_LENGTH_];
 
             $starting_indent = 0;
-            $starting_level  = $rLL->[$Kref]->[_LEVEL_];
+            my $level    = $rLL->[$Kref]->[_LEVEL_];
             my $ci_level = $rLL->[$Kref]->[_CI_LEVEL_];
+
             if ( !$rOpts_variable_maximum_line_length ) {
 
-                $starting_indent = $rOpts_indent_columns * $starting_level +
+                $starting_indent = $rOpts_indent_columns * $level +
                   $ci_level * $rOpts_continuation_indentation;
+
+                # Switch to using the outer opening token as the reference
+                # point if a line break before it would make a longer line.
+                # Fixes case b1055 and is also an alternate fix for b1065.
+                my $level_oo = $rLL->[$Kouter_opening]->[_LEVEL_];
+                if ( $Kref < $Kouter_opening ) {
+                    my $ci_level_oo = $rLL->[$Kouter_opening]->[_CI_LEVEL_];
+                    my $lentot_oo =
+                      $rLL->[ $Kouter_opening - 1 ]->[_CUMULATIVE_LENGTH_];
+                    my $starting_indent_oo = $rOpts_indent_columns * $level_oo +
+                      $ci_level_oo * $rOpts_continuation_indentation;
+                    if ( $lentot_oo - $starting_lentot <
+                        $starting_indent_oo - $starting_indent )
+                    {
+                        $Kref            = $Kouter_opening;
+                        $level           = $level_oo;
+                        $ci_level        = $ci_level_oo;
+                        $starting_lentot = $lentot_oo;
+                        $starting_indent = $starting_indent_oo;
+                    }
+                }
             }
 
             # Avoid problem areas with the -wn -lp combination.
@@ -7454,9 +7465,9 @@ EOM
             $starting_lentot =
               $self->cumulative_length_before_K($Kinner_opening);
             $starting_indent = 0;
-            $starting_level  = $inner_opening->[_LEVEL_];
             if ( !$rOpts_variable_maximum_line_length ) {
-                $starting_indent = $rOpts_indent_columns * $starting_level;
+                my $level = $inner_opening->[_LEVEL_];
+                $starting_indent = $rOpts_indent_columns * $level;
             }
 
             if (DEBUG_WELD) {
@@ -8546,7 +8557,10 @@ sub extended_ci {
             next;
         }
 
-        # Skip if this is a -bli container (this fixes case b1065)
+        # Skip if this is a -bli container (this fixes case b1065) Note: case
+        # b1065 is also fixed by the update for b1055, so this update is not
+        # essential now.  But there does not seem to be a good reason to add
+        # xci and bli together, so the update is retained.
         if ( $ris_bli_container->{$seqno} ) {
             next;
         }
index 3f46c9b6334be4d68fe73e2650fc93c0ecd30ecd..930a08db0d1e29d049019fe48c8d815b23a710a8 100644 (file)
@@ -3,6 +3,13 @@
 
 =over 4
 
+=item B<Improve previous -wn update>
+
+The previous update produced some problems in testing which are corrected
+with this update.
+
+5 Apr 2021.
+
 =item B<Fix rare convergence problem with -wn>
 
 Random testing produced some cases in which unusual parameter combinations
index 93b8037809b2abff7821c6a4699f3d4156fd7d9d..b037744b6cc98c93729233dc27f9718faacbdeb4 100644 (file)
@@ -5,9 +5,9 @@
                 PDL::Graphics::TriD::Scale->new( $sx, $sy, $sz ) );
 
             # but weld this more complex statement
-            my $compass = uc( opposite_direction(
-                line_to_canvas_direction( @{ $coords[0] }, @{ $coords[1] } )
-            ) );
+            my $compass = uc( opposite_direction( line_to_canvas_direction(
+                @{ $coords[0] }, @{ $coords[1] }
+            ) ) );
 
             # OLD: do not weld to a one-line block because the function could
             # get separated from its opening paren.
index a9798f4d856f82ccc8ed42cb04c70f1f5e7f8d40..76958dace1ae69c94f27d4cbe445e392e86c8469 100644 (file)
@@ -544,9 +544,9 @@ use_all_ok( qw{
                 PDL::Graphics::TriD::Scale->new( $sx, $sy, $sz ) );
 
             # but weld this more complex statement
-            my $compass = uc( opposite_direction(
-                line_to_canvas_direction( @{ $coords[0] }, @{ $coords[1] } )
-            ) );
+            my $compass = uc( opposite_direction( line_to_canvas_direction(
+                @{ $coords[0] }, @{ $coords[1] }
+            ) ) );
 
             # OLD: do not weld to a one-line block because the function could
             # get separated from its opening paren.