From: Steve Hancock Date: Wed, 9 Sep 2020 02:47:34 +0000 (-0700) Subject: -nib side comments get 1 space and do not align or form hanging side comments X-Git-Tag: 20200907.01~26 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5131cb4ea96da06532825988d423f72df26f088c;p=perltidy.git -nib side comments get 1 space and do not align or form hanging side comments --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 94d3b2d7..5c977d6a 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -315,6 +315,8 @@ BEGIN { _rweld_len_left_opening_ => $i++, _rweld_len_right_opening_ => $i++, + _rspecial_side_comment_type_ => $i++, + }; # Array index names for _this_batch_ (in above list) @@ -768,6 +770,8 @@ sub new { $self->[_rweld_len_left_opening_] = {}; $self->[_rweld_len_right_opening_] = {}; + $self->[_rspecial_side_comment_type_] = {}; + bless $self, $class; # Safety check..this is not a class yet @@ -4644,6 +4648,8 @@ sub non_indenting_braces { my $rLL = $self->[_rLL_]; return unless ( defined($rLL) && @{$rLL} ); + my $rspecial_side_comment_type = $self->[_rspecial_side_comment_type_]; + my $radjusted_levels; my $Kmax = @{$rLL} - 1; my @seqno_stack; @@ -4674,7 +4680,9 @@ sub non_indenting_braces { # we added it back for the match. That way we require an exact # match to the special string and also allow additional text. $token_sc .= "\n"; - return ( $token_sc =~ /$non_indenting_brace_pattern/ ); + my $is_nib = ( $token_sc =~ /$non_indenting_brace_pattern/ ); + if ($is_nib) { $rspecial_side_comment_type->{$K_sc} = 'NIB' } + return $is_nib; }; foreach my $KK ( 0 .. $Kmax ) { @@ -12710,6 +12718,7 @@ sub get_seqno { # accept vertical alignment. my ( $self, $ri_first, $ri_last ) = @_; + my $rspecial_side_comment_type = $self->[_rspecial_side_comment_type_]; my $rOpts_add_whitespace = $rOpts->{'add-whitespace'}; my $ralignment_type_to_go; @@ -12785,10 +12794,16 @@ sub get_seqno { # align a side comment -- elsif ( $type eq '#' ) { + my $KK = $K_to_go[$i]; + my $sc_type = $rspecial_side_comment_type->{$KK}; + unless ( - # it is a static side comment - ( + # it is any specially marked side comment + $sc_type + + # or it is a static side comment + || ( $rOpts->{'static-side-comments'} && $token =~ /$static_side_comment_pattern/ ) diff --git a/t/snippets/expect/nib.def b/t/snippets/expect/nib.def index 4499f503..32d71ec4 100644 --- a/t/snippets/expect/nib.def +++ b/t/snippets/expect/nib.def @@ -1,5 +1,5 @@ -{ #<<< -{ #<<< +{ #<<< +{ #<<< { #++ print "hello world\n"; } @@ -8,7 +8,7 @@ { #++ { #++ - { #<<< + { #<<< print "hello world\n"; } } diff --git a/t/snippets/expect/nib.nib2 b/t/snippets/expect/nib.nib2 index 4b36c954..d28b77f7 100644 --- a/t/snippets/expect/nib.nib2 +++ b/t/snippets/expect/nib.nib2 @@ -1,13 +1,13 @@ { #<<< { #<<< - { #++ + { #++ print "hello world\n"; } } } -{ #++ -{ #++ +{ #++ +{ #++ { #<<< print "hello world\n"; } diff --git a/t/snippets21.t b/t/snippets21.t index 5133d03e..a565dd8b 100644 --- a/t/snippets21.t +++ b/t/snippets21.t @@ -639,8 +639,8 @@ method sum_radlinks { source => "nib", params => "def", expect => <<'#14...........', -{ #<<< -{ #<<< +{ #<<< +{ #<<< { #++ print "hello world\n"; } @@ -649,7 +649,7 @@ method sum_radlinks { { #++ { #++ - { #<<< + { #<<< print "hello world\n"; } } @@ -687,14 +687,14 @@ method sum_radlinks { expect => <<'#16...........', { #<<< { #<<< - { #++ + { #++ print "hello world\n"; } } } -{ #++ -{ #++ +{ #++ +{ #++ { #<<< print "hello world\n"; }