From 057b333d41276a1ad6d8d9a14c1158cad36c4f21 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 6 Nov 2024 14:42:42 -0800 Subject: [PATCH] make space controls work better around here targets --- CHANGES.md | 9 +++++++++ dev-bin/run_convergence_tests.pl.expect | 4 ++-- lib/Perl/Tidy/Formatter.pm | 23 +++++++++-------------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d32e7cf0..f0ac1b67 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,15 @@ ## 2024 09 03.06 + - Space around here doc delimiters follow spacing controls better. For + example, a space is now added before the closing paren here: + + OLD: (without the here doc): + push( @script, <<'EOT'); + + NEW: + push( @script, <<'EOT' ); + - Added parameter --break-at-trailing-comma-types=s, or -btct=s, where s is a string which selects trailing commas. For example, -btct='f(b' places a line break after all bare trailing commas in function calls. diff --git a/dev-bin/run_convergence_tests.pl.expect b/dev-bin/run_convergence_tests.pl.expect index 69a73323..940c2a96 100644 --- a/dev-bin/run_convergence_tests.pl.expect +++ b/dev-bin/run_convergence_tests.pl.expect @@ -9617,13 +9617,13 @@ my ( ==> b523 <== foreach my $name (@$names) - { unless ($callcopy) { $ret .= << "EOC"} + { unless ($callcopy) { $ret .= << "EOC" } XX EOC } foreach my $name (@$names) - { unless ($callcopy) { $ret .= << "EOC"} + { unless ($callcopy) { $ret .= << "EOC" } XX EOC } diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index a3b41553..51349ad7 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -4581,16 +4581,11 @@ sub set_whitespace_flags { } # always preserve whatever space was used after a possible - # filehandle (except _) or here doc operator - if ( - ( - ( $last_type eq 'Z' && $last_token ne '_' ) - || $last_type eq 'h' - ) - && $type ne '#' # no longer required due to early exit for '#' above - ) - { + # filehandle (except _) + if ( $last_type eq 'Z' && $last_token ne '_' ) { + # no space for '$ {' even if '$' is marked as type 'Z', issue c221 + # note: redundant check on type 'h' here removed for c419 part 2b if ( $last_type eq 'Z' && $last_token eq '$' && $token eq '{' ) { $ws = WS_NO; } @@ -5123,8 +5118,8 @@ EOM # It can cause a syntax error if oops is a sub || $typel eq 'w' && ( $tokenr eq '-' || $typer eq 'Q' ) - # perl is very fussy about spaces before << - || $tokenr_leading_ch2 eq '<<' + # perl is very fussy about spaces before <<; c419 part 1 + || $tokenr_leading_ch2 eq '<<' && $typel ne '{' && $typel ne ',' # avoid combining tokens to create new meanings. Example: # $a+ +$b must not become $a++$b @@ -5169,8 +5164,9 @@ EOM ) ) ## end $tokenr_is_open_paren - # retain any space after here doc operator ( hereerr.t) - || $typel eq 'h' + # retain any space after here doc operator ( see hereerr.t) + # c419, part 2a: unless followed by '}' or ','. See also part 2b. + || $typel eq 'h' && $typer ne '}' && $typer ne ',' # Be careful with a space around ++ and --, to avoid ambiguity as to # which token it applies @@ -32310,7 +32306,6 @@ EOM } ## end sub break_lists_decreasing_depth } ## end closure break_lists - my %is_kwiZ; my %is_key_type; -- 2.39.5