From 5d7ae339785bad370b63f07e0aca2419dba87e64 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 17 Nov 2021 05:39:30 -0800 Subject: [PATCH] update sub set_vertical_tightness_flags for new -lp model --- lib/Perl/Tidy/Formatter.pm | 11 +++++++---- t/snippets/expect/lpxl.lpxl3 | 3 ++- t/snippets/expect/lpxl.lpxl5 | 3 ++- t/snippets24.t | 6 ++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 374dbd90..708a45ee 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -23762,6 +23762,8 @@ sub set_vertical_tightness_flags { my $rwant_container_open = $self->[_rwant_container_open_]; my $rK_weld_left = $self->[_rK_weld_left_]; + my $is_lp_formatting = ref( $leading_spaces_to_go[$ibeg] ); + # Uses these global parameters: # $rOpts_block_brace_tightness # $rOpts_block_brace_vertical_tightness @@ -23787,6 +23789,7 @@ sub set_vertical_tightness_flags { my $ibeg_next = $ri_first->[ $n + 1 ]; my $token_end = $tokens_to_go[$iend]; my $iend_next = $ri_last->[ $n + 1 ]; + $is_lp_formatting ||= ref( $leading_spaces_to_go[$ibeg_next] ); if ( $type_sequence_to_go[$iend] && !$block_type_to_go[$iend] @@ -23795,7 +23798,7 @@ sub set_vertical_tightness_flags { $opening_vertical_tightness{$token_end} > 0 # allow 2-line method call to be closed up - || ( $rOpts_line_up_parentheses + || ( $is_lp_formatting && $token_end eq '(' && $iend > $ibeg && $types_to_go[ $iend - 1 ] ne 'b' ) @@ -23872,7 +23875,7 @@ sub set_vertical_tightness_flags { $cvt == 1 # allow closing up 2-line method calls - || ( $rOpts_line_up_parentheses + || ( $is_lp_formatting && $token_next eq ')' ) ) ) @@ -23906,7 +23909,7 @@ sub set_vertical_tightness_flags { # flag off and set the maximum to 0. This is equivalent to # using a large number. my $seqno_ibeg_next = $type_sequence_to_go[$ibeg_next]; - if ( $rOpts_line_up_parentheses + if ( $is_lp_formatting && $total_weld_count && $self->is_welded_at_seqno($seqno_ibeg_next) ) { @@ -23964,7 +23967,7 @@ sub set_vertical_tightness_flags { && $token_end ne '||' && $token_end ne '&&' # Keep break after '=' if -lp. Fixes b964 b1040 b1062 b1083 b1089. - && !( $token_end eq '=' && $rOpts_line_up_parentheses ) + && !( $token_end eq '=' && $is_lp_formatting ) # looks bad if we align vertically with the wrong container && $tokens_to_go[$ibeg] ne $tokens_to_go[$ibeg_next] diff --git a/t/snippets/expect/lpxl.lpxl3 b/t/snippets/expect/lpxl.lpxl3 index fef22cae..0bfd5569 100644 --- a/t/snippets/expect/lpxl.lpxl3 +++ b/t/snippets/expect/lpxl.lpxl3 @@ -24,7 +24,8 @@ debug( # simple function call with code block $m->command( -label => 'Save', - -command => sub { print "DOS\n"; save_dialog($win); } ); + -command => sub { print "DOS\n"; save_dialog($win); } +); # function call, ternary in list return OptArgs2::Result->usage( diff --git a/t/snippets/expect/lpxl.lpxl5 b/t/snippets/expect/lpxl.lpxl5 index e1cb9f91..de0dfa6a 100644 --- a/t/snippets/expect/lpxl.lpxl5 +++ b/t/snippets/expect/lpxl.lpxl5 @@ -24,7 +24,8 @@ debug( # simple function call with code block $m->command( -label => 'Save', - -command => sub { print "DOS\n"; save_dialog($win); } ); + -command => sub { print "DOS\n"; save_dialog($win); } +); # function call, ternary in list return OptArgs2::Result->usage( diff --git a/t/snippets24.t b/t/snippets24.t index 7af02e65..3a783c55 100644 --- a/t/snippets24.t +++ b/t/snippets24.t @@ -637,7 +637,8 @@ debug( # simple function call with code block $m->command( -label => 'Save', - -command => sub { print "DOS\n"; save_dialog($win); } ); + -command => sub { print "DOS\n"; save_dialog($win); } +); # function call, ternary in list return OptArgs2::Result->usage( @@ -771,7 +772,8 @@ debug( # simple function call with code block $m->command( -label => 'Save', - -command => sub { print "DOS\n"; save_dialog($win); } ); + -command => sub { print "DOS\n"; save_dialog($win); } +); # function call, ternary in list return OptArgs2::Result->usage( -- 2.39.5