From: Steve Hancock Date: Sun, 24 Jan 2021 18:56:41 +0000 (-0800) Subject: Fix git #51, closing qw paren not outdented if -ndnl is set X-Git-Tag: 20210402~73 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=52996fb6b4deebb340bdb35addedc5d70c005210;p=perltidy.git Fix git #51, closing qw paren not outdented if -ndnl is set --- diff --git a/CHANGES.md b/CHANGES.md index 91a09074..8e7669f7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,9 @@ ## 2021 01 xx + - Fixed issue git #51, a closing qw bare paren was not being outdented when + the -nodelete-old-newlines flag was set. + - Fixed a rare problem with -lp formatting which could cause alternating output states. Except for some very deeply nested data structures, most scripts formatted with this option will not be changed. diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 6ef5b969..5a51768b 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -17181,6 +17181,15 @@ sub send_lines_to_vertical_aligner { $type_end_next = $rLL->[$Kend_next]->[_TYPE_]; $ljump = $rLL->[$Kbeg_next]->[_LEVEL_] - $rLL->[$Kend]->[_LEVEL_]; } + else { + + # Patch for git #51, a bare closing qw paren was not outdented + # if the flag '-nodelete-old-newlines is set + my $Kbeg_next = $self->K_next_code($Kend); + if ( defined($Kbeg_next) ) { + $ljump = $rLL->[$Kbeg_next]->[_LEVEL_] - $rLL->[$Kend]->[_LEVEL_]; + } + } # level jump at end of line for the vertical aligner: my $level_jump = @@ -19138,6 +19147,11 @@ sub make_paren_name { || ( $i_terminal > $ibeg && $is_closing_type{ $types_to_go[$iend] } ) + # Alternate Patch for git #51, isolated closing qw token not + # outdented if no-delete-old-newlines is set. This works, but + # a more general patch elsewhere fixes the real problem: ljump. + # || ( $seqno_qw_closing && $ibeg == $i_terminal ) + ) { $adjust_indentation = 1; diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 055c539d..72a60a8f 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,44 @@ =over 4 +=item B + +The problem is that a bare closing qw paren was not being outdented +if the flag '-nodelete-old-newlines is set. For example + + # OLD (OK, outdented): perltidy -ci=4 -xci + { + modules => [ + qw( + JSON + ) + ], + } + + + # OLD (indented) : perltidy -ndnl -ci=4 -xci + { + modules => [ + qw( + JSON + ) + ], + } + + # FIXED: perltidy -ndnl -ci=4 -xci + { + modules => [ + qw( + JSON + ) + ], + } + +The problem happened because the -ndnl flag forces each line to be written +immediately, so the next line (which needs to be checked in this case) was not +available when the outdent decision had to be made. A patch to work around +this was added 24 Jan 2021. + =item B Random testing revealed some problems involving the B<-lp> option which are