]> git.donarmstrong.com Git - perltidy.git/commitdiff
Improve indentation of welded multiline qw quotes
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 7 May 2021 13:16:28 +0000 (06:16 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 7 May 2021 13:16:28 +0000 (06:16 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index bb76acb629fbd1a1621c3d1cd721306c2fdc9abb..72dfe21e6e3c5321306f20600e89344ad9873b13 100644 (file)
@@ -8120,8 +8120,13 @@ sub weld_nested_quotes {
             # Change the level of a closing qw token to be that of the outer
             # containing token. This will allow -lp indentation to function
             # correctly in the vertical aligner.
-            $rLL->[$Kinner_closing]->[_LEVEL_] =
-              $rLL->[$Kouter_closing]->[_LEVEL_];
+            # Patch to fix c002: but not if it contains text and is not -lp.
+            if ( $rOpts_line_up_parentheses
+                || length( $rLL->[$Kinner_closing]->[_TOKEN_] ) == 1 )
+            {
+                $rLL->[$Kinner_closing]->[_LEVEL_] =
+                  $rLL->[$Kouter_closing]->[_LEVEL_];
+            }
         }
     }
     return;
index b11fdd3df3824fc4ff30b7f101c0fe4c53801fcd..38015dfd7fac12ae8a44130c90bc7ea08a4f1132 100644 (file)
@@ -2,13 +2,66 @@
 
 =over 4
 
+=item B<Improve indentation of welded multiline qw quotes>
+
+Formatting of multiline qw lists with welding works best if the
+opening and closing qw tokens are on separate lines, like this:
+
+    # perltidy -wn
+    my $mon_name = ( qw(
+        January February March April
+        May June July August
+        September October November December
+    ) )[$mon];
+
+    # perltidy -wn -lp
+    my $mon_name = ( qw(
+                     January February March April
+                     May June July August
+                     September October November December
+    ) )[$mon];
+
+Otherwise formatting can be poor, particularly if the last line
+has text and a closing container.
+
+    # OLD: perltidy -wn
+    my $mon_name = ( qw(January February March April
+        May June July August
+    September October November December) )[$mon];
+
+Note that perltidy does not change the line breaks within multiline quotes, so
+they must be changed by hand if desired.
+
+This update indents the last line of a multiline quote which contains both
+text and the closing token, such as:
+
+    # NEW: perltidy -wn
+    my $mon_name = ( qw(January February March April
+        May June July August
+        September October November December) )[$mon];
+
+This update is only when the -lp flag is not used.   If -lp is used and the
+last line contains text, the last line is still outdented:
+
+    $ OLD and NEW: perltidy -wn -lp
+    my $mon_name = ( qw(January February March April
+                     May June July August
+    September October November December) )[$mon];
+
+This is difficult to fix.  The best solution is to place the closing qw qw
+containers on a separate line.
+
+This fix is for case c002.
+
+6 May 2021.
+
 =item B<Test length of closing multiline qw quote before welding>
 
 Random testing produced an unstable state which was due to not checking for
 excessive length of the last line of a multiline qw quote.  A check was added,
 this fixes issue b1039.
 
-5 May 2021.
+5 May 2021, b72ad24.
 
 =item B<Update welding rule to avoid blinking states>