]> git.donarmstrong.com Git - perltidy.git/commitdiff
Vertical alignment improvements for =~ and //
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 11 Nov 2018 14:54:52 +0000 (06:54 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 11 Nov 2018 14:54:52 +0000 (06:54 -0800)
18 files changed:
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/VerticalAligner.pm
local-docs/ChangeLog.pod
t/snippets/expect/arrows1.def
t/snippets/expect/carat.def
t/snippets/expect/tutor.def
t/snippets1.t
t/snippets10.t
t/snippets11.t
t/snippets12.t
t/snippets2.t
t/snippets3.t
t/snippets4.t
t/snippets5.t
t/snippets6.t
t/snippets7.t
t/snippets8.t
t/snippets9.t

index 4ab86b9b511fea4f39c69214d9cb8a318f2b8da0..5788ca636109d3b95dd0a463b6896feb4cfa0c43 100644 (file)
@@ -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;
index a6fc4d0a0b85693bfad6e877e3370bd68a2daff5..5a823bb85dcf816447944854e65567553b17d660 100644 (file)
@@ -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 )
           )
     );
 
index ea2cad33931b7eb00c41628edc79f1f023fe6601..16cb654cb5360def1739168476eb38ecb862bc69 100644 (file)
@@ -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;
     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
 
index d8759a3890dee235e28df9ba8320039e6167801b..e3a8b0510fe21fe9bb63b30cbe1785f0e5480f89 100644 (file)
@@ -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 } );
index 285c4da8b5e3d817bf2a1e11621f3f11aa65e237..9d02df1e1292fd2aeba39b86a9ced75fe3b7634f 100644 (file)
@@ -1,4 +1,4 @@
 my $a = ${^WARNING_BITS};
 @{^HOWDY_PARDNER} = ( 101, 102 );
-${^W} = 1;
+${^W}             = 1;
 $bb[$^]] = "bubba";
index e875b6ab789d346d542e796f30d39aa73257cfa9..55b6e2dc2d2f4dbba4fbaea32816a0aff9a133b9 100644 (file)
@@ -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";
index 21403836bfdf6a7d4c3db984edfb35d85e83a581..e7c91e2eb15538852e6e6bbf799e2f561880577b 100644 (file)
@@ -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'
 
index 86cca9d24cd0d7e2291a45517d9acddbdec39a71..e89f19cdcba1674d5e5a9e2845a1ce6607f7b184 100644 (file)
@@ -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'
 
index 7ecf70d899bc9f75f8d90baa361edd876fc8e6d4..0ddbe0344c933e4640efb0c304dea7f208b27cff 100644 (file)
@@ -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";
index 208720ef4e1461d0c6a1de743ef01cee2a4e717b..5fd19bfff02376f057ca869de90380ccb867f8ee 100644 (file)
@@ -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'
 
index 643312bb5d0b91ad5fafb20cd02ff0f6b95bb804..997f2a9d864c029316c1c68e65698dd6d946fb2d 100644 (file)
@@ -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...........
         },
index 555521d2feb706331bc4b9a5f0d81c510c4bc293..4e97c6b56d5fe67f9dd88efc69730962c3c53061 100644 (file)
@@ -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'
 
index f283a601ddf38e66c5d2b1dbc55327304c05e9f2..8ea7115251f01b09d376588ea25d92fd427df8e1 100644 (file)
@@ -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'
 
index adfeb6b3101f50f0e3e47d775fd9119e8ffab26d..354194d9b65fa8434a60da4e40152ab85dbacab4 100644 (file)
@@ -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'
 
index bd517ad6da398215df0f799139bc3cb4fc82d48c..c581d4c92c445dde79926d9c2f62fd2d19713a99 100644 (file)
@@ -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'
 
index 1be22359a08fa17a68c6adb911e7a3d82c8bd42c..520105953498b5bd037fec3df8f34c3462ffc7aa 100644 (file)
@@ -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'
 
index 936bc771119e777c3e49e99343e1638c61f14770..d6ceae08e005646edff195f868cc57c1ee8b0e18 100644 (file)
@@ -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'
 
index be0aeb6c151120088d2e8677f4346b332854876c..14f2d029715ba7a9eb56ccf8a257e942deed1570 100644 (file)
@@ -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'