]> git.donarmstrong.com Git - perltidy.git/commitdiff
vsn fix for single item in list
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 24 Jan 2024 13:33:38 +0000 (05:33 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 24 Jan 2024 13:33:38 +0000 (05:33 -0800)
bin/perltidy
lib/Perl/Tidy/VerticalAligner.pm

index f82fce6c5ff1c0e68dbbb761c65f375b51b4911b..26b12f6815e8803a68e3426cca8830915b6258d1 100755 (executable)
@@ -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<N> avoids this problem by not adding extra indentation to a run
-of more than B<N> lines of unsigned numbers.  The default value, B<N=20>, 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<N>
+avoids this problem by not adding extra indentation to a run of more than B<N>
+lines of unsigned numbers.  The default value, B<N=20>, 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
 
index e7363bca3f8f9c067711c4d554b9f52e21b28d92..981d784d3023c0a7015b1b49ccba6e3f9da52eaf 100644 (file)
@@ -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;