]> git.donarmstrong.com Git - perltidy.git/commitdiff
eliminate sub initialize_lp_part2
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 16 Sep 2023 01:49:59 +0000 (18:49 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 16 Sep 2023 01:49:59 +0000 (18:49 -0700)
lib/Perl/Tidy/Formatter.pm

index 05e8ec3c37b76b0eee18e543ffd54c8241abe904..43693dc2064f7e6b02f545d7085d7f0e1185bc7a 100644 (file)
@@ -293,7 +293,7 @@ my (
     # INITIALIZER: initialize_container_indentation_options
     %container_indentation_options,
 
-    # INITIALIZER: sub initialize_lp_part1
+    # INITIALIZER: sub initialize_line_up_parentheses
     %line_up_parentheses_control_hash,
     $line_up_parentheses_control_is_lxpl,
 
@@ -1422,7 +1422,7 @@ sub check_options {
         Exit(0);
     }
 
-    initialize_lp_part1();
+    initialize_line_up_parentheses();
 
     check_tabs();
 
@@ -1458,8 +1458,6 @@ EOM
     initialize_token_break_preferences();
     initialize_old_breakpoint_controls();
 
-    initialize_lp_part2();
-
     initialize_container_indentation_options();
 
     # make -l=0 equal to -l=infinite
@@ -2046,10 +2044,34 @@ sub initialize_token_break_preferences {
     for ( $rOpts->{'break-before-paren'} ) {
         $break_before_container_types{'('} = $_ if $_ && $_ > 0;
     }
+
+    #--------------------------------------------------------------
+    # The combination -lp -iob -vmll -bbx=2 can be unstable (b1266)
+    #--------------------------------------------------------------
+    # The -vmll and -lp parameters do not really work well together.
+    # To avoid instabilities, we will change any -bbx=2 to -bbx=1 (stable).
+    # NOTE: we could make this more precise by looking at any exclusion
+    # flags for -lp, and allowing -bbx=2 for excluded types.
+    if (   $rOpts->{'variable-maximum-line-length'}
+        && $rOpts->{'ignore-old-breakpoints'}
+        && $rOpts->{'line-up-parentheses'} )
+    {
+        my @changed;
+        foreach my $key ( keys %break_before_container_types ) {
+            if ( $break_before_container_types{$key} == 2 ) {
+                $break_before_container_types{$key} = 1;
+                push @changed, $key;
+            }
+        }
+        if (@changed) {
+
+            # we could write a warning here
+        }
+    }
     return;
 } ## end sub initialize_token_break_preferences
 
-sub initialize_lp_part1 {
+sub initialize_line_up_parentheses {
 
     # -xlp implies -lp
     if ( $rOpts->{'extended-line-up-parentheses'} ) {
@@ -2083,6 +2105,38 @@ EOM
         }
     }
 
+    #-----------------------------------------------------------
+    # The combination -lp -vmll can be unstable if -ci<2 (b1267)
+    #-----------------------------------------------------------
+    # The -vmll and -lp parameters do not really work well together.
+    # This is a very crude fix for an unusual parameter combination.
+    if (   $rOpts->{'variable-maximum-line-length'}
+        && $rOpts->{'line-up-parentheses'}
+        && $rOpts->{'continuation-indentation'} < 2 )
+    {
+        $rOpts->{'continuation-indentation'} = 2;
+        ##Warn("Increased -ci=n to n=2 for stability with -lp and -vmll\n");
+    }
+
+    #-----------------------------------------------------------
+    # The combination -lp -vmll -atc -dtc can be unstable
+    #-----------------------------------------------------------
+    # This fixes b1386 b1387 b1388 which had -wtc='b'
+    # Updated to to include any -wtc to fix b1426
+    if (   $rOpts->{'variable-maximum-line-length'}
+        && $rOpts->{'line-up-parentheses'}
+        && $rOpts->{'add-trailing-commas'}
+        && $rOpts->{'delete-trailing-commas'}
+        && $rOpts->{'want-trailing-commas'} )
+    {
+        $rOpts->{'delete-trailing-commas'} = 0;
+## Issuing a warning message causes trouble with test cases, and this combo is
+## so rare that it is unlikely to not occur in practice. So skip warning.
+##        Warn(
+##"The combination -vmll -lp -atc -dtc can be unstable; turning off -dtc\n"
+##        );
+    }
+
     %line_up_parentheses_control_hash    = ();
     $line_up_parentheses_control_is_lxpl = 1;
     my $lpxl = $rOpts->{'line-up-parentheses-exclusion-list'};
@@ -2107,7 +2161,7 @@ EOM
     }
 
     return;
-} ## end sub initialize_lp_part1
+} ## end sub initialize_line_up_parentheses
 
 sub check_tabs {
 
@@ -2139,69 +2193,6 @@ EOM
     return;
 } ## end sub check_tabs
 
-sub initialize_lp_part2 {
-
-    # TODO: try to merge with sub initialize_lp_part1
-
-    #--------------------------------------------------------------
-    # The combination -lp -iob -vmll -bbx=2 can be unstable (b1266)
-    #--------------------------------------------------------------
-    # The -vmll and -lp parameters do not really work well together.
-    # To avoid instabilities, we will change any -bbx=2 to -bbx=1 (stable).
-    # NOTE: we could make this more precise by looking at any exclusion
-    # flags for -lp, and allowing -bbx=2 for excluded types.
-    if (   $rOpts->{'variable-maximum-line-length'}
-        && $rOpts->{'ignore-old-breakpoints'}
-        && $rOpts->{'line-up-parentheses'} )
-    {
-        my @changed;
-        foreach my $key ( keys %break_before_container_types ) {
-            if ( $break_before_container_types{$key} == 2 ) {
-                $break_before_container_types{$key} = 1;
-                push @changed, $key;
-            }
-        }
-        if (@changed) {
-
-            # we could write a warning here
-        }
-    }
-
-    #-----------------------------------------------------------
-    # The combination -lp -vmll can be unstable if -ci<2 (b1267)
-    #-----------------------------------------------------------
-    # The -vmll and -lp parameters do not really work well together.
-    # This is a very crude fix for an unusual parameter combination.
-    if (   $rOpts->{'variable-maximum-line-length'}
-        && $rOpts->{'line-up-parentheses'}
-        && $rOpts->{'continuation-indentation'} < 2 )
-    {
-        $rOpts->{'continuation-indentation'} = 2;
-        ##Warn("Increased -ci=n to n=2 for stability with -lp and -vmll\n");
-    }
-
-    #-----------------------------------------------------------
-    # The combination -lp -vmll -atc -dtc can be unstable
-    #-----------------------------------------------------------
-    # This fixes b1386 b1387 b1388 which had -wtc='b'
-    # Updated to to include any -wtc to fix b1426
-    if (   $rOpts->{'variable-maximum-line-length'}
-        && $rOpts->{'line-up-parentheses'}
-        && $rOpts->{'add-trailing-commas'}
-        && $rOpts->{'delete-trailing-commas'}
-        && $rOpts->{'want-trailing-commas'} )
-    {
-        $rOpts->{'delete-trailing-commas'} = 0;
-## Issuing a warning message causes trouble with test cases, and this combo is
-## so rare that it is unlikely to not occur in practice. So skip warning.
-##        Warn(
-##"The combination -vmll -lp -atc -dtc can be unstable; turning off -dtc\n"
-##        );
-    }
-
-    return;
-} ## end sub initialize_lp_part2
-
 sub initialize_container_indentation_options {
 
     %container_indentation_options = ();