## 2022 06 13.03
+ - Fix issue git #106. This fixes some edge cases of formatting with the
+ combination -xlp -pt=2, mainly for two-line lists with short function
+ names. One indentation space is removed to improve alignment:
+
+ # OLD: perltidy -xlp -pt=2
+ is($module->VERSION, $expected,
+ "$main_module->VERSION matches $module->VERSION ($expected)");
+
+ # NEW: perltidy -xlp -pt=2
+ is($module->VERSION, $expected,
+ "$main_module->VERSION matches $module->VERSION ($expected)");
+
- Fix for issue git #105, incorrect formatting with 5.36 experimental
for_list feature.
# it becomes clear that we do not have a good list.
my $available_spaces = 0;
my $align_seqno = 0;
+ my $K_extra_space;
my $last_nonblank_seqno;
my $last_nonblank_block_type;
}
elsif ( $available_spaces > 1 ) {
$min_gnu_indentation += $available_spaces + 1;
+
+ # The "+1" space can cause mis-alignment if there is no
+ # blank space between the opening paren and the next
+ # nonblank token (i.e., -pt=2) and the container does not
+ # get broken open. So we will mark this token for later
+ # space removal by sub 'xlp_tweak' if this container
+ # remains intact (issue git #106).
+ if (
+ $type ne 'b'
+
+ # Skip if the maximum line length is exceeded here
+ && $excess <= 0
+
+ # This is only for level changes, not ci level changes.
+ # But note: this test is here out of caution but I have
+ # not found a case where it is actually necessary.
+ && $is_opening_token{$last_nonblank_token}
+
+ # Be sure we are at consecutive nonblanks. This test
+ # should be true, but it guards against future coding
+ # changes to level values assigned to blank spaces.
+ && $ii > 0
+ && $types_to_go[ $ii - 1 ] ne 'b'
+
+ )
+ {
+ $K_extra_space = $K_to_go[$ii];
+ }
}
- ##elsif ( $last_nonblank_token =~ /^[\{\[\(]$/ ) {
elsif ( $is_opening_token{$last_nonblank_token} ) {
if ( ( $tightness{$last_nonblank_token} < 2 ) ) {
$min_gnu_indentation += 2;
stack_depth => $max_lp_stack,
K_begin_line => $K_begin_line,
standard_spaces => $standard_spaces,
+ K_extra_space => $K_extra_space,
);
DEBUG_LP && do {
$starting_in_quote )
if ( $n_last_line > 0 && $rOpts_logical_padding );
+ $self->xlp_tweak( $ri_first, $ri_last )
+ if ( $rOpts_extended_line_up_parentheses && $n_last_line > 0 );
+
if (DEVEL_MODE) { $self->check_batch_summed_lengths() }
# ----------------------------------------------------------
return;
} ## end sub pad_token
+sub xlp_tweak {
+
+ # Remove one indentation space from unbroken containers marked with
+ # 'K_extra_space'. These are mostly two-line lists with short names
+ # formatted with -xlp -pt=2.
+ #
+ # Before this fix (extra space in line 2):
+ # is($module->VERSION, $expected,
+ # "$main_module->VERSION matches $module->VERSION ($expected)");
+ #
+ # After this fix:
+ # is($module->VERSION, $expected,
+ # "$main_module->VERSION matches $module->VERSION ($expected)");
+ #
+ # Notes:
+ # - This fixes issue git #106
+ # - This must be called after 'set_logical_padding'.
+ # - This is currently only applied to -xlp. It would also work for -lp
+ # but that style is essentially frozen.
+
+ my ( $self, $ri_first, $ri_last ) = @_;
+
+ # Must be 2 or more lines
+ return unless ( @{$ri_first} > 1 );
+
+ # Pull indentation object from start of second line
+ my $ibeg_1 = $ri_first->[1];
+ my $lp_object = $leading_spaces_to_go[$ibeg_1];
+ return if ( !ref($lp_object) );
+
+ # This only applies to an indentation object with a marked token
+ my $K_extra_space = $lp_object->get_K_extra_space();
+ return unless ($K_extra_space);
+
+ # Look for the marked token within the first line of this batch
+ my $ibeg_0 = $ri_first->[0];
+ my $iend_0 = $ri_last->[0];
+ my $ii = $ibeg_0 + $K_extra_space - $K_to_go[$ibeg_0];
+ return if ( $ii <= $ibeg_0 || $ii > $iend_0 );
+
+ # Skip padded tokens, they have already been aligned
+ my $tok = $tokens_to_go[$ii];
+ return if ( substr( $tok, 0, 1 ) eq SPACE );
+
+ # Skip 'if'-like statements, this does not improve them
+ return
+ if ( $types_to_go[$ibeg_0] eq 'k'
+ && $is_if_unless_elsif{ $tokens_to_go[$ibeg_0] } );
+
+ # Looks okay, reduce indentation by 1 space if possible
+ my $spaces = $lp_object->get_spaces();
+ if ( $spaces > 0 ) {
+ $lp_object->decrease_SPACES(1);
+ }
+
+ return;
+}
+
{ ## begin closure make_alignment_patterns
my %keyword_map;
_K_begin_line_ => $i++,
_arrow_count_ => $i++,
_standard_spaces_ => $i++,
+ _K_extra_space_ => $i++,
};
}
$self->[_K_begin_line_] = $input_hash{K_begin_line};
$self->[_arrow_count_] = 0;
$self->[_standard_spaces_] = $input_hash{standard_spaces};
+ $self->[_K_extra_space_] = $input_hash{K_extra_space};
bless $self, $class;
return $self;
sub decrease_available_spaces {
my ( $self, $value ) = @_;
+
if ( defined($value) ) {
$self->[_available_spaces_] -= $value;
}
return $_[0]->[_K_begin_line_];
}
+sub get_K_extra_space {
+ return $_[0]->[_K_extra_space_];
+}
+
sub set_have_child {
my ( $self, $value ) = @_;
if ( defined($value) ) {
--- /dev/null
+is( $module->VERSION, $expected,
+ "$main_module->VERSION matches $module->VERSION ($expected)" );
+
+ok( ( $@ eq "" && "@b" eq "1 4 5 9" ),
+ 'redefinition should not take effect during the sort' );
+
+&$f(
+ ( map { $points->slice($_) } @sls1 ),
+ ( map { $n->slice($_) } @sls1 ),
+ ( map { $this->{Colors}->slice($_) } @sls1 )
+);
+
+AA(
+ "0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789"
+);
+
+AAAAAA(
+ "0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789"
+);
+
+# padded
+return !( $elem->isa('PPI::Statement::End')
+ || $elem->isa('PPI::Statement::Data') );
+
+for (
+ $s = $dbobj->seq( $k, $v, R_LAST ) ;
+ $s == 0 ;
+ $s = $dbobj->seq( $k, $v, R_PREV )
+ )
+{
+ print "$k: $v\n";
+}
+
+# excess without -xci
+fresh_perl_is( '-C-',
+ <<'abcdefghijklmnopq', {}, "ambiguous unary operator check doesn't crash" );
+Warning: Use of "-C-" without parentheses is ambiguous at - line 1.
+abcdefghijklmnopq
+
+# excess with -xci
+{
+ {
+ {
+ $self->privmsg( $to,
+ "One moment please, I shall display the groups with agendas:" );
+ }
+ }
+}
--- /dev/null
+is($module->VERSION, $expected,
+ "$main_module->VERSION matches $module->VERSION ($expected)");
+
+ok(($@ eq "" && "@b" eq "1 4 5 9"),
+ 'redefinition should not take effect during the sort');
+
+&$f((map { $points->slice($_) } @sls1),
+ (map { $n->slice($_) } @sls1),
+ (map { $this->{Colors}->slice($_) } @sls1));
+
+AA("0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789");
+
+AAAAAA("0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789");
+
+# padded
+return !( $elem->isa('PPI::Statement::End')
+ || $elem->isa('PPI::Statement::Data'));
+
+for ($s = $dbobj->seq($k, $v, R_LAST) ;
+ $s == 0 ;
+ $s = $dbobj->seq($k, $v, R_PREV))
+{
+ print "$k: $v\n";
+}
+
+# excess without -xci
+fresh_perl_is('-C-',
+ <<'abcdefghijklmnopq', {}, "ambiguous unary operator check doesn't crash");
+Warning: Use of "-C-" without parentheses is ambiguous at - line 1.
+abcdefghijklmnopq
+
+# excess with -xci
+{
+ {
+ {
+ $self->privmsg($to,
+ "One moment please, I shall display the groups with agendas:"
+ );
+ }
+ }
+}
--- /dev/null
+is( $module->VERSION, $expected,
+ "$main_module->VERSION matches $module->VERSION ($expected)" );
+
+ok( ( $@ eq "" && "@b" eq "1 4 5 9" ),
+ 'redefinition should not take effect during the sort' );
+
+&$f(
+ ( map { $points->slice($_) } @sls1 ),
+ ( map { $n->slice($_) } @sls1 ),
+ ( map { $this->{Colors}->slice($_) } @sls1 )
+);
+
+AA(
+ "0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789"
+);
+
+AAAAAA(
+ "0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789"
+);
+
+# padded
+return !( $elem->isa('PPI::Statement::End')
+ || $elem->isa('PPI::Statement::Data') );
+
+for (
+ $s = $dbobj->seq( $k, $v, R_LAST ) ;
+ $s == 0 ;
+ $s = $dbobj->seq( $k, $v, R_PREV )
+ )
+{
+ print "$k: $v\n";
+}
+
+# excess without -xci
+fresh_perl_is( '-C-',
+ <<'abcdefghijklmnopq', {}, "ambiguous unary operator check doesn't crash" );
+Warning: Use of "-C-" without parentheses is ambiguous at - line 1.
+abcdefghijklmnopq
+
+# excess with -xci
+{
+ {
+ {
+ $self->privmsg( $to,
+ "One moment please, I shall display the groups with agendas:" );
+ }
+ }
+}
--- /dev/null
+-xlp -gnu -xci
../snippets26.t c139.def
../snippets26.t drc.def
../snippets26.t drc.drc
+../snippets26.t git105.def
../snippets3.t ce_wn1.ce_wn
../snippets3.t ce_wn1.def
../snippets3.t colin.colin
../snippets9.t rt98902.def
../snippets9.t rt98902.rt98902
../snippets9.t rt99961.def
-../snippets26.t git105.def
+../snippets26.t git106.def
+../snippets26.t git106.git106
#9 drc.def
#10 drc.drc
#11 git105.def
+#12 git106.def
+#13 git106.git106
# To locate test #13 you can search for its name or the string '#13'
# BEGIN SECTION 1: Parameter combinations #
###########################################
$rparams = {
- 'bal2' => "-bal=2",
- 'c133' => "-boc",
- 'def' => "",
- 'drc' => "-drc",
- 'git93' => <<'----------',
+ 'bal2' => "-bal=2",
+ 'c133' => "-boc",
+ 'def' => "",
+ 'drc' => "-drc",
+ 'git106' => "-xlp -gnu -xci",
+ 'git93' => <<'----------',
-vxl='q'
----------
'lpxl6' => <<'----------',
}
say 'end';
+----------
+
+ 'git106' => <<'----------',
+is( $module->VERSION, $expected,
+ "$main_module->VERSION matches $module->VERSION ($expected)" );
+
+ok( ( $@ eq "" && "@b" eq "1 4 5 9" ),
+ 'redefinition should not take effect during the sort' );
+
+&$f(
+ ( map { $points->slice($_) } @sls1 ),
+ ( map { $n->slice($_) } @sls1 ),
+ ( map { $this->{Colors}->slice($_) } @sls1 )
+);
+
+AA(
+ "0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789"
+);
+
+AAAAAA(
+ "0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789"
+);
+
+# padded
+return !( $elem->isa('PPI::Statement::End')
+ || $elem->isa('PPI::Statement::Data') );
+
+for (
+ $s = $dbobj->seq( $k, $v, R_LAST ) ;
+ $s == 0 ;
+ $s = $dbobj->seq( $k, $v, R_PREV )
+ )
+{
+ print "$k: $v\n";
+}
+
+# excess without -xci
+fresh_perl_is( '-C-',
+ <<'abcdefghijklmnopq', {}, "ambiguous unary operator check doesn't crash" );
+Warning: Use of "-C-" without parentheses is ambiguous at - line 1.
+abcdefghijklmnopq
+
+# excess with -xci
+{
+ {
+ {
+ $self->privmsg( $to,
+ "One moment please, I shall display the groups with agendas:" );
+ }
+ }
+}
----------
'git93' => <<'----------',
#11...........
},
+
+ 'git106.def' => {
+ source => "git106",
+ params => "def",
+ expect => <<'#12...........',
+is( $module->VERSION, $expected,
+ "$main_module->VERSION matches $module->VERSION ($expected)" );
+
+ok( ( $@ eq "" && "@b" eq "1 4 5 9" ),
+ 'redefinition should not take effect during the sort' );
+
+&$f(
+ ( map { $points->slice($_) } @sls1 ),
+ ( map { $n->slice($_) } @sls1 ),
+ ( map { $this->{Colors}->slice($_) } @sls1 )
+);
+
+AA(
+ "0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789"
+);
+
+AAAAAA(
+ "0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789"
+);
+
+# padded
+return !( $elem->isa('PPI::Statement::End')
+ || $elem->isa('PPI::Statement::Data') );
+
+for (
+ $s = $dbobj->seq( $k, $v, R_LAST ) ;
+ $s == 0 ;
+ $s = $dbobj->seq( $k, $v, R_PREV )
+ )
+{
+ print "$k: $v\n";
+}
+
+# excess without -xci
+fresh_perl_is( '-C-',
+ <<'abcdefghijklmnopq', {}, "ambiguous unary operator check doesn't crash" );
+Warning: Use of "-C-" without parentheses is ambiguous at - line 1.
+abcdefghijklmnopq
+
+# excess with -xci
+{
+ {
+ {
+ $self->privmsg( $to,
+ "One moment please, I shall display the groups with agendas:" );
+ }
+ }
+}
+#12...........
+ },
+
+ 'git106.git106' => {
+ source => "git106",
+ params => "git106",
+ expect => <<'#13...........',
+is($module->VERSION, $expected,
+ "$main_module->VERSION matches $module->VERSION ($expected)");
+
+ok(($@ eq "" && "@b" eq "1 4 5 9"),
+ 'redefinition should not take effect during the sort');
+
+&$f((map { $points->slice($_) } @sls1),
+ (map { $n->slice($_) } @sls1),
+ (map { $this->{Colors}->slice($_) } @sls1));
+
+AA("0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789");
+
+AAAAAA("0123456789012345678901234567890123456789",
+ "0123456789012345678901234567890123456789");
+
+# padded
+return !( $elem->isa('PPI::Statement::End')
+ || $elem->isa('PPI::Statement::Data'));
+
+for ($s = $dbobj->seq($k, $v, R_LAST) ;
+ $s == 0 ;
+ $s = $dbobj->seq($k, $v, R_PREV))
+{
+ print "$k: $v\n";
+}
+
+# excess without -xci
+fresh_perl_is('-C-',
+ <<'abcdefghijklmnopq', {}, "ambiguous unary operator check doesn't crash");
+Warning: Use of "-C-" without parentheses is ambiguous at - line 1.
+abcdefghijklmnopq
+
+# excess with -xci
+{
+ {
+ {
+ $self->privmsg($to,
+ "One moment please, I shall display the groups with agendas:"
+ );
+ }
+ }
+}
+#13...........
+ },
};
my $ntests = 0 + keys %{$rtests};