]> git.donarmstrong.com Git - perltidy.git/commitdiff
reset side comment location at a new level 0 opening block
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 25 Aug 2020 19:46:13 +0000 (12:46 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 25 Aug 2020 19:46:13 +0000 (12:46 -0700)
CHANGES.md
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/VerticalAligner.pm
t/snippets/expect/comments.comments2
t/snippets/expect/comments.def
t/snippets/expect/gnu7.def
t/snippets17.t
t/snippets21.t

index a6f86debb5f41fc50c71f77a1c7b88d56c3486a4..d7c49749a6ac76b85d31be56b6cdf7c8f418b7e3 100644 (file)
@@ -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
index 15ef4418db8effcad3a72fa96e364c57574f5f23..8608d7422c3c485df7da673724fa96059b4d413e 100644 (file)
@@ -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 );
     }
 }
index cd6a339ea513dbfe03ec83175bbecccf5b2ce6e5..1073eff6d5d496100273fa7b53e0ce273a84e320 100644 (file)
@@ -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 {
index feac27a7b432a934f70c4997b4983b3a20714c05..713e9d33570b4a59e972e6ff5c2a7ad76d060f1c 100644 (file)
@@ -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
index 2bfe03ec6549ef74536a6d72adf595bed3dcf280..09d57974c66a53ceef6816a46e9e8646d185560c 100644 (file)
@@ -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
index f8f2d6890f290e5f29cc3e6e37b696a64093ddd1..8c3ce0e0484bce012f34f5cb442089edcf97066c 100644 (file)
@@ -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;
 }
index b670832bd434b1e70ad7ab70738c761927ff803e..e5e78c68d2376ef4d0ee78d7accd2ad2769bb65f 100644 (file)
@@ -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
index 52e4d78cd1ec02ffbfd14db065713525ceaaab3d..a41b696776492f8cd9d601a84a64ec9d4c671db3 100644 (file)
@@ -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...........