From: Steve Hancock Date: Fri, 11 Dec 2020 16:04:32 +0000 (-0800) Subject: improve alignment for 2 lines when line length limit is exceeded X-Git-Tag: 20210111~44 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f3c6cd8230e953337971d888c0c3256870e72454;p=perltidy.git improve alignment for 2 lines when line length limit is exceeded --- diff --git a/CHANGES.md b/CHANGES.md index 6c2ddc32..b3f33d12 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,15 @@ # Perltidy Change Log +## 2020 12 07 xx + + - Fixed issue git #49, -se breaks warnings exit status behavior. + The exit status flag was not always being set when the -se flag was set. + + - Some minor issues that the average user would not encounter were found + and fixed. They can be seen in the more complete list of updates at + + https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod + ## 2020 12 07 - Fixed issue git #47, incorrect welding of anonymous subs. diff --git a/dev-bin/build.pl b/dev-bin/build.pl index 8ecab492..05b36cff 100755 --- a/dev-bin/build.pl +++ b/dev-bin/build.pl @@ -628,10 +628,10 @@ sub update_VERSION { my $is_pod_file = !$is_md_file && $source_file !~ /\.pm/; while ( my $line = <$fh> ) { - # Look for and turn off any DEVEL_MODE, DEBUG_XXX, VERIFY_XXX, + # Look for and turn off any DEVEL_MODE, DEBUG_XXX, VERIFY_XXX, TEST_XXX, # and EXPLAIN_XXX constants if ( $line =~ -/^(\s*use\s+constant\s+(?:DEBUG|DEVEL|EXPLAIN|VERIFY)_[A-Z]+\s*)=>\s*(-?\d*);(.*)$/ +/^(\s*use\s+constant\s+(?:DEBUG|DEVEL|EXPLAIN|VERIFY|TEST)_[A-Z]+\s*)=>\s*(-?\d*);(.*)$/ ) { if ( $2 != 0 ) { diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index ec699a83..c4c4be73 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -1131,6 +1131,11 @@ sub check_match { 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(); @@ -1288,7 +1293,7 @@ sub check_match { # 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"; @@ -1927,12 +1932,20 @@ sub sweep_left_to_right { # 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 @@ -2464,6 +2477,9 @@ EOM } + # 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 ) = @_; @@ -2859,11 +2875,13 @@ EOM # 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 ); diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 3bc3fca8..b5f63dda 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,56 @@ =over 4 +=item B + +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 In perltidy a 'marginal match' occurs for example when two lines share some @@ -10,7 +60,7 @@ placed on the size of the padding spaces that can be introduced. In this 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; @@ -39,7 +89,7 @@ if either ended in a '=>'. The old rule was preventing some good alignments 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( @@ -79,7 +129,7 @@ command line to perltidy, as for 'file1.pl' here 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 @@ -87,7 +137,7 @@ placed on the list of files to remove duplicates. 9 Dec 2020. 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 @@ -124,7 +174,7 @@ This bug has been fixed, and code which has been incorrectly formatted will be 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