From: Steve Hancock Date: Tue, 25 Aug 2020 19:46:13 +0000 (-0700) Subject: reset side comment location at a new level 0 opening block X-Git-Tag: 20200907~34 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6a13ff7024ad3855e730edecce9060cee5e60069;p=perltidy.git reset side comment location at a new level 0 opening block --- diff --git a/CHANGES.md b/CHANGES.md index a6f86deb..d7c49749 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Perltidy Change Log + - Side comment locations reset at a line ending in a level 0 open + block, such as when a new multi-line sub begins. This is intended to + help keep side comments from drifting to far to the right. + ## 2020 08 22 - Fix RT #133166, encoding not set for -st. Also reported as RT #133171 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 15ef4418..8608d742 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -10645,13 +10645,15 @@ sub send_lines_to_vertical_aligner { $self->make_alignment_patterns( $ibeg, $iend, $ralignment_type_to_go ); - my ( $indentation, $lev, $level_end, $terminal_type, + my ( $indentation, $lev, $level_end, $terminal_type, $i_terminal, $is_semicolon_terminated, $is_outdented_line ) = $self->set_adjusted_indentation( $ibeg, $iend, $rfields, $rpatterns, $ri_first, $ri_last, $rindentation_list, $ljump, $starting_in_quote, $is_static_block_comment, ); + my $terminal_block_type=$block_type_to_go[$i_terminal]; + # we will allow outdenting of long lines.. my $outdent_long_lines = ( @@ -10753,6 +10755,7 @@ sub send_lines_to_vertical_aligner { $rvalign_hash->{rpatterns} = $rpatterns; $rvalign_hash->{rtokens} = $rtokens; $rvalign_hash->{rfield_lengths} = $rfield_lengths; + $rvalign_hash->{terminal_block_type} = $terminal_block_type; my $vao = $self->[_vertical_aligner_object_]; $vao->valign_input($rvalign_hash); @@ -12080,7 +12083,7 @@ sub lookup_opening_indentation { } } - return ( $indentation, $lev, $level_end, $terminal_type, + return ( $indentation, $lev, $level_end, $terminal_type, $i_terminal, $is_semicolon_terminated, $is_outdented_line ); } } diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index cd6a339e..1073eff6 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -354,6 +354,7 @@ sub valign_input { my $rtokens = $rline_hash->{rtokens}; my $rpatterns = $rline_hash->{rpatterns}; my $rfield_lengths = $rline_hash->{rfield_lengths}; + my $terminal_block_type = $rline_hash->{terminal_block_type}; # number of fields is $jmax # number of tokens between fields is $jmax-1 @@ -394,6 +395,12 @@ sub valign_input { $self->[_consecutive_block_comments_] = 0; } + # Reset side comment location if we are entering a new block from level 0. + # This is intended to keep them from drifting too far to the right. + if ( $terminal_block_type && $level == 0 && $level_end > $level ) { + $self->forget_side_comment(); + } + my $group_level = $self->[_group_level_]; 0 && do { diff --git a/t/snippets/expect/comments.comments2 b/t/snippets/expect/comments.comments2 index feac27a7..713e9d33 100644 --- a/t/snippets/expect/comments.comments2 +++ b/t/snippets/expect/comments.comments2 @@ -20,7 +20,7 @@ sub macro_get_names { # 'Nov', 'Dec' ); -{ # this side comment will not align +{ # this side comment will not align my $IGNORE = 0; # This is a side comment # This is a hanging side comment # And so is this diff --git a/t/snippets/expect/comments.def b/t/snippets/expect/comments.def index 2bfe03ec..09d57974 100644 --- a/t/snippets/expect/comments.def +++ b/t/snippets/expect/comments.def @@ -30,7 +30,7 @@ sub macro_get_names { # 'Nov', 'Dec' ); -{ # this side comment will not align +{ # this side comment will not align my $IGNORE = 0; # This is a side comment # This is a hanging side comment # And so is this diff --git a/t/snippets/expect/gnu7.def b/t/snippets/expect/gnu7.def index f8f2d689..8c3ce0e0 100644 --- a/t/snippets/expect/gnu7.def +++ b/t/snippets/expect/gnu7.def @@ -7,7 +7,7 @@ elsif ( $seen == 2 ) { # We're the second word to have this # abbreviation, so we can't use it. delete $hashref->{$abbrev}; } -else { # We're the third word to have this - # abbreviation, so skip to the next word. +else { # We're the third word to have this + # abbreviation, so skip to the next word. next WORD; } diff --git a/t/snippets17.t b/t/snippets17.t index b670832b..e5e78c68 100644 --- a/t/snippets17.t +++ b/t/snippets17.t @@ -420,7 +420,7 @@ sub macro_get_names { # 'Nov', 'Dec' ); -{ # this side comment will not align +{ # this side comment will not align my $IGNORE = 0; # This is a side comment # This is a hanging side comment # And so is this @@ -688,7 +688,7 @@ sub macro_get_names { # 'Nov', 'Dec' ); -{ # this side comment will not align +{ # this side comment will not align my $IGNORE = 0; # This is a side comment # This is a hanging side comment # And so is this diff --git a/t/snippets21.t b/t/snippets21.t index 52e4d78c..a41b6967 100644 --- a/t/snippets21.t +++ b/t/snippets21.t @@ -460,8 +460,8 @@ elsif ( $seen == 2 ) { # We're the second word to have this # abbreviation, so we can't use it. delete $hashref->{$abbrev}; } -else { # We're the third word to have this - # abbreviation, so skip to the next word. +else { # We're the third word to have this + # abbreviation, so skip to the next word. next WORD; } #8...........