my ( $self, $Kj, $K_last_nonblank, $K_last, $level, $slevel, $ci_level ) =
@_;
- my $rbreak_container = $self->[_rbreak_container_];
- my $rshort_nested = $self->[_rshort_nested_];
- my $rLL = $self->[_rLL_];
+ my $rbreak_container = $self->[_rbreak_container_];
+ my $rshort_nested = $self->[_rshort_nested_];
+ my $rLL = $self->[_rLL_];
+ my $K_opening_container = $self->[_K_opening_container_];
# kill any current block - we can only go 1 deep
destroy_one_line_block();
# If this brace follows a parenthesized list, we should look back to
# find the keyword before the opening paren because otherwise we might
# form a one line block which stays intack, and cause the parenthesized
- # expression to break open. That looks bad. However, actually
- # searching for the opening paren is slow and tedius.
- # The actual keyword is often at the start of a line, but might not be.
- # For example, we might have an anonymous sub with signature list
- # following a =>. It is safe to mark the start anywhere before the
- # opening paren, so we just go back to the prevoious break (or start of
- # the line) if that is before the opening paren. The minor downside is
- # that we may very occasionally break open a block unnecessarily.
+ # expression to break open. That looks bad.
if ( $tokens_to_go[$i_start] eq ')' ) {
- $i_start = $index_max_forced_break + 1;
- if ( $types_to_go[$i_start] eq 'b' ) { $i_start++; }
+
+ # Find the opening paren
+ my $K_start = $K_to_go[$i_start];
+ return 0 unless defined($K_start);
+ my $seqno = $type_sequence_to_go[$i_start];
+ return 0 unless ($seqno);
+ my $K_opening = $K_opening_container->{$seqno};
+ return 0 unless defined($K_opening);
+ my $i_opening = $i_start + ( $K_opening - $K_start );
+
+ # give up if not on this line
+ return 0 unless ( $i_opening >= 0 );
+ $i_start = $i_opening; ##$index_max_forced_break + 1;
+
+ # go back one token before the opening paren
+ if ( $i_start > 0 ) { $i_start-- }
+ if ( $types_to_go[$i_start] eq 'b' && $i_start > 0 ) { $i_start--; }
my $lev = $levels_to_go[$i_start];
if ( $lev > $level ) { return 0 }
}
=head1 Issues fixed after release 20201001
+=item b<fix missing line break for hash of subs with signatures>
+
+During testing the following error was found and fixed.
+Given the following input snippet:
+
+ get(
+ on_ready => sub ($worker) {
+ $on_ready->end;
+ return;
+ },
+ on_exit => sub ( $worker, $status ) { return; },
+ );
+
+The resulting formatting was
+
+ get(
+ on_ready => sub ($worker) {
+ $on_ready->end;
+ return;
+ }, on_exit => sub ( $worker, $status ) { return; },
+ );
+
+Notice that the break after the comma has been lost. The problem was traced to
+a short-cut taken by the code looking for one-line blocks. The unique
+circumstances in which this occured involved a hash of anonymous subs, one with
+a signature with multiple parameters and short enough to be a one-line block,
+as in the last sub definition line. This was fixed 17 Oct 2020.
+
=item b<fix issues with prototype and signature parsing>
Problems with parsing prototypes and signatures were found during testing and
-fixed. For example the following snippet was mis-parsed because of the hash
-mark.
+fixed 17 Oct 2020 in 'fixed problem parsing multi-line signatures with
+comments', 017fd07. For example the following snippet was mis-parsed because
+of the hash mark.
sub test ( # comment )))
$x, $x) { $x+$y }
This problem was discovered in random testing. When a slash follows a bareword
whose prototype is not known to perltidy, it has to guess whether the slash
starts a pattern or is a division. The guessing logic was rewritten and
-improved.
+improved 14 Oct 2020 in 'rewrote logic to guess if divide or pattern', afebe2f.
=item b<fix -bos to keep isolated semicolon breaks after block braces>
;
In testing it was found not to be doing this after braces which require
-semicolons, such as 'do' and anonymous subs. This was fixed. For example
+semicolons, such as 'do' and anonymous subs. This was fixed 12 Oct 2020 in
+'fix -bos to work with semicolons after braces', 03ee7fc. For example
my $dist = sub {
$z = sqrt( $x**2 + $y**2 )
This keeps the list from shifting to the right and can avoid problems in
formatting the list with certain styles, including with the -xci flag.
+Fixed 12 Oct 2020 in 'keep break after use overload statement', 8485afa.
=item B<added flag -xci to improve formatting when -ci and -i are equal, issue git #28>
get(
on_ready => sub ($worker) { $on_ready->end; return; },
- on_exit => sub ( $worker, $status ) {
- return;
- },
- on_data => sub ($data) { $self->_on_data(@_) if $self; return; }
+ on_exit => sub ( $worker, $status ) { return; },
+ on_data => sub ($data) { $self->_on_data(@_) if $self; return; }
);
}
# This signature should get put back on one line
-sub t022 ( $p = do { $z += 10; 222 }, $a = do { $z++; 333 } ) {
- "$p/$a";
-}
+sub t022 ( $p = do { $z += 10; 222 }, $a = do { $z++; 333 } ) { "$p/$a" }
# anonymous sub with signature
my $subref = sub ( $cat, $id = do { state $auto_id = 0; $auto_id++ } ) {
../snippets22.t bbhb.bbhb4
../snippets22.t bbhb.bbhb5
../snippets22.t braces.braces7
+../snippets22.t xci.def
+../snippets22.t xci.xci1
+../snippets22.t xci.xci2
../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
-../snippets22.t xci.def
-../snippets22.t xci.xci1
-../snippets22.t xci.xci2
}
# This signature should get put back on one line
-sub t022 ( $p = do { $z += 10; 222 }, $a = do { $z++; 333 } ) {
- "$p/$a";
-}
+sub t022 ( $p = do { $z += 10; 222 }, $a = do { $z++; 333 } ) { "$p/$a" }
# anonymous sub with signature
my $subref = sub ( $cat, $id = do { state $auto_id = 0; $auto_id++ } ) {
expect => <<'#8...........',
get(
on_ready => sub ($worker) { $on_ready->end; return; },
- on_exit => sub ( $worker, $status ) {
- return;
- },
- on_data => sub ($data) { $self->_on_data(@_) if $self; return; }
+ on_exit => sub ( $worker, $status ) { return; },
+ on_data => sub ($data) { $self->_on_data(@_) if $self; return; }
);
#8...........
},