From: Steve Hancock Date: Thu, 8 Oct 2020 19:22:03 +0000 (-0700) Subject: make do and sub blocks work better with -xci X-Git-Tag: 20201001.01~8 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4dd4966f5e67dce159f868a3752452d0377cd252;p=perltidy.git make do and sub blocks work better with -xci --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index cdaef1c1..00d795eb 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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_] );