]> git.donarmstrong.com Git - perltidy.git/commitdiff
moved previous patch to better location
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 4 Jan 2021 15:51:33 +0000 (07:51 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 4 Jan 2021 15:51:33 +0000 (07:51 -0800)
lib/Perl/Tidy/VerticalAligner.pm
local-docs/BugLog.pod

index 924ee0906840d2711dabd4fbc60a941e61fc73d3..773c45fc669299f306da1984458ada6417a65f3e 100644 (file)
@@ -4375,6 +4375,25 @@ sub adjust_side_comments {
 
     my $last_side_comment_column = $self->[_last_side_comment_column_];
 
+    # Forget the last side comment if this comment might join a cached line
+    if ( my $cached_line_type = get_cached_line_type() ) {
+
+        # PATCH: Forget last side comment col if we might join the next
+        # line to this line. Otherwise side comment alignment will get
+        # messed up.  For example, in the following test script
+        # with using 'perltidy -sct -act=2', the last comment would try to
+        # align with the previous and then be in the wrong column when
+        # the lines are combined:
+
+        # foreach $line (
+        #    [0, 1, 2], [3, 4, 5], [6, 7, 8],    # rows
+        #    [0, 3, 6], [1, 4, 7], [2, 5, 8],    # columns
+        #    [0, 4, 8], [2, 4, 6]
+        #  )                                     # diagonals
+        $last_side_comment_column = 0
+          if ( $cached_line_type == 2 || $cached_line_type == 4 );
+    }
+
     # If there are multiple groups we will do two passes
     # so that we can find a common alignment for all groups.
     my $MAX_PASS = @todo > 1 ? 2 : 1;
@@ -4810,23 +4829,6 @@ sub get_output_line_number {
                 $open_or_close, $tightness_flag, $seqno, $valid, $seqno_beg,
                 $seqno_end
             ) = @{$rvertical_tightness_flags};
-
-            # PATCH: Forget last side comment col if we might join the next
-            # line to this line. Otherwise side comment alignment will get
-            # messed up.  For example, in the following test script the last
-            # comment would try to align with the previous comment and then be
-            # in the wrong column when the lines are combined:
-
-            # # perltidy -sct -act=2
-            # foreach $line (
-            #    [0, 1, 2], [3, 4, 5], [6, 7, 8],    # rows
-            #    [0, 3, 6], [1, 4, 7], [2, 5, 8],    # columns
-            #    [0, 4, 8], [2, 4, 6]
-            #  )                                     # diagonals
-
-            if ( $open_or_close == 2 || $open_or_close == 4 ) {
-                $self->forget_side_comment();
-            }
         }
 
         $seqno_string = $seqno_end;
index 8bec9f94c165f3838a0f1b2f48f177ce5c9f8994..1a8eb9de530c5d310dbbb2404de2f0efd9534da2 100644 (file)
@@ -2,6 +2,12 @@
 
 =over 4
 
+=item B<Moved previous patch to a better location>
+
+The previous patch was moved to a location where it only applies if
+there is a side comment on the line with a closing token.  This minimizes
+changes to other side comment locations.
+
 =item B<Further improvement in rules for forgetting last side comment location>
 
 The code for forgetting the last side comment location was rewritten to improve
@@ -26,7 +32,7 @@ In the old version the last side comment was aligned before the closing paren
 was attached to the previous line, causing the final side comment to be far to
 the right.  A patch in the new version just places it at the default location.
 This is the best than can be done for now, but is preferable to the old
-formatting.
+formatting. 3 Jan 2021, e57d8db.
 
 =item B<Improve rule for forgetting last side comment location>