]> git.donarmstrong.com Git - perltidy.git/commitdiff
add -xlp flag
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 20 Nov 2021 01:52:11 +0000 (17:52 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 20 Nov 2021 01:52:11 +0000 (17:52 -0800)
CHANGES.md
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm

index efcff45055ee7799205be56e7b628a0ca97834ef..34541c4a5200672f092543ccc3d747723871f0d4 100644 (file)
@@ -1,5 +1,10 @@
 # Perltidy Change Log
 
+## 2021 10 29 xx
+
+    - The coding for the -lp flag has been rewritten to avoid some problems
+      and limitations.
+
 ## 2021 10 29
 
     - No significant bugs have been found since the last release, but several
index 6218176928032efad1b82d3d05b873dd37c0c44a..71965ba60a6a905a5573fdf9106221f7aa064ec4 100644 (file)
@@ -2263,6 +2263,7 @@ sub generate_options {
     $add_option->( 'continuation-indentation',             'ci',    '=i' );
     $add_option->( 'extended-continuation-indentation',    'xci',   '!' );
     $add_option->( 'line-up-parentheses',                  'lp',    '!' );
+    $add_option->( 'extended-line-up-parentheses',         'xlp',   '!' );
     $add_option->( 'line-up-parentheses-exclusion-list',   'lpxl',  '=s' );
     $add_option->( 'outdent-keyword-list',                 'okwl',  '=s' );
     $add_option->( 'outdent-keywords',                     'okw',   '!' );
index 48299459b005dec7ff40714826176ff28bf4336a..a96d2f51ac157679381b75e1910137406363c3eb 100644 (file)
@@ -46,13 +46,6 @@ use warnings;
 # This flag gets switched on during automated testing for extra checking
 use constant DEVEL_MODE => 0;
 
-# This temporary flag is being used to test new coding for -lp:
-# 0 = old version, process by token   [ no longer available ]
-# 1 = new version, process in batches [ like 0 but more one-line blocks ]
-# 2 = new version w/minimal objects   [ like 1 but faster and improves -xci ]
-# 3 = new version plus skip finish_lp [ like 2 plus -lp works past line breaks ]
-use constant TEST_NEW_LP => 2;
-
 { #<<< A non-indenting brace to contain all lexical variables
 
 use Carp;
@@ -201,6 +194,7 @@ my (
     $rOpts_valign_code,
     $rOpts_valign_side_comments,
     $rOpts_whitespace_cycle,
+    $rOpts_extended_line_up_parentheses,
 
     # Static hashes initialized in a BEGIN block
     %is_assignment,
@@ -1270,6 +1264,11 @@ sub check_options {
         Exit(0);
     }
 
+    # -xlp implies -lp
+    if ( $rOpts->{'extended-line-up-parentheses'} ) {
+        $rOpts->{'line-up-parentheses'} ||= 1;
+    }
+
     if ( $rOpts->{'line-up-parentheses'} ) {
 
         if (   $rOpts->{'indent-only'}
@@ -1709,7 +1708,9 @@ EOM
     $rOpts_indent_only              = $rOpts->{'indent-only'};
     $rOpts_keep_interior_semicolons = $rOpts->{'keep-interior-semicolons'};
     $rOpts_line_up_parentheses      = $rOpts->{'line-up-parentheses'};
-    $rOpts_logical_padding          = $rOpts->{'logical-padding'};
+    $rOpts_extended_line_up_parentheses =
+      $rOpts->{'extended-line-up-parentheses'};
+    $rOpts_logical_padding = $rOpts->{'logical-padding'};
     $rOpts_maximum_consecutive_blank_lines =
       $rOpts->{'maximum-consecutive-blank-lines'};
     $rOpts_maximum_fields_per_table  = $rOpts->{'maximum-fields-per-table'};
@@ -13374,8 +13375,7 @@ EOM
         if ($rOpts_line_up_parentheses) {
             $self->set_lp_indentation();
 
-            # This call will eventually be removed
-            finish_lp_batch() if ( TEST_NEW_LP < 3 );
+            finish_lp_batch() if ( !$rOpts_extended_line_up_parentheses );
         }
 
         #----------------------------
@@ -19575,10 +19575,6 @@ sub get_available_spaces_to_go {
         $max_gnu_item_index  = -1;
 
         my $gs_object;
-        if ( TEST_NEW_LP < 2 && $rOpts_line_up_parentheses ) {
-            $gs_object = new_lp_indentation_item( 0, -1, -1, 0, 0 );
-        }
-
         $rGS = [];
 
         $rGS->[$max_gnu_stack_index]->[_gs_ci_level_]     = -1;
@@ -20696,6 +20692,11 @@ EOM
           )
         {
             $rvao_args->{outdent_long_lines} = 1;
+
+            # convert -lp indentation objects to spaces to allow outdenting
+            if ( ref($indentation) ) {
+                $indentation = $indentation->get_spaces();
+            }
         }
 
         # --------------------------------------------------