From b3f3bb2bfdc19b0f78229c4fcc4c8eb01c13c06a Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 4 Jan 2021 07:51:33 -0800 Subject: [PATCH] moved previous patch to better location --- lib/Perl/Tidy/VerticalAligner.pm | 36 +++++++++++++++++--------------- local-docs/BugLog.pod | 8 ++++++- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index 924ee090..773c45fc 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -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; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 8bec9f94..1a8eb9de 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,12 @@ =over 4 +=item B + +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 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 -- 2.39.5