]> git.donarmstrong.com Git - perltidy.git/commitdiff
Add option -pvtc=3, requested in rt136416
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 4 May 2021 01:22:13 +0000 (18:22 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 4 May 2021 01:22:13 +0000 (18:22 -0700)
CHANGES.md
bin/perltidy
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod
t/snippets/expect/rt136417.def [new file with mode: 0644]
t/snippets/expect/rt136417.rt136417 [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets/rt136417.in [new file with mode: 0644]
t/snippets/rt136417.par [new file with mode: 0644]
t/snippets24.t

index 2b9503b2194121e376fdc36ef68e3df5b3e6f1cd..3f27fb653216800de75cbf544e5c24c7c17be6c7 100644 (file)
@@ -1,5 +1,13 @@
 # Perltidy Change Log
 
+## 2021 xx xx
+
+    - Added a new option for closing paren placement, -vtc=3, requested in rt #136417.
+
+    - A more complete list of updates is at
+
+           https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod
+
 ## 2021 04 02
 
     - This release fixes several non-critical bugs which have been found since the last
index 6b0eee2423a1f00266909992c88d299b02566d32..04ed1edcae6b640e71c8ea50e912fa4c17dc5a38 100755 (executable)
@@ -2696,9 +2696,11 @@ B<--vertical-tightness-closing=n>, where
         by a semicolon or another closing token, and is not in 
         a list environment.
  -vtc=2 never break before a closing token.
+ -vtc=3 Like -vtc=1 except always break before a closing token
+        if the corresponding opening token follows an = or =>.
 
-The rules for B<-vtc=1> are designed to maintain a reasonable balance
-between tightness and readability in complex lists.
+The rules for B<-vtc=1> and B<-vtc=3> are designed to maintain a reasonable
+balance between tightness and readability in complex lists.
 
 =item *
 
@@ -2739,6 +2741,24 @@ Here are some examples:
                        three => 'III',
                        four  => 'IV', );
 
+    # perltidy -vtc=3
+    my_function(
+        one   => 'I',
+        two   => 'II',
+        three => 'III',
+        four  => 'IV', );
+
+    # perltidy -vtc=3
+    %romanNumerals = (
+        one   => 'I',
+        two   => 'II',
+        three => 'III',
+        four  => 'IV',
+    );
+
+In the last example for B<-vtc=3>, the opening paren is preceded by an equals
+so the closing paren is placed on a new line.
+
 The difference between B<-vt=1> and B<-vt=2> is shown here:
 
     # perltidy -lp -vt=1 
index c1092bee9254b2268b2a7538047c8836d5c323b4..b888c0c57b19ca22d784fd560b500ebe2b2db868 100644 (file)
@@ -439,6 +439,7 @@ BEGIN {
         _rbreak_before_container_by_seqno_  => $i++,
         _ris_essential_old_breakpoint_      => $i++,
         _roverride_cab3_                    => $i++,
+        _ris_assigned_structure_            => $i++,
     };
 
     # Array index names for _this_batch_ (in above list)
@@ -798,6 +799,7 @@ sub new {
     $self->[_rbreak_before_container_by_seqno_] = {};
     $self->[_ris_essential_old_breakpoint_]     = {};
     $self->[_roverride_cab3_]                   = {};
+    $self->[_ris_assigned_structure_]           = {};
 
     # This flag will be updated later by a call to get_save_logfile()
     $self->[_save_logfile_] = defined($logger_object);
@@ -5038,6 +5040,7 @@ sub respace_tokens {
     my $rparent_of_seqno                 = {};
     my $rchildren_of_seqno               = {};
     my $roverride_cab3                   = {};
+    my $ris_assigned_structure           = {};
 
     my $last_nonblank_type       = ';';
     my $last_nonblank_token      = ';';
@@ -5663,6 +5666,14 @@ sub respace_tokens {
             if ($type_sequence) {
 
                 if ( $is_opening_token{$token} ) {
+
+                    if (   $last_nonblank_type eq '='
+                        || $last_nonblank_type eq '=>' )
+                    {
+                        $ris_assigned_structure->{$type_sequence} =
+                          $last_nonblank_type;
+                    }
+
                     my $seqno_parent = $seqno_stack{ $depth_next - 1 };
                     $seqno_parent = SEQ_ROOT unless defined($seqno_parent);
                     push @{ $rchildren_of_seqno->{$seqno_parent} },
@@ -6196,6 +6207,7 @@ sub respace_tokens {
     $self->[_rchildren_of_seqno_]        = $rchildren_of_seqno;
     $self->[_ris_list_by_seqno_]         = $ris_list_by_seqno;
     $self->[_roverride_cab3_]            = $roverride_cab3;
+    $self->[_ris_assigned_structure_]    = $ris_assigned_structure;
 
     # DEBUG OPTION: make sure the new array looks okay.
     # This is no longer needed but should be retained for future development.
@@ -21299,6 +21311,14 @@ sub set_vertical_tightness_flags {
         {
             my $ovt = $opening_vertical_tightness{$token_next};
             my $cvt = $closing_vertical_tightness{$token_next};
+
+            # Implement cvt=3: like cvt=0 for assigned structures, like cvt=1
+            # otherwise.  Added for rt136417.
+            if ( $cvt == 3 ) {
+                my $seqno = $type_sequence_to_go[$ibeg_next];
+                $cvt = $self->[_ris_assigned_structure_]->{$seqno} ? 0 : 1;
+            }
+
             if (
 
                 # Never append a trailing line like   ')->pack(' because it
index e5344c0c24144f61c0272426ab5d913ef6900a34..65345e92623e45e4eacaafc3102257e38db8e8f3 100644 (file)
@@ -2,6 +2,14 @@
 
 =over 4
 
+=item B<Add option -pvtc=3, requested in rt136416>
+
+A new integer option, n=3, has been added to the vertical tightness closing flags.
+For a container with n=3, the closing token will behave as for n=0 if the opening
+token is preceded by an '=' or '=>', and like n=1 otherwise.
+
+3 May 2021.
+
 =item B<Fix vertical alignment issue in rt136416>
 
 This update fixes a problem with unwanted vertical alignment rasied in
diff --git a/t/snippets/expect/rt136417.def b/t/snippets/expect/rt136417.def
new file mode 100644 (file)
index 0000000..5417670
--- /dev/null
@@ -0,0 +1,9 @@
+function(
+    #
+    a, b, c
+);
+
+%hash = (
+    a => b,
+    c => d,
+);
diff --git a/t/snippets/expect/rt136417.rt136417 b/t/snippets/expect/rt136417.rt136417
new file mode 100644 (file)
index 0000000..1977d74
--- /dev/null
@@ -0,0 +1,8 @@
+function(
+    #
+    a, b, c );
+
+%hash = (
+    a => b,
+    c => d,
+);
index fdb8571fc92d58467778af65d60f0e9e46583469..2ff9249d6899e232a3c569cbd8d9fadf53f44c98 100644 (file)
 ../snippets24.t        lpxl.lpxl4
 ../snippets24.t        lpxl.lpxl5
 ../snippets24.t        git63.def
+../snippets24.t        align35.def
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets24.t        align35.def
+../snippets24.t        rt136417.def
+../snippets24.t        rt136417.rt136417
diff --git a/t/snippets/rt136417.in b/t/snippets/rt136417.in
new file mode 100644 (file)
index 0000000..3f21a97
--- /dev/null
@@ -0,0 +1,8 @@
+function(
+  #
+  a, b, c);
+
+%hash = (
+  a => b,
+  c => d,
+);
diff --git a/t/snippets/rt136417.par b/t/snippets/rt136417.par
new file mode 100644 (file)
index 0000000..d4d577a
--- /dev/null
@@ -0,0 +1 @@
+-vtc=3
index 7b944a7942ed60fee76689737a219ccd1e8c2565..f171b4bd7fc2a73f61cf4611dc75e53acd37091a 100644 (file)
@@ -13,6 +13,8 @@
 #10 lpxl.lpxl5
 #11 git63.def
 #12 align35.def
+#13 rt136417.def
+#14 rt136417.rt136417
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -44,6 +46,7 @@ BEGIN {
         'lpxl5' => <<'----------',
 -lp -lpxl='{ [ F(2'
 ----------
+        'rt136417' => "-vtc=3",
     };
 
     ############################
@@ -202,6 +205,17 @@ $behaviour = {
               dog   => {prowl  => "growl", pool => "drool"},
               mouse => {nibble => "kibble"},
              };
+----------
+
+        'rt136417' => <<'----------',
+function(
+  #
+  a, b, c);
+
+%hash = (
+  a => b,
+  c => d,
+);
 ----------
     };
 
@@ -731,6 +745,37 @@ use constant COUNTUP   => reverse 1, 2, 3, 4, 5;
 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
 #12...........
         },
+
+        'rt136417.def' => {
+            source => "rt136417",
+            params => "def",
+            expect => <<'#13...........',
+function(
+    #
+    a, b, c
+);
+
+%hash = (
+    a => b,
+    c => d,
+);
+#13...........
+        },
+
+        'rt136417.rt136417' => {
+            source => "rt136417",
+            params => "rt136417",
+            expect => <<'#14...........',
+function(
+    #
+    a, b, c );
+
+%hash = (
+    a => b,
+    c => d,
+);
+#14...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};