From: Steve Hancock Date: Wed, 14 Jun 2023 18:24:17 +0000 (-0700) Subject: Do not align opening braces across ci level changes (c224) X-Git-Tag: 20230309.04~12 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=a748829755baf40dd7c641d10a9a1220bb567ae0;p=perltidy.git Do not align opening braces across ci level changes (c224) --- diff --git a/docs/ci_update.md b/docs/ci_update.md index e729c8b2..f1a6d51c 100644 --- a/docs/ci_update.md +++ b/docs/ci_update.md @@ -350,3 +350,22 @@ of side comments. The new version handles this correctly: readdir(D) ); ``` + +A related change is that some undesirable alignments across changes in +continuation indentation have been removed. For example, here is an +example of this issue as previously formatted: + +``` + print $fh map { $_->[0] } + sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] } + map { my $f = lc $_; $f =~ s/[^a-z0-9\s]//g; [ $_, $f ] } @manifest; +``` + +The alignment of the ``map`` and ``sort`` braces produces an undesirable +gap. The revised formatting avoids this: + +``` + return sort grep { length($_) > 0 } + map { substr( $_, $length ) } + grep { starts_with( $_, $prefix . $text ) } @bookmarks; +``` diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 8b093fbb..24f71b8e 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -28969,6 +28969,10 @@ sub xlp_tweak { if ( $block_type =~ /^[A-Z]+$/ ) { $block_type = 'BEGIN' } $tok .= $block_type; + + # Avoid aligning opening braces across leading ci level + # changes by marking block type with _ci (issue c224) + if ( $ci_levels_to_go[$ibeg] ) { $tok .= '_1' } } # Mark multiple copies of certain tokens with the copy number