we delete a comma which has become bare, which is not what is wanted. This
happened because the change was based on the starting rather than the final
-line breaks. Rerunning with B<--converge> added fixes things
+line breaks. Running with B<--converge> gives the desired result:
# perltidy -wtc=b -dtc --converge
f(
b => 2,
);
-because changes are based on the line breaks after the first iteration.
+because comma changes are based on the line breaks after the first iteration.
The additional computer time needed by the B<--converge> option to do another
iteration or two will not be noticable except for files with many thousands of
=item *
-Perltidy does not add a trailing comma to a list which appears to be near a
-B<stability limit>. So if a comma is unexpectedly not added, this is probably
-the reason.
-
-This issue can be illustrated with the following example. The closing brace is
-at column 80, the default line length:
-
- # perltidy -atc -dtc -wtc=b
- $menuitem_paste->signal_connect( 'activate' => sub { create_paste_window() }
- );
-
-Adding a trailing comma would cause the maximum line length to be exceeded.
-This in turn would cause a different break point to occur for which the comma
-is no longer bare. So it would get deleted on the next formatting pass,
-returning things to the starting state. This is is an unstable situation.
-
-The rules used to detect and avoid instability work well but are not precise,
-so in some cases where perltidy will not add a comma, it may be possible to add
-a stable trailing comma with editing. For example, if the above example were
-run with B<-l=81 -atc -wtc=b>, perltidy would still not add a trailing comma,
-even though it would be stable.
+Perltidy does not add a trailing comma in some B<edge cases> which appear to
+be near a stability limit. So if a comma is unexpectedly not added, this is
+probably the reason.
=item *
{ # Don't allow interruptions
$SIG{$_} = 'IGNORE';
}
- ( open( CHECKPOINT, "> $aub_tmp"
+ ( open(
+ CHECKPOINT, "> $aub_tmp"
) )
|| # This is just temporary...
&abort(
{ # Don't allow interruptions
$SIG{$_} = 'IGNORE';
}
- ( open( CHECKPOINT, "> $aub_tmp"
+ ( open(
+ CHECKPOINT, "> $aub_tmp"
) )
|| # This is just temporary...
&abort(
==> b1105 <==
foreach $port (
sort
- ( @ARGV[ 1 .. $#ARGV ]
- ) )
+ (
+ @ARGV[ 1 .. $#ARGV ] )
+ )
__END__
foreach $port (
sort
@EXPORT_OK %EXPORT_TAGS);
==> b1489 <==
- $menuitem_dict->signal_connect ( 'activate' => sub { create_dict_window () }
- );
- $menuitem_dict->signal_connect ( 'activate' => sub { create_dict_window () }
- );
+ $menuitem_dict->signal_connect (
+ 'activate' => sub { create_dict_window () } );
+ $menuitem_dict->signal_connect (
+ 'activate' => sub { create_dict_window () } );
==> b1490 <==
-$e_str->bind ( '<return>' => sub {$e_hnr->tabfocus if $e_hnr->can ( 'tabfocus' );}
-);
-$e_str->bind ( '<return>' => sub {$e_hnr->tabfocus if $e_hnr->can ( 'tabfocus' );}
-);
+$e_str->bind (
+'<return>' => sub {$e_hnr->tabfocus if $e_hnr->can ( 'tabfocus' );} );
+$e_str->bind (
+'<return>' => sub {$e_hnr->tabfocus if $e_hnr->can ( 'tabfocus' );} );
==> b156 <==
# State 1
)->join() ;
threads->create(
- sub { lock($COUNT) ; $COUNT++ ; }
- )->join() ;
+ sub { lock($COUNT) ; $COUNT++ ; } )->join() ;
==> b978 <==
$ans = threads->create( sub {
threads->create(
- sub { $p->greeting }
- )->join ;
+ sub { $p->greeting } )->join ;
} )->join ;
$ans = threads->create( sub {
# separated by this line
}
+ # Fix two-line shear (c406)
+ my $i_next_nonblank = $inext_to_go[$i_lowest];
+ if ( $tokens_to_go[$i_next_nonblank] eq ')' ) {
+
+ # Example of a '2 line shear':
+
+ # $wrapped->add_around_modifier(
+ # sub { push @tracelog => 'around 1'; $_[0]->(); } );
+
+ # If we try formatting this with increasing line lengths, the
+ # break based on bond strengths is after the '(' until the closing
+ # paren is just beyond the line length limit. In that case, it can
+ # switch to being just before the ')'. This is rare, and may be
+ # undesirable because it can cause unexpected formatting
+ # variations between similar code, and worse, instability with
+ # trailing commas. So we check for that here and put the break
+ # back after the opening '(' if the ')' is not preceded by a ','.
+ # Issue c406.
+ my $i_prev = iprev_to_go($i_next_nonblank);
+ my $i_opening = $mate_index_to_go[$i_next_nonblank];
+ if ( $types_to_go[$i_prev] ne ','
+ && defined($i_opening)
+ && $i_opening > $i_last_break )
+ {
+ # set a forced breakpoint to block recombination
+ $i_lowest = $i_opening;
+ $forced_breakpoint_to_go[$i_lowest] = 1;
+ }
+ }
+
# guard against infinite loop (should never happen)
if ( $i_lowest <= $i_last_break ) {
DEVEL_MODE