From: Steve Hancock Date: Sun, 11 Nov 2018 14:54:52 +0000 (-0800) Subject: Vertical alignment improvements for =~ and // X-Git-Tag: 20181117~25 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b61825bbbcd5a60b21c35c1ae92351676da98b0f;p=perltidy.git Vertical alignment improvements for =~ and // --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 4ab86b9b..5788ca63 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -10611,11 +10611,11 @@ sub get_seqno { my @q; - # Removed =~ from list to improve chances of alignment - # Removed // from list to improve chances of alignment (RT# 119588) + # replaced =~ in the list + # TESTING: replaced. Removed // from list to improve chances of alignment (RT# 119588) @q = qw# = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x= - { ? : => && || ~~ !~~ + { ? : => && || ~~ !~~ =~ // #; @is_vertical_alignment_type{@q} = (1) x scalar(@q); @@ -10672,6 +10672,7 @@ sub get_seqno { $vert_last_nonblank_block_type = ''; # look at each token in this output line.. + my $count=0; foreach my $i ( $ibeg .. $iend ) { my $alignment_type = ''; my $type = $types_to_go[$i]; @@ -10823,10 +10824,25 @@ sub get_seqno { $alignment_type = $vert_last_nonblank_type; } + #-------------------------------------------------------- + # patch for =~ operator. We only align this if it + # is the first operator in a line, and the line is a simple + # statement. Aligning them within a statement causes + # interferes with other good alignments. + #-------------------------------------------------------- + if ( $alignment_type eq '=~' ) { + my $terminal_type = $types_to_go[$i_terminal]; + if ( $count > 0 || $max_line > 0 || $terminal_type ne ';' ) + { + $alignment_type = ""; + } + } + #-------------------------------------------------------- # then store the value #-------------------------------------------------------- $matching_token_to_go[$i] = $alignment_type; + $count++ if ($alignment_type); if ( $type ne 'b' ) { $vert_last_nonblank_type = $type; $vert_last_nonblank_token = $token; diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index a6fc4d0a..5a823bb8 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -1953,23 +1953,28 @@ sub decide_if_aligned { my $group_list_type = $group_lines[0]->get_list_type(); + # See if these two lines have leading equals type tokens + my $rtokens = $group_lines[0]->get_rtokens(); + my $leading_equals = $rtokens->[0] =~ /=/; + my $do_not_align = ( # always align lists !$group_list_type + # always align lines with leading equality operators + && !$leading_equals + && ( - # don't align if it was just a marginal match + # don't align if it was marked as a 'marginal" match $marginal_match # don't align two lines with big gap || $group_maximum_gap > 12 - # or lines with differing number of alignment tokens - # TODO: this could be improved. It occasionally rejects - # good matches. - || $previous_maximum_jmax_seen != $previous_minimum_jmax_seen + # don't align lines with differing number of alignment tokens + || ( $previous_maximum_jmax_seen != $previous_minimum_jmax_seen ) ) ); diff --git a/local-docs/ChangeLog.pod b/local-docs/ChangeLog.pod index ea2cad33..16cb654c 100644 --- a/local-docs/ChangeLog.pod +++ b/local-docs/ChangeLog.pod @@ -2,6 +2,10 @@ =head2 2018 02 20.01 + - The packaging for this version has changed. The Tidy.pm file has + been split into a smaller Tidy.pm file plus supporting modules in the path + Perl/Tidy/*. + - Fixed RT #126965, in which a ternary operator was misparsed if immediately following a function call without arguments, such as: my $restrict_customer = shift ? 1 : 0; @@ -46,9 +50,42 @@ stamp on certain closing side comments. We need to avoid this in order to test this feature in an installation test. - - The packaging for this version has changed. The Tidy.pm file has - been split into a smaller Tidy.pm file plus supporting modules in the path - Perl/Tidy/*. + - Vertical alignment has been improved in several ways. Thanks especially to + Glenn for sending helpful snippets. + + - In many cases, two lines which were previously left unaligned are now + aligned. + + OLD: + $expect = "1$expect" if $expect =~ /^e/i; + $p = "1$p" if defined $p and $p =~ /^e/i; + + NEW: + $expect = "1$expect" if $expect =~ /^e/i; + $p = "1$p" if defined $p and $p =~ /^e/i; + + - Alignment of the =~ operators has been reactivated. + + OLD: + $service_profile =~ s/^\s+|\s+$//g; + $host_profile =~ s/^\s+|\s+$//g; + + NEW: + $service_profile =~ s/^\s+|\s+$//g; + $host_profile =~ s/^\s+|\s+$//g; + + - Alignment of the // operator has been reactivated. + + OLD: + is( pop // 7, 7, 'pop // ... works' ); + is( pop() // 7, 0, 'pop() // ... works' ); + is( pop @ARGV // 7, 3, 'pop @array // ... works' ); + + NEW: + is( pop // 7, 7, 'pop // ... works' ); + is( pop() // 7, 0, 'pop() // ... works' ); + is( pop @ARGV // 7, 3, 'pop @array // ... works' ); + =head2 2018 02 20 diff --git a/t/snippets/expect/arrows1.def b/t/snippets/expect/arrows1.def index d8759a38..e3a8b051 100644 --- a/t/snippets/expect/arrows1.def +++ b/t/snippets/expect/arrows1.def @@ -1,3 +1,3 @@ # remove spaces around arrows -my $obj = Bio::Variation::AAChange->new; +my $obj = Bio::Variation::AAChange->new; my $termcap = Term::Cap->Tgetent( { TERM => undef } ); diff --git a/t/snippets/expect/carat.def b/t/snippets/expect/carat.def index 285c4da8..9d02df1e 100644 --- a/t/snippets/expect/carat.def +++ b/t/snippets/expect/carat.def @@ -1,4 +1,4 @@ my $a = ${^WARNING_BITS}; @{^HOWDY_PARDNER} = ( 101, 102 ); -${^W} = 1; +${^W} = 1; $bb[$^]] = "bubba"; diff --git a/t/snippets/expect/tutor.def b/t/snippets/expect/tutor.def index e875b6ab..55b6e2dc 100644 --- a/t/snippets/expect/tutor.def +++ b/t/snippets/expect/tutor.def @@ -29,7 +29,7 @@ while (1) { $l[$i] = $u; chomp( $l[$i] ); $w[$i] = $t; - $t = 1000000; + $t = 1000000; } else { $l[$i] = $q[$z]; $w[$i] = $p[$z]; $z++; } print $l[$i], "\t", $w[$i], "\r\n"; diff --git a/t/snippets1.t b/t/snippets1.t index 21403836..e7c91e2e 100644 --- a/t/snippets1.t +++ b/t/snippets1.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:22 2018 +# Sun Nov 11 06:54:11 2018 # To locate test #13 for example, search for the string '#13' diff --git a/t/snippets10.t b/t/snippets10.t index 86cca9d2..e89f19cd 100644 --- a/t/snippets10.t +++ b/t/snippets10.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:23 2018 +# Sun Nov 11 06:54:12 2018 # To locate test #13 for example, search for the string '#13' diff --git a/t/snippets11.t b/t/snippets11.t index 7ecf70d8..0ddbe034 100644 --- a/t/snippets11.t +++ b/t/snippets11.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:23 2018 +# Sun Nov 11 06:54:12 2018 # To locate test #13 for example, search for the string '#13' @@ -416,7 +416,7 @@ while (1) { $l[$i] = $u; chomp( $l[$i] ); $w[$i] = $t; - $t = 1000000; + $t = 1000000; } else { $l[$i] = $q[$z]; $w[$i] = $p[$z]; $z++; } print $l[$i], "\t", $w[$i], "\r\n"; diff --git a/t/snippets12.t b/t/snippets12.t index 208720ef..5fd19bff 100644 --- a/t/snippets12.t +++ b/t/snippets12.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:23 2018 +# Sun Nov 11 06:54:12 2018 # To locate test #13 for example, search for the string '#13' diff --git a/t/snippets2.t b/t/snippets2.t index 643312bb..997f2a9d 100644 --- a/t/snippets2.t +++ b/t/snippets2.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:22 2018 +# Sun Nov 11 06:54:11 2018 # To locate test #13 for example, search for the string '#13' @@ -205,7 +205,7 @@ if ( VERSION < 5.009 && $op->name eq 'aassign' ) { params => "def", expect => <<'#2...........', # remove spaces around arrows -my $obj = Bio::Variation::AAChange->new; +my $obj = Bio::Variation::AAChange->new; my $termcap = Term::Cap->Tgetent( { TERM => undef } ); #2........... }, @@ -415,7 +415,7 @@ my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, ); expect => <<'#18...........', my $a = ${^WARNING_BITS}; @{^HOWDY_PARDNER} = ( 101, 102 ); -${^W} = 1; +${^W} = 1; $bb[$^]] = "bubba"; #18........... }, diff --git a/t/snippets3.t b/t/snippets3.t index 555521d2..4e97c6b5 100644 --- a/t/snippets3.t +++ b/t/snippets3.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:22 2018 +# Sun Nov 11 06:54:11 2018 # To locate test #13 for example, search for the string '#13' diff --git a/t/snippets4.t b/t/snippets4.t index f283a601..8ea71152 100644 --- a/t/snippets4.t +++ b/t/snippets4.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:22 2018 +# Sun Nov 11 06:54:11 2018 # To locate test #13 for example, search for the string '#13' diff --git a/t/snippets5.t b/t/snippets5.t index adfeb6b3..354194d9 100644 --- a/t/snippets5.t +++ b/t/snippets5.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:22 2018 +# Sun Nov 11 06:54:11 2018 # To locate test #13 for example, search for the string '#13' diff --git a/t/snippets6.t b/t/snippets6.t index bd517ad6..c581d4c9 100644 --- a/t/snippets6.t +++ b/t/snippets6.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:22 2018 +# Sun Nov 11 06:54:11 2018 # To locate test #13 for example, search for the string '#13' diff --git a/t/snippets7.t b/t/snippets7.t index 1be22359..52010595 100644 --- a/t/snippets7.t +++ b/t/snippets7.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:22 2018 +# Sun Nov 11 06:54:11 2018 # To locate test #13 for example, search for the string '#13' diff --git a/t/snippets8.t b/t/snippets8.t index 936bc771..d6ceae08 100644 --- a/t/snippets8.t +++ b/t/snippets8.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:23 2018 +# Sun Nov 11 06:54:11 2018 # To locate test #13 for example, search for the string '#13' diff --git a/t/snippets9.t b/t/snippets9.t index be0aeb6c..14f2d029 100644 --- a/t/snippets9.t +++ b/t/snippets9.t @@ -1,6 +1,6 @@ # **This script was automatically generated** # Created with: ./make_t.pl -# Sat Nov 10 08:48:23 2018 +# Sun Nov 11 06:54:11 2018 # To locate test #13 for example, search for the string '#13'