From: Steve Hancock Date: Fri, 7 May 2021 13:16:28 +0000 (-0700) Subject: Improve indentation of welded multiline qw quotes X-Git-Tag: 20210402.01~50 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=176f8a7495ca61407bdda951fe72e71e336590f5;p=perltidy.git Improve indentation of welded multiline qw quotes --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index bb76acb6..72dfe21e 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index b11fdd3d..38015dfd 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,13 +2,66 @@ =over 4 +=item B + +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 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