From 7ba2eeb4ab6e1218f2a6171a55df76ef99bbc192 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 16 Oct 2019 06:53:17 -0700 Subject: [PATCH] improved vertical alignment for multiple equals --- CHANGES.md | 2 +- lib/Perl/Tidy/Formatter.pm | 18 ++++++++++++++++++ t/snippets/expect/multiple_equals.def | 8 ++++++++ t/snippets/multiple_equals.in | 8 ++++++++ t/snippets/packing_list.txt | 1 + t/snippets16.t | 27 +++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 t/snippets/expect/multiple_equals.def create mode 100644 t/snippets/multiple_equals.in diff --git a/CHANGES.md b/CHANGES.md index ed17d7c6..cb871ddf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 562bab4b..6378c808 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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 index 00000000..4a7be469 --- /dev/null +++ b/t/snippets/expect/multiple_equals.def @@ -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 index 00000000..4a7be469 --- /dev/null +++ b/t/snippets/multiple_equals.in @@ -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/packing_list.txt b/t/snippets/packing_list.txt index 5076cc6d..c22888c0 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -301,3 +301,4 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def +../snippets16.t multiple_equals.def diff --git a/t/snippets16.t b/t/snippets16.t index 3ad65a8d..27cbd5eb 100644 --- a/t/snippets16.t +++ b/t/snippets16.t @@ -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}; -- 2.39.5