]> git.donarmstrong.com Git - perltidy.git/commitdiff
improved vertical alignment for multiple equals
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 16 Oct 2019 13:53:17 +0000 (06:53 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 16 Oct 2019 13:53:17 +0000 (06:53 -0700)
CHANGES.md
lib/Perl/Tidy/Formatter.pm
t/snippets/expect/multiple_equals.def [new file with mode: 0644]
t/snippets/multiple_equals.in [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets16.t

index ed17d7c6c4238e64b0aa9427ea0c58db59f13e4b..cb871ddf34e6fc9bce48137202e5187de9d05ba8 100644 (file)
@@ -9,7 +9,7 @@
 
         perltidy -sal='method fun' 
 
-      will cause the perltidy to treate the words 'method' and 'fun' to be
+      will cause the perltidy to treat the words 'method' and 'fun' to be
       treated the same as if they were 'sub'.
 
     - Added flag --space-prototype-paren=i, or -spp=i, to control spacing 
index 562bab4b20f4023ef06529fc936ee524cf32c57d..6378c808575324e0e1bd99c437942885caf604f2 100644 (file)
@@ -10127,6 +10127,7 @@ sub send_lines_to_vertical_aligner {
         my $j = 0;    # field index
 
         $patterns[0] = "";
+       my %token_count; 
         for my $i ( $ibeg .. $iend ) {
 
             # Keep track of containers balanced on this line only.
@@ -10278,6 +10279,23 @@ sub send_lines_to_vertical_aligner {
                     $tok .= $block_type;
                 }
 
+               # Mark multiple copies of certain tokens with the copy number
+               # This will allow the aligner to decide if they are matched.
+               # For now, only do this for equals. For example, the two
+               # equals on the next line will be labeled '=0' and '=0.2'.
+               # Later, the '=0.2' will be ignored in alignment because it
+               # has no match.
+
+               # $|          = $debug = 1 if $opt_d;
+               # $full_index = 1          if $opt_i;
+               
+                if ( $raw_tok eq '=' ) {
+                    $token_count{$tok}++;
+                    if ( $token_count{$tok} > 1 ) {
+                        $tok .= '.' . $token_count{$tok};
+                    }
+                }
+
                 # concatenate the text of the consecutive tokens to form
                 # the field
                 push( @fields,
diff --git a/t/snippets/expect/multiple_equals.def b/t/snippets/expect/multiple_equals.def
new file mode 100644 (file)
index 0000000..4a7be46
--- /dev/null
@@ -0,0 +1,8 @@
+# ignore second '=' here
+$|          = $debug = 1 if $opt_d;
+$full_index = 1          if $opt_i;
+$query_all  = $opt_A     if $opt_A;
+
+# align multiple '='s here
+$start   = $end     = $len = $ismut = $number = $allele_ori = $allele_mut =
+  $proof = $xxxxreg = $reg = $dist  = '';
diff --git a/t/snippets/multiple_equals.in b/t/snippets/multiple_equals.in
new file mode 100644 (file)
index 0000000..4a7be46
--- /dev/null
@@ -0,0 +1,8 @@
+# ignore second '=' here
+$|          = $debug = 1 if $opt_d;
+$full_index = 1          if $opt_i;
+$query_all  = $opt_A     if $opt_A;
+
+# align multiple '='s here
+$start   = $end     = $len = $ismut = $number = $allele_ori = $allele_mut =
+  $proof = $xxxxreg = $reg = $dist  = '';
index 5076cc6d06d9c85fb57ff8c7aa8d460270252a9f..c22888c08156e7b4a2986feffc54217e227006bf 100644 (file)
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
+../snippets16.t        multiple_equals.def
index 3ad65a8d0c482a913b0ccf1b23a338791a1bacca..27cbd5eb2f6cf9910653ef02bc6cd9ef52a1e074 100644 (file)
@@ -6,6 +6,7 @@
 #3 git16.def
 #4 git10.def
 #5 git10.git10
+#6 multiple_equals.def
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -51,6 +52,17 @@ my $Package = $Self->RepositoryGet( %Param, Result => 'SCALAR' );
 my %Structure = $Self->PackageParse( String => $Package );
 ----------
 
+        'multiple_equals' => <<'----------',
+# ignore second '=' here
+$|          = $debug = 1 if $opt_d;
+$full_index = 1          if $opt_i;
+$query_all  = $opt_A     if $opt_A;
+
+# align multiple '='s here
+$start   = $end     = $len = $ismut = $number = $allele_ori = $allele_mut =
+  $proof = $xxxxreg = $reg = $dist  = '';
+----------
+
         'spp' => <<'----------',
 sub get_val() { }
 
@@ -125,6 +137,21 @@ my %Structure = $Self->PackageParse( String => $Package );
 } @unsorted;
 #5...........
         },
+
+        'multiple_equals.def' => {
+            source => "multiple_equals",
+            params => "def",
+            expect => <<'#6...........',
+# ignore second '=' here
+$|          = $debug = 1 if $opt_d;
+$full_index = 1          if $opt_i;
+$query_all  = $opt_A     if $opt_A;
+
+# align multiple '='s here
+$start   = $end     = $len = $ismut = $number = $allele_ori = $allele_mut =
+  $proof = $xxxxreg = $reg = $dist  = '';
+#6...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};