]> git.donarmstrong.com Git - perltidy.git/commitdiff
improve alignment for 2 lines when line length limit is exceeded
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 11 Dec 2020 16:04:32 +0000 (08:04 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 11 Dec 2020 16:04:32 +0000 (08:04 -0800)
CHANGES.md
dev-bin/build.pl
lib/Perl/Tidy/VerticalAligner.pm
local-docs/BugLog.pod

index 6c2ddc3200e5d316287a1a4db4db86de7191676c..b3f33d128a339c1d0c9c04a1d989e365a47e43be 100644 (file)
@@ -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. 
index 8ecab49272b0e371052e2fb77966dfc6de97d592..05b36cff81058247fffe87756de1e72e82414212 100755 (executable)
@@ -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 ) {
index ec699a834af3a7d3e9ff5ab64f4f1a79224e836f..c4c4be734208cb35c7fd2b74e9f84b33beb195d6 100644 (file)
@@ -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 );
index 3bc3fca86b7c3faf7817ed4957526e47515e4a54..b5f63ddac750354a150dd09852a19f65f9db4d04 100644 (file)
@@ -2,6 +2,56 @@
 
 =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
@@ -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