]> git.donarmstrong.com Git - perltidy.git/commitdiff
improve coding for qw lists with -lp style
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 27 Dec 2020 02:42:39 +0000 (18:42 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 27 Dec 2020 02:42:39 +0000 (18:42 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index cef96c98f966c40f4228752864085fdf69f6ac33..404720a05ee0b63baf3318dfde89b946456d9c5f 100644 (file)
@@ -7795,17 +7795,22 @@ EOM
             my $parent_seqno = $self->parent_seqno_by_K($Kend);
             next unless ($parent_seqno);
 
-            # If the first outer container exactly surrounds this qw, then -lp
+            # If the parent container exactly surrounds this qw, then -lp
             # formatting seems to work so we will not mark it.
-            my $Kp      = $self->K_previous_nonblank($Kbeg) if defined($Kbeg);
-            my $Kn      = $self->K_next_nonblank($Kend)     if defined($Kend);
-            my $seqno_p = defined($Kp) ? $rLL->[$Kp]->[_TYPE_SEQUENCE_] : undef;
+            my $is_tightly_contained;
+            my $Kn      = $self->K_next_nonblank($Kend);
             my $seqno_n = defined($Kn) ? $rLL->[$Kn]->[_TYPE_SEQUENCE_] : undef;
-            my $is_tightly_contained =
-              defined($seqno_p) && defined($seqno_n) && $seqno_p eq $seqno_n;
+            if ( defined($seqno_n) && $seqno_n eq $parent_seqno ) {
 
-            $rcontains_multiline_qw_by_seqno->{$parent_seqno} =
-              !$is_tightly_contained;
+                my $Kp = $self->K_previous_nonblank($Kbeg);
+                my $seqno_p =
+                  defined($Kp) ? $rLL->[$Kp]->[_TYPE_SEQUENCE_] : undef;
+                if ( defined($seqno_p) && $seqno_p eq $parent_seqno ) {
+                    $is_tightly_contained = 1;
+                }
+            }
+            $rcontains_multiline_qw_by_seqno->{$parent_seqno} = 1
+              unless ($is_tightly_contained);
 
             # continue up the tree marking parent containers
             while (1) {
index fc61c99ad9224c6a4ef9a0c93ee4fdd87f52dfd2..acfd3fe61fd5ce197bfc01a8af508cee9b483668 100644 (file)
@@ -2,6 +2,35 @@
 
 =over 4
 
+=item B<Avoid -lp style formatting of lists containing multiline qw quotes>
+
+The -lp formatting style often does not work well when lists contain multiline qw
+quotes.  This update avoids this problem by not formatting such lists with the
+-lp style.  For example,
+
+    # OLD, perltidy -gnu
+    @EXPORT = (
+        qw(
+          i Re Im rho theta arg
+          sqrt log ln
+          log10 logn cbrt root
+          cplx cplxe
+          ),
+        @trig,
+              ); 
+
+
+    # NEW, perltidy -gnu
+    @EXPORT = (
+        qw(
+          i Re Im rho theta arg
+          sqrt log ln
+          log10 logn cbrt root
+          cplx cplxe
+        ),
+        @trig,
+    );
+
 =item B<improve formatting of multiline qw>
 
 This update adds a sequence numbering system for multiline qw quotes.  In the