From 34622fb3b1faf5bf03df8ecd89adcf1e49196354 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 24 Jan 2024 05:33:38 -0800 Subject: [PATCH] vsn fix for single item in list --- bin/perltidy | 39 +++++++++++++++++++++++--------- lib/Perl/Tidy/VerticalAligner.pm | 25 ++++++++++++++++---- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/bin/perltidy b/bin/perltidy index f82fce6c..26b12f68 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -5042,20 +5042,37 @@ The current default alignment is strict left justification: [ 10.9, 10.9, 11 ], ); -This option is mainly limited to lists of comma-separated numbers. In a future -release B<-vsn> will become the default. +In a future release B<-vsn> will become the default. +Some points regarding B<-vsn> are: + +=over 4 + +=item * +This option works by inserting a single space ahead of unsigned numbers +when possible. This is not done if it would require increasing the +maximum width of a column. + +=item * +This option is mainly limited to lists of comma-separated numbers. For +multiline lists of numbers, having trailing commas can sometimes improve the +results. If missing, perltidy can add them for example +with parameters B<-wtc=b -atc>. See L<"Adding and Deleting Commas">. + +=item * This option has a control parameter B<--valign-signed-number-limit=N>, or B<-vsnl=N>. This value controls formatting of very long columns of numbers and -should not normally need to be changed. To see the function of this parameter, -consider a very long column of just unsigned numbers, say 1000 lines. If we add -a single negative number, it is undesirable to move all of the other lines over -by one space. This would create many lines of file differences but not really -improve the appearance when a local section of the table was viewed. The number -B avoids this problem by not adding extra indentation to a run -of more than B lines of unsigned numbers. The default value, B, is -set to be approximately the number of lines for which a viewer does not -normally see both ends of a long column of unsigned numbers on a single page. +should not normally need to be changed. To see its purpose, consider a very +long column of just unsigned numbers, say 1000 lines. If we add a single +negative number, it is undesirable to move all of the other numbers over by one +space. This would create many lines of file differences but not really improve +the appearance when a local section of the table was viewed. The number B +avoids this problem by not adding extra indentation to a run of more than B +lines of unsigned numbers. The default value, B, is set to be a number +of lines for which the ends of a long column of unsigned numbers are not +normally both in view. + +=back =back diff --git a/lib/Perl/Tidy/VerticalAligner.pm b/lib/Perl/Tidy/VerticalAligner.pm index e7363bca..981d784d 100644 --- a/lib/Perl/Tidy/VerticalAligner.pm +++ b/lib/Perl/Tidy/VerticalAligner.pm @@ -845,7 +845,14 @@ sub valign_input { if ( $jmax <= 0 ) { $self->[_zero_count_]++; - if ( @{$rgroup_lines} + # VSN PATCH for a single number, part 1. + my $is_numeric = + ( $jmax == 0 + && $rOpts_valign_signed_numbers + && $rpatterns->[0] eq 'n,' ); + + if ( !$is_numeric + && @{$rgroup_lines} && !get_recoverable_spaces( $rgroup_lines->[0]->{'indentation'} ) ) { @@ -5270,14 +5277,19 @@ sub pad_signed_number_columns { } # Try to keep the end data column running; test case 'rfc.in' - # In a list, the last item will still need a trailing comma. - # TODO: consider doing this earlier in the left-right sweep + # The last item in a list will still need a trailing comma. + # VSN PATCH for a single number, part 3: change >= to >=0 and + # check for a leading digit my $jcol = $jmax - 1; - if ( $jcol > 0 && $column_info{$jcol} ) { + if ( $jcol >= 0 && $column_info{$jcol} ) { my $alignment = $alignments[$jcol]; my $old_col = $columns[$jcol]; my $col = $alignment->{column}; - if ( $col < $old_col ) { + + # only do this if the text has a leading digit + if ( $col < $old_col + && $rfields->[$jcol] =~ /^[+-]?\d/ ) + { my $spaces_needed = $old_col - $col; my $spaces_available = $line->get_available_space_on_right(); @@ -5325,6 +5337,9 @@ sub pad_signed_number_columns { my $field = $rfields->[$jcol]; my $pattern = $rpatterns->[$jcol]; + # VSN PATCH for single number part 2 + if ( $pattern eq 'n,' ) { $pattern = 'Q,' } + my $is_signed_number = 0; my $is_unsigned_number = 0; -- 2.39.5