]> git.donarmstrong.com Git - perltidy.git/commitdiff
-nib side comments get 1 space and do not align or form hanging side comments
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 9 Sep 2020 02:47:34 +0000 (19:47 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 9 Sep 2020 02:47:34 +0000 (19:47 -0700)
lib/Perl/Tidy/Formatter.pm
t/snippets/expect/nib.def
t/snippets/expect/nib.nib2
t/snippets21.t

index 94d3b2d757043357c416058018e1dda8da35b01a..5c977d6ad0d8c83b8ffe1bbca77f4588f0cc79d3 100644 (file)
@@ -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/
                         )
index 4499f5032be89b9bef4f7e577b5e2beca60bca70..32d71ec458b558c344107c7cd14a520348761a59 100644 (file)
@@ -1,5 +1,5 @@
-{    #<<<
-{    #<<<
+{ #<<<
+{ #<<<
 {    #++
     print "hello world\n";
 }
@@ -8,7 +8,7 @@
 
 {    #++
     {    #++
-        {    #<<<
+        { #<<<
         print "hello world\n";
         }
     }
index 4b36c954c865214eff175fc90c10597049fa823d..d28b77f77a40d09f35e3578694d31b1c94ecebd7 100644 (file)
@@ -1,13 +1,13 @@
 {    #<<<
     {    #<<<
-        {    #++
+        { #++
         print "hello world\n";
         }
     }
 }
 
-{    #++
-{    #++
+{ #++
+{ #++
 {    #<<<
     print "hello world\n";
 }
index 5133d03e32f6dc3f97071ea4c5aef18f862e779f..a565dd8bbe0b58e8d029c5adf924b6d6b4042cc9 100644 (file)
@@ -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";
 }