]> git.donarmstrong.com Git - perltidy.git/commitdiff
make do and sub blocks work better with -xci
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 8 Oct 2020 19:22:03 +0000 (12:22 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 8 Oct 2020 19:22:03 +0000 (12:22 -0700)
lib/Perl/Tidy/Formatter.pm

index cdaef1c1a813663aa82c4aa9ce52f7439caaafb5..00d795ebb4d3f231c9ef3b5c8f21a5d864a327cf 100644 (file)
@@ -172,6 +172,7 @@ my (
     %is_opening_token,
     %is_closing_token,
     %is_equal_or_fat_comma,
+    %is_block_with_ci,
 
     # Initialized in check_options. These are constants and could
     # just as well be initialized in a BEGIN block.
@@ -514,6 +515,10 @@ BEGIN {
     @q = qw( = => );
     @is_equal_or_fat_comma{@q} = (1) x scalar(@q);
 
+    # These block types can take ci.  This is used by the -xci option.
+    @q = qw( do sub );
+    @is_block_with_ci{@q} = (1) x scalar(@q);
+
 }
 
 {    ## begin closure to count instanes
@@ -6868,6 +6873,13 @@ sub extended_ci {
         my $KK = $KNEXT;
         $KNEXT = $rLL->[$KNEXT]->[_KNEXT_SEQ_ITEM_];
 
+       # Certain block types arrive from the tokenizer without CI but should
+       # have it for this option.  These include 'do' and anonymous subs.
+        my $block_type = $rLL->[$KK]->[_BLOCK_TYPE_];
+        if ( $block_type && $is_block_with_ci{$block_type} ) {
+            $rLL->[$KK]->[_CI_LEVEL_] = 1;
+        }
+
         # This is only for containers with ci
         next unless ( $rLL->[$KK]->[_CI_LEVEL_] );