From cdbf0e4266204eef362cac34eae5c89f4bfca9d1 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 26 Dec 2020 18:42:39 -0800 Subject: [PATCH] improve coding for qw lists with -lp style --- lib/Perl/Tidy/Formatter.pm | 21 +++++++++++++-------- local-docs/BugLog.pod | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index cef96c98..404720a0 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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) { diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index fc61c99a..acfd3fe6 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,35 @@ =over 4 +=item B + +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 This update adds a sequence numbering system for multiline qw quotes. In the -- 2.39.5