]> git.donarmstrong.com Git - perltidy.git/commitdiff
remove unused code, update docs
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 2 Jan 2022 17:31:07 +0000 (09:31 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 2 Jan 2022 17:31:07 +0000 (09:31 -0800)
bin/perltidy
lib/Perl/Tidy/VerticalAligner.pm

index 62b0f3b2c932c49bd8dd321cfe928135e4cc3385..7e7fd6c674ff9b83308e5b0ddd66b589a4bd2f5d 100755 (executable)
@@ -4210,8 +4210,34 @@ list of possible alignment tokens.  If an unrecognized parameter appears, it is
 simply ignored. And if a parameter is entered in both lists (it should
 not), then the exclusion list has priority.
 
-Note that control of side comment alignment is not done with these parameters but
-rather with the B<--valign-side_comments> listed above.
+To illustrate, consider the following snippet with default formatting
+
+    # perltidy
+    $co_description = ($color) ? 'bold cyan'  : '';           # description
+    $co_prompt      = ($color) ? 'bold green' : '';           # prompt
+    $co_unused      = ($color) ? 'on_green'   : 'reverse';    # unused
+
+To exclude all alignments except the equals we could use:
+
+    # perltidy -vxl='*' -vil='='
+    $co_description = ($color) ? 'bold cyan' : '';          # description
+    $co_prompt      = ($color) ? 'bold green' : '';         # prompt
+    $co_unused      = ($color) ? 'on_green' : 'reverse';    # unused
+
+To exclude only the equals we could use:
+
+    # perltidy -vxl='='
+    $co_description = ($color) ? 'bold cyan' : '';     # description
+    $co_prompt = ($color) ? 'bold green' : '';         # prompt
+    $co_unused = ($color) ? 'on_green' : 'reverse';    # unused
+
+Notice in this last example that although only the equals alignment was
+excluded, the ternary alignments were also lost.  This happens because
+alignments are formed from left-to-right, and when an alignment is prevented
+for any reason, any remaining possible alignments to its right are skipped.
+
+Also notice side comments remain aligned because their alignment is
+controlled separately with the parameter B<--valign-side_comments> described above.
 
 =back
 
index a08ddf7a497aa8d3f91130add9c23d3e2ec7d37b..e0647b6b40a5b0ba2e4e26b1a34be713b852f1ce 100644 (file)
@@ -1313,30 +1313,11 @@ EOM
             $pad += $leading_space_count;
         }
 
-        # Give up if not enough space is available to increase padding.
-        # Note: $padding_available can be a negative number.
-        my $no_fit = $pad > 0 && $pad > $padding_available;
-
-        # Apply any user-defined vertical alignment controls in top-down sweep
-        if (  !$no_fit
-            && $j < $jmax
-            && %valign_control_hash )
-        {
-
-            my $tok = $rtokens_old->[$j];
-            my ( $raw_tok, $lev, $tag, $tok_count ) =
-              decode_alignment_token($tok);
-
-            my $align_ok = $valign_control_hash{$raw_tok};
-            $align_ok = $valign_control_default unless defined($align_ok);
-
-            if ( !$align_ok && $pad != 0 ) {
-                $no_fit = 1;
-            }
-        }
+        # Keep going if this field does not need any space.
+        next if ( $pad < 0 );
 
         # Revert to the starting state if does not fit
-        if ($no_fit) {
+        if ( $pad > $padding_available ) {
 
             ################################################
             # Line does not fit -- revert to starting state
@@ -1347,9 +1328,6 @@ EOM
             return;
         }
 
-        # Keep going if this field does not need any space.
-        next if ( $pad < 0 );
-
         # make room for this field
         $old_line->increase_field_width( $j, $pad );
         $padding_available -= $pad;
@@ -2303,21 +2281,6 @@ sub sweep_left_to_right {
                       && $col > $col_want + $short_pad * $factor;
                 }
 
-                # Apply user-defined vertical alignment controls in l-r sweep
-                if ( !$is_big_gap && %valign_control_hash ) {
-
-                    my $align_ok = $valign_control_hash{$raw_tok};
-                    $align_ok = $valign_control_default
-                      unless defined($align_ok);
-
-                    # Note that the following definition of $pad is not the
-                    # total pad because we are working at group boundaries. But
-                    # we can still see if it is zero or not.
-                    if ( !$align_ok && $col_want != $col ) {
-                        $is_big_gap = 1;
-                    }
-                }
-
                 # if match is limited by gap size, stop aligning at this level
                 if ($is_big_gap) {
                     $blocking_level[$ng] = $lev - 1;
@@ -2835,7 +2798,7 @@ EOM
                     # this way so they have to be applied elsewhere too.
                     my $align_ok = 1;
                     if (%valign_control_hash) {
-                        my $align_ok = $valign_control_hash{$raw_tok};
+                        $align_ok = $valign_control_hash{$raw_tok};
                         $align_ok = $valign_control_default
                           unless defined($align_ok);
                         $delete_me ||= !$align_ok;