my $GoToMsg = "";
use constant EXPLAIN_CHECK_MATCH => 0;
+ # This is a flag for testing alignment by sub sweep_left_to_right only.
+ # This test can help find problems with the alignment logic.
+ # This flag should normally be zero.
+ use constant TEST_SWEEP_ONLY => 0;
+
my $is_hanging_side_comment = $new_line->get_is_hanging_side_comment();
my $rtokens = $new_line->get_rtokens();
my $rfields = $new_line->get_rfields();
# The tokens match. Now See if there is space for this line in the
# current group.
- if ( $self->check_fit( $new_line, $old_line ) ) {
+ if ( $self->check_fit( $new_line, $old_line ) && !TEST_SWEEP_ONLY ) {
EXPLAIN_CHECK_MATCH
&& print "match and fit, imax_align=$imax_align, jmax=$jmax\n";
# Special treatment of two one-line groups isolated from other lines,
# unless they form a simple list or a terminal match. Otherwise the
# alignment can look strange in some cases.
- if ( $jend == $jbeg
+ if (
+ $jend == $jbeg
&& $jend_m == $jbeg_m
&& !$rlines->[$jbeg]->get_list_type()
&& ( $ng == 1 || $istop_mm < 0 )
&& ( $ng == $ng_max || $istop < 0 )
- && !$line->get_j_terminal_match() )
+ && !$line->get_j_terminal_match()
+
+ # Only do this for imperfect matches. This is normally true except
+ # when two perfect matches cannot form a group because the line
+ # length limit would be exceeded. In that case we can still try
+ # to match as many alignments as possible.
+ && ( $imax != $imax_m || $istop_m != $imax_m )
+ )
{
# We will just align a leading equals
}
+ # This flag is for testing only and should normally be zero.
+ use constant TEST_DELETE_NULL => 0;
+
sub delete_unmatched_tokens {
my ( $rlines, $group_level ) = @_;
# PASS 2 over subgroups to remove null alignments
#################################################
- # This works but is currently deactivated pending more testing
- if (0) { #<<<
- delete_null_alignments( $rnew_lines, $rline_hashes, \@subgroups,
- $saw_list_type )
- if ($saw_large_group);
+ # This pass is only used for testing. It is helping to identify
+ # alignment situations which might be improved with a future more
+ # general algorithm which adds a tail matching capability.
+ if (TEST_DELETE_NULL) {
+ delete_null_alignments( $rnew_lines, $rline_hashes, \@subgroups,
+ $saw_list_type )
+ if ($saw_large_group);
}
return ( $max_lev_diff, $saw_side_comment );
=over 4
+=item B<Improve vertical alignment in some two-line matches>
+
+When two lines would be perfectly aligned except for the line length limit,
+previously they would only be aligned if they had a common leading equals. The
+update removes this restriction and allows as many alignments to be made as
+possible. The results are generally improved. This update was made 11 Dec 2020.
+Some examples:
+
+# In this example the side comments were limiting the matches
+
+ # OLD
+ shift @data if @data and $data[0] =~ /Contributed\s+Perl/; # Skip header
+ pop @data if @data and $data[-1] =~ /^\w/; # Skip footer, like
+
+ # NEW
+ shift @data if @data and $data[0] =~ /Contributed\s+Perl/; # Skip header
+ pop @data if @data and $data[-1] =~ /^\w/; # Skip footer, like
+
+# The same is true here.
+
+ # OLD
+ if ($tvg::o_span) { $tvg::hour_span = $tvg::o_span; }
+ if ( $tvg::hour_span % 2 > 0 ) { $tvg::hour_span++; } # Multiple of 2
+
+ # NEW
+ if ($tvg::o_span) { $tvg::hour_span = $tvg::o_span; }
+ if ( $tvg::hour_span % 2 > 0 ) { $tvg::hour_span++; } # Multiple of 2
+
+In the next example, the first comma is now aligned but not the second, because
+of the line length limit:
+
+ # OLD
+ is( MyClass->meta, $mc, '... these metas are still the same thing' );
+ is( MyClass->meta->meta, $mc->meta, '... these meta-metas are the same thing' );
+
+ # NEW
+ is( MyClass->meta, $mc, '... these metas are still the same thing' );
+ is( MyClass->meta->meta, $mc->meta, '... these meta-metas are the same thing' );
+
+In this last example, the first comma is not aligned, but space allows
+alignment to resumes with the second comma.
+
+ # OLD
+ is( $obj->name, $COMPRESS_FILE, " Name now set to '$COMPRESS_FILE'" );
+ is( $obj->prefix, '', " Prefix now empty" );
+
+ # NEW
+ is( $obj->name, $COMPRESS_FILE, " Name now set to '$COMPRESS_FILE'" );
+ is( $obj->prefix, '', " Prefix now empty" );
+
=item B<Improve vertical alignment in some marginal matches>
In perltidy a 'marginal match' occurs for example when two lines share some
update the amount of allowed padding is significatly increased for certain
'good' alignment tokens. Results of extensive testing were favorable provided
that the change is restricted to alignments of '=', 'if' and 'unless'. Update
-made 10 Dec 2020.
+made 10 Dec 2020, a585f0b.
# OLD
my @roles = $self->role_names;
in a later stage of the iteration. In the following example, the last
two lines are processed separately because they do not match the comma
in 'sprintf'. The new rule allows the fat comma alignment to eventually
-get made later in the iteration. Update made 9 Dec 2020.
+get made later in the iteration. Update made 9 Dec 2020, ca0ddf4.
# OLD
$template->param(
then that file will be processed more than once. This looks harmless, but if
the user was also using the -b (backup) parameter, then the original backup
would be overwritten, which is not good. To avoid this, a filter has been
-placed on the list of files to remove duplicates. 9 Dec 2020.
+placed on the list of files to remove duplicates. 9 Dec 2020, 646a542.
=back
The exit status flag was not being set for the -w option if the -se or if the -q flag
were set. Issue git #44 was similar but a special case of the problem. The
-problem was fixed 8 Dec 2020.
+problem was fixed 8 Dec 2020, cb6028f.
=back
correctly formatted with the next release. The bug was a result of a new
coding introduced in v20201202 for fixing some issues with parsing sub
signatures. Previously they were sometimes parsed the same as prototypes and
-sometimes as lists, now they are always parsed as lists.
+sometimes as lists, now they are always parsed as lists. Fixed 6 Dec 2020, 6fd0c4f.
=back