]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix for issue git #53, do not align spaced function parens
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 5 Mar 2021 16:39:58 +0000 (08:39 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 5 Mar 2021 16:39:58 +0000 (08:39 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 155762eeeb140a4b76740d078a97a3faa01b14d5..6a57f1c2794e864ce0aae5b9c61fda3d0857d1f3 100644 (file)
@@ -5781,14 +5781,19 @@ sub respace_tokens {
         my $K_opening = $K_opening_container->{$seqno};
         next unless defined($K_opening);
 
-        # only for lists, not for code blocks
-        my $block_type = $rLL_new->[$K_opening]->[_BLOCK_TYPE_];
-        next if ($block_type);
-
         # code errors may leave undefined closing tokens
         my $K_closing = $K_closing_container->{$seqno};
         next unless defined($K_closing);
 
+        my $lx_open   = $rLL_new->[$K_opening]->[_LINE_INDEX_];
+        my $lx_close  = $rLL_new->[$K_closing]->[_LINE_INDEX_];
+        my $line_diff = $lx_close - $lx_open;
+        $ris_broken_container->{$seqno} = $line_diff;
+
+        # The rest is only for lists, not for code blocks
+        my $block_type = $rLL_new->[$K_opening]->[_BLOCK_TYPE_];
+        next if ($block_type);
+
         my $rtype_count = $rtype_count_by_seqno->{$seqno};
         next unless ($rtype_count);
         my $comma_count     = $rtype_count->{','};
@@ -5800,12 +5805,7 @@ sub respace_tokens {
         my $is_list = ( $comma_count || $fat_comma_count ) && !$semicolon_count;
         if ($is_list) { $ris_list_by_seqno->{$seqno} = $seqno }
 
-        my $lx_open   = $rLL_new->[$K_opening]->[_LINE_INDEX_];
-        my $lx_close  = $rLL_new->[$K_closing]->[_LINE_INDEX_];
-        my $line_diff = $lx_close - $lx_open;
-
         if ($line_diff) {
-            $ris_broken_container->{$seqno} = $line_diff;
             my $seqno_parent = $rparent_of_seqno->{$seqno};
             if ( defined($seqno_parent) && $seqno_parent ne SEQ_ROOT ) {
                 $rhas_broken_container->{$seqno_parent} = 1;
@@ -14959,10 +14959,12 @@ sub set_continuation_breaks {
                         # line difference is > 1 (see case b977)
                         if ($ok) {
                             my $seqno = $type_sequence_to_go[$i_line_start];
-                            if (   $ris_broken_container->{$seqno}
-                                && $ris_broken_container->{$seqno} <= 1 )
+                            if (  !$ris_broken_container->{$seqno}
+                                || $ris_broken_container->{$seqno} <= 1 )
                             {
                                 $ok = 0;
+                                print
+                                  "BOOGA, $ris_broken_container->{$seqno}\n";
                             }
                         }
 
@@ -18231,6 +18233,22 @@ sub send_lines_to_vertical_aligner {
                               unless $vert_last_nonblank_token =~
                               /^(if|unless|elsif)$/;
                         }
+
+                        # Do not align a spaced-function-paren - fixes git #53
+                        # Note that index $i-1 is a blank token if we get here
+                        if ( $i > $ibeg + 1 ) {
+                            my $type_m  = $types_to_go[ $i - 2 ];
+                            my $token_m = $tokens_to_go[ $i - 2 ];
+
+                            # this is the same test as 'space-function-paren'
+                            if (   $type_m =~ /^[wUG]$/
+                                || $type_m eq '->'
+                                || $type_m  =~ /^[wi]$/
+                                && $token_m =~ /^(\&|->)/ )
+                            {
+                                $alignment_type = "";
+                            }
+                        }
                     }
 
                     # be sure the alignment tokens are unique
index b503086f3c7d7807a7bb2bca982cf792835fc4a3..23a63fcfc6c2faa372f603b3aefbb0ce13162fc2 100644 (file)
@@ -2,6 +2,30 @@
 
 =over 4
 
+=item B<Fix for issue git #53, do not align spaced function parens>
+
+Introducing a space before a function call paren had a side effect of
+allowing the vertical aligner to align the parens, as in the example.
+
+    # OLD and NEW, default without -sfp:
+    log_something_with_long_function( 'This is a log message.', 2 );
+    Coro::AnyEvent::sleep( 3, 4 );
+
+    # OLD: perltidy -sfp 
+    log_something_with_long_function ( 'This is a log message.', 2 );
+    Coro::AnyEvent::sleep            ( 3, 4 );
+
+    # NEW: perltidy -sfp 
+    log_something_with_long_function ( 'This is a log message.', 2 );
+    Coro::AnyEvent::sleep ( 3, 4 );
+
+This update changes the default to not do this vertical alignment.  This should
+have been the default but this side-effect was missed when the -sfp parameter
+was added.  Note that parens following keywords are likewise not vertically
+aligned.
+
+5 Mar 2021.
+
 =item B<Fix issue git#54 involving -bbp=n and -bbpi=n>
 
 In this issue, different results were obtained depending upon the existance of
@@ -11,7 +35,7 @@ requiring one or more commas to requiring either a fat comma or a comma.
 At the same time, a known problem involving the combination -lp -bbp=n -bbpi=n
 was fixed.  This fixes cases b826 b909 b989.
 
-4 Mar 2021.
+4 Mar 2021, 872d4b4.
 
 =item B<Fix several minor weld issues>