From: Steve Hancock Date: Sun, 2 Jan 2022 17:31:07 +0000 (-0800) Subject: remove unused code, update docs X-Git-Tag: 20211029.05~9 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3178f8ca211f3ef03f9ae9cc481ef2728a750450;p=perltidy.git remove unused code, update docs --- diff --git a/bin/perltidy b/bin/perltidy index 62b0f3b2..7e7fd6c6 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -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 diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index a08ddf7a..e0647b6b 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -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;