Several minor issues have been fixed, and some new parameters have been
added, as follows:
+ - Fixed rare problem with irregular indentation involving --cuddled-else,
+ usually also with the combination -xci and -lp. Reported in rt #144979.
+
- Add option --weld-fat-comma (-wfc) for issue git #108. When -wfc
is set, along with -wn, perltidy is allowed to weld an opening paren
to an inner opening container when they are separated by a hash key
_rparent_of_seqno_ => $i++,
_rchildren_of_seqno_ => $i++,
_ris_list_by_seqno_ => $i++,
+ _ris_cuddled_closing_brace_ => $i++,
+ _ris_cuddled_opening_brace_ => $i++,
_rbreak_container_ => $i++,
_rshort_nested_ => $i++,
_length_function_ => $i++,
$self->[_rparent_of_seqno_] = {};
$self->[_rchildren_of_seqno_] = {};
$self->[_ris_list_by_seqno_] = {};
+ $self->[_ris_cuddled_closing_brace_] = {};
+ $self->[_ris_cuddled_opening_brace_] = {};
$self->[_rbreak_container_] = {}; # prevent one-line blocks
$self->[_rshort_nested_] = {}; # blocks not forced open
my $rLL = $self->[_rLL_];
return unless ( defined($rLL) && @{$rLL} );
- my $rbreak_container = $self->[_rbreak_container_];
- my $K_opening_container = $self->[_K_opening_container_];
- my $K_closing_container = $self->[_K_closing_container_];
+ my $rbreak_container = $self->[_rbreak_container_];
+ my $ris_cuddled_closing_brace = $self->[_ris_cuddled_closing_brace_];
+ my $ris_cuddled_opening_brace = $self->[_ris_cuddled_opening_brace_];
+ my $K_opening_container = $self->[_K_opening_container_];
+ my $K_closing_container = $self->[_K_closing_container_];
my $is_broken_block = sub {
# so that the cuddled line is balanced.
$rbreak_container->{$opening_seqno} = 1
if ($CBO);
+
+ # Remember which braces are cuddled.
+ # The closing brace is used to set adjusted indentations.
+ # The opening brace is not yet used but might eventually
+ # be needed in setting adjusted indentation.
+ $ris_cuddled_closing_brace->{$closing_seqno} = 1;
+ $ris_cuddled_opening_brace->{$opening_seqno} = 1;
+
}
}
$terminal_type = $types_to_go[ $iend - 2 ];
}
}
- if ( $terminal_type eq '{' ) {
+
+ # Patch for rt144979, part 2. Coordinated with part 1.
+ # Skip cuddled braces.
+ my $seqno_beg = $type_sequence_to_go[$ibeg];
+ my $is_cuddled_closing_brace = $seqno_beg
+ && $self->[_ris_cuddled_closing_brace_]->{$seqno_beg};
+
+ if ( $terminal_type eq '{' && !$is_cuddled_closing_brace ) {
my $Kbeg = $K_to_go[$ibeg];
$ci_levels_to_go[$ibeg] = 0;
}
= $self->get_opening_indentation( $ibeg_weld_fix, $ri_first,
$ri_last, $rindentation_list, $seqno_qw_closing );
+ # Patch for rt144979, part 1. Coordinated with part 2.
+ # Do not undo ci for a cuddled closing brace control; it
+ # needs to be treated exactly the same ci as an isolated
+ # closing brace.
+ my $is_cuddled_closing_brace = $seqno_beg
+ && $self->[_ris_cuddled_closing_brace_]->{$seqno_beg};
+
# First set the default behavior:
if (
# of the form: "); }; ]; )->xxx;"
$is_semicolon_terminated
- # and 'cuddled parens' of the form: ")->pack("
- # Bug fix for RT #123749]: the types here were
- # incorrectly '(' and ')'. Corrected to be '{' and '}'
+ # and 'cuddled parens' of the form: ")->pack(". Bug fix for RT
+ # #123749]: the TYPES here were incorrectly ')' and '('. The
+ # corrected TYPES are '}' and '{'. But skip a cuddled block.
|| (
$terminal_type eq '{'
&& $type_beg eq '}'
&& ( $nesting_depth_to_go[$iend] + 1 ==
$nesting_depth_to_go[$ibeg] )
+ && !$is_cuddled_closing_brace
)
# remove continuation indentation for any line like
&& ( $types_to_go[$iend] eq '{'
|| $levels_to_go[$iend] < $level_beg )
+
+ # but not if a cuddled block
+ && !$is_cuddled_closing_brace
)
# and when the next line is at a lower indentation level...
);
}
-
} ## end closure get_final_indentation
sub get_opening_indentation {
# no one-line block for first map with -ce -cbl=map,sort,grep
@sorted = map {
$_->[0]
-} sort {
+ } sort {
$a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
-} map {
+ } map {
[ $_, length($_) ]
-} @unsorted;
+ } @unsorted;
# perltidy -wn -ce -cbl=sort,map,grep
@sorted = map {
$_->[0]
-} sort {
+ } sort {
$a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
-} map {
+ } map {
[ $_, length($_) ]
-} @unsorted;
+ } @unsorted;
--- /dev/null
+# part 1
+GetOptions(
+ "format|f=s" => sub {
+ my ( $n, $v ) = @_;
+ if ( ( my $k = $formats{$v} ) ) {
+ $format = $k;
+ }
+ else {
+ die("--format must be 'system' or 'user'\n");
+ }
+ return;
+ },
+);
+
+# part 2
+{
+ {
+ {
+ my $desc =
+ $access
+ ? "for -$op under use filetest 'access' $desc_tail"
+ : "for -$op $desc_tail";
+ {
+ local $SIG{__WARN__} = sub {
+ my $w = shift;
+ if ( $w =~ /^File::stat ignores VMS ACLs/ ) {
+ ++$vwarn;
+ }
+ elsif ( $w =~ /^File::stat ignores use filetest 'access'/ )
+ {
+ ++$awarn;
+ }
+ else {
+ $warnings .= $w;
+ }
+ };
+ $rv = eval "$access; -$op \$stat";
+ }
+ }
+ }
+}
+
--- /dev/null
+# part 1
+GetOptions(
+ "format|f=s" => sub {
+ my ( $n, $v ) = @_;
+ if ( ( my $k = $formats{$v} ) ) {
+ $format = $k;
+ } else {
+ die("--format must be 'system' or 'user'\n");
+ }
+ return;
+ },
+);
+
+# part 2
+{
+ {
+ {
+ my $desc =
+ $access
+ ? "for -$op under use filetest 'access' $desc_tail"
+ : "for -$op $desc_tail";
+ {
+ local $SIG{__WARN__} = sub {
+ my $w = shift;
+ if ( $w =~ /^File::stat ignores VMS ACLs/ ) {
+ ++$vwarn;
+ } elsif (
+ $w =~ /^File::stat ignores use filetest 'access'/ )
+ {
+ ++$awarn;
+ } else {
+ $warnings .= $w;
+ }
+ };
+ $rv = eval "$access; -$op \$stat";
+ }
+ }
+ }
+}
+
../snippets27.t dwic.def
../snippets27.t dwic.dwic
../snippets27.t wtc.wtc7
+../snippets27.t rt144979.def
+../snippets27.t rt144979.rt144979
../snippets3.t ce_wn1.ce_wn
../snippets3.t ce_wn1.def
../snippets3.t colin.colin
--- /dev/null
+# part 1
+GetOptions(
+ "format|f=s" => sub {
+ my ( $n, $v ) = @_;
+ if ( ( my $k = $formats{$v} ) ) {
+ $format = $k;
+ } else {
+ die("--format must be 'system' or 'user'\n");
+ }
+ return;
+ },
+);
+
+# part 2
+{{{
+ my $desc =
+ $access
+ ? "for -$op under use filetest 'access' $desc_tail"
+ : "for -$op $desc_tail";
+ {
+ local $SIG{__WARN__} = sub {
+ my $w = shift;
+ if ($w =~ /^File::stat ignores VMS ACLs/)
+ {
+ ++$vwarn;
+ } elsif (
+ $w =~ /^File::stat ignores use filetest 'access'/)
+ {
+ ++$awarn;
+ } else
+ {
+ $warnings .= $w;
+ }
+ };
+ $rv = eval "$access; -$op \$stat";
+ }
+}}}
+
--- /dev/null
+-xci -ce -lp
# no one-line block for first map with -ce -cbl=map,sort,grep
@sorted = map {
$_->[0]
-} sort {
+ } sort {
$a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
-} map {
+ } map {
[ $_, length($_) ]
-} @unsorted;
+ } @unsorted;
#14...........
},
# perltidy -wn -ce -cbl=sort,map,grep
@sorted = map {
$_->[0]
-} sort {
+ } sort {
$a->[1] <=> $b->[1] or $a->[0] cmp $b->[0]
-} map {
+ } map {
[ $_, length($_) ]
-} @unsorted;
+ } @unsorted;
#5...........
},
#7 dwic.def
#8 dwic.dwic
#9 wtc.wtc7
+#10 rt144979.def
+#11 rt144979.rt144979
# To locate test #13 you can search for its name or the string '#13'
# BEGIN SECTION 1: Parameter combinations #
###########################################
$rparams = {
- 'def' => "",
- 'dwic' => "-wn -dwic",
- 'wtc1' => "-wtc=0 -dtc",
- 'wtc2' => "-wtc=1 -atc",
- 'wtc3' => "-wtc=m -atc",
- 'wtc4' => "-wtc=m -atc -dtc",
- 'wtc5' => "-wtc=b -atc -dtc -vtc=2",
- 'wtc6' => "-wtc=i -atc -dtc -vtc=2",
- 'wtc7' => "-wtc=h -atc -dtc -vtc=2",
+ 'def' => "",
+ 'dwic' => "-wn -dwic",
+ 'rt144979' => "-xci -ce -lp",
+ 'wtc1' => "-wtc=0 -dtc",
+ 'wtc2' => "-wtc=1 -atc",
+ 'wtc3' => "-wtc=m -atc",
+ 'wtc4' => "-wtc=m -atc -dtc",
+ 'wtc5' => "-wtc=b -atc -dtc -vtc=2",
+ 'wtc6' => "-wtc=i -atc -dtc -vtc=2",
+ 'wtc7' => "-wtc=h -atc -dtc -vtc=2",
};
############################
PL_sys_intern
) ],
);
+----------
+
+ 'rt144979' => <<'----------',
+# part 1
+GetOptions(
+ "format|f=s" => sub {
+ my ( $n, $v ) = @_;
+ if ( ( my $k = $formats{$v} ) ) {
+ $format = $k;
+ } else {
+ die("--format must be 'system' or 'user'\n");
+ }
+ return;
+ },
+);
+
+# part 2
+{{{
+ my $desc =
+ $access
+ ? "for -$op under use filetest 'access' $desc_tail"
+ : "for -$op $desc_tail";
+ {
+ local $SIG{__WARN__} = sub {
+ my $w = shift;
+ if ($w =~ /^File::stat ignores VMS ACLs/)
+ {
+ ++$vwarn;
+ } elsif (
+ $w =~ /^File::stat ignores use filetest 'access'/)
+ {
+ ++$awarn;
+ } else
+ {
+ $warnings .= $w;
+ }
+ };
+ $rv = eval "$access; -$op \$stat";
+ }
+}}}
+
----------
'wtc' => <<'----------',
#9...........
},
+
+ 'rt144979.def' => {
+ source => "rt144979",
+ params => "def",
+ expect => <<'#10...........',
+# part 1
+GetOptions(
+ "format|f=s" => sub {
+ my ( $n, $v ) = @_;
+ if ( ( my $k = $formats{$v} ) ) {
+ $format = $k;
+ }
+ else {
+ die("--format must be 'system' or 'user'\n");
+ }
+ return;
+ },
+);
+
+# part 2
+{
+ {
+ {
+ my $desc =
+ $access
+ ? "for -$op under use filetest 'access' $desc_tail"
+ : "for -$op $desc_tail";
+ {
+ local $SIG{__WARN__} = sub {
+ my $w = shift;
+ if ( $w =~ /^File::stat ignores VMS ACLs/ ) {
+ ++$vwarn;
+ }
+ elsif ( $w =~ /^File::stat ignores use filetest 'access'/ )
+ {
+ ++$awarn;
+ }
+ else {
+ $warnings .= $w;
+ }
+ };
+ $rv = eval "$access; -$op \$stat";
+ }
+ }
+ }
+}
+
+#10...........
+ },
+
+ 'rt144979.rt144979' => {
+ source => "rt144979",
+ params => "rt144979",
+ expect => <<'#11...........',
+# part 1
+GetOptions(
+ "format|f=s" => sub {
+ my ( $n, $v ) = @_;
+ if ( ( my $k = $formats{$v} ) ) {
+ $format = $k;
+ } else {
+ die("--format must be 'system' or 'user'\n");
+ }
+ return;
+ },
+);
+
+# part 2
+{
+ {
+ {
+ my $desc =
+ $access
+ ? "for -$op under use filetest 'access' $desc_tail"
+ : "for -$op $desc_tail";
+ {
+ local $SIG{__WARN__} = sub {
+ my $w = shift;
+ if ( $w =~ /^File::stat ignores VMS ACLs/ ) {
+ ++$vwarn;
+ } elsif (
+ $w =~ /^File::stat ignores use filetest 'access'/ )
+ {
+ ++$awarn;
+ } else {
+ $warnings .= $w;
+ }
+ };
+ $rv = eval "$access; -$op \$stat";
+ }
+ }
+ }
+}
+
+#11...........
+ },
};
my $ntests = 0 + keys %{$rtests};