]> git.donarmstrong.com Git - perltidy.git/commitdiff
added flag -fpva, --function-paren-vertical-alignment; see git #53
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 6 Mar 2021 02:25:54 +0000 (18:25 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 6 Mar 2021 02:25:54 +0000 (18:25 -0800)
12 files changed:
bin/perltidy
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod
t/snippets/expect/fpva.def [new file with mode: 0644]
t/snippets/expect/fpva.fpva1 [new file with mode: 0644]
t/snippets/expect/fpva.fpva2 [new file with mode: 0644]
t/snippets/fpva.in [new file with mode: 0644]
t/snippets/fpva1.par [new file with mode: 0644]
t/snippets/fpva2.par [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets24.t

index 3008a553c9df25be74d860a2c5e1f3d562339fc9..453a61b13fa00e5c79bf26d71292f4673b9c1510 100755 (executable)
@@ -1332,6 +1332,21 @@ reformatted with -sfp:
 In this particular case the syntax error can be removed if the line order is
 reversed, so that Perl parses 'sub filename' first. 
 
+=item B<-fpva>  or B<--function-paren-vertical-alignment>
+
+A side-effect of using the B<-sfp> flag is that the parens may become vertically
+aligned. For example,
+
+    # perltidy -sfp
+    myfun     ( $aaa, $b, $cc );
+    mylongfun ( $a, $b, $c );
+
+This is the default behavior.  To prevent this alignment use B<-nfpva>:
+
+    # perltidy -sfp -nfpva
+    myfun ( $aaa, $b, $cc );
+    mylongfun ( $a, $b, $c );
+
 =item B<-spp=n>  or B<--space-prototype-paren=n>
 
 This flag can be used to control whether a function prototype is preceded by a space.  For example, the following prototype does not have a space.
@@ -3862,11 +3877,11 @@ aligned in the following statement:
             Proto    => 'tcp'
         );
 
-The only explicit control on vertical alignment is to turn it off using
-B<-novalign>, a flag mainly intended for debugging.  However, vertical
-alignment can be forced to stop and restart by selectively introducing blank
-lines.  For example, a blank has been inserted in the following code
-to keep somewhat similar things aligned.
+Vertical alignment can be completely turned off using B<-novalign>, a flag
+mainly intended for debugging.  However, vertical alignment can be forced to
+stop and restart by selectively introducing blank lines.  For example, a blank
+has been inserted in the following code to keep somewhat similar things
+aligned.
 
     %option_range = (
         'format'             => [ 'tidy', 'html', 'user' ],
@@ -3879,6 +3894,20 @@ to keep somewhat similar things aligned.
         'square-bracket-tightness' => [ 0, 2 ],
     );
 
+Vertical alignment is implemented by locally increasing an existing blank space
+to produce alignment with an adjacent line.  It cannot occur if there is no
+blank space to increase.  So if a particular space is removed by one of the
+existing controls then vertical alignment cannot occur. Likewise, if a space is
+added with one of the controls, then vertical alignment might occur.
+
+For example, 
+
+        # perltidy -nwls='=>'
+        $data = $pkg->new(
+            PeerAddr=> join( ".", @port[ 0 .. 3 ] ),
+            PeerPort=> $port[4] * 256 + $port[5],
+            Proto=> 'tcp'
+        );
 
 =head2 Other Controls
 
index f593e8a57fe9d11d18e03a008dd350d740d7628e..14fe9035a0347619426dc13d297e65e9573beeb7 100644 (file)
@@ -3,7 +3,7 @@
 #
 #    perltidy - a perl script indenter and formatter
 #
-#    Copyright (c) 2000-2020 by Steve Hancock
+#    Copyright (c) 2000-2021 by Steve Hancock
 #    Distributed under the GPL license agreement; see file COPYING
 #
 #    This program is free software; you can redistribute it and/or modify
@@ -2269,6 +2269,7 @@ sub generate_options {
     $add_option->( 'brace-tightness',                           'bt',    '=i' );
     $add_option->( 'delete-old-whitespace',                     'dws',   '!' );
     $add_option->( 'delete-semicolons',                         'dsm',   '!' );
+    $add_option->( 'function-paren-vertical-alignment',         'fpva',  '!' );
     $add_option->( 'keyword-paren-inner-tightness',             'kpit',  '=i' );
     $add_option->( 'keyword-paren-inner-tightness-list',        'kpitl', '=s' );
     $add_option->( 'logical-padding',                           'lop',   '!' );
@@ -2580,6 +2581,7 @@ sub generate_options {
       delete-old-newlines
       delete-semicolons
       extended-syntax
+      function-paren-vertical-alignment
       fuzzy-line-length
       hanging-side-comments
       indent-block-comments
@@ -4206,7 +4208,7 @@ sub show_version {
     print STDOUT <<"EOM";
 This is perltidy, v$VERSION 
 
-Copyright 2000-2020, Steve Hancock
+Copyright 2000-2021, Steve Hancock
 
 Perltidy is free software and may be copied under the terms of the GNU
 General Public License, which is included in the distribution files.
index 6a57f1c2794e864ce0aae5b9c61fda3d0857d1f3..d6e47f023db8d05f563162d066aa5ad6f67360fb 100644 (file)
@@ -173,6 +173,7 @@ my (
     $rOpts_add_whitespace,
     $rOpts_delete_old_whitespace,
     $rOpts_freeze_whitespace,
+    $rOpts_function_paren_vertical_alignment,
 
     # Static hashes initialized in a BEGIN block
     %is_assignment,
@@ -1499,6 +1500,9 @@ EOM
     $rOpts_delete_old_whitespace = $rOpts->{'delete-old-whitespace'};
     $rOpts_freeze_whitespace     = $rOpts->{'freeze-whitespace'};
 
+    $rOpts_function_paren_vertical_alignment =
+      $rOpts->{'function-paren-vertical-alignment'};
+
     # Note that both opening and closing tokens can access the opening
     # and closing flags of their container types.
     %opening_vertical_tightness = (
@@ -14963,8 +14967,6 @@ sub set_continuation_breaks {
                                 || $ris_broken_container->{$seqno} <= 1 )
                             {
                                 $ok = 0;
-                                print
-                                  "BOOGA, $ris_broken_container->{$seqno}\n";
                             }
                         }
 
@@ -18234,9 +18236,12 @@ sub send_lines_to_vertical_aligner {
                               /^(if|unless|elsif)$/;
                         }
 
-                        # Do not align a spaced-function-paren - fixes git #53
-                        # Note that index $i-1 is a blank token if we get here
-                        if ( $i > $ibeg + 1 ) {
+                        # Do not align a spaced-function-paren if requested.
+                        # Issue git #53.  Note that $i-1 is a blank token if we
+                        # get here.
+                        if (  !$rOpts_function_paren_vertical_alignment
+                            && $i > $ibeg + 1 )
+                        {
                             my $type_m  = $types_to_go[ $i - 2 ];
                             my $token_m = $tokens_to_go[ $i - 2 ];
 
index 23a63fcfc6c2faa372f603b3aefbb0ce13162fc2..dba05a0febb5e0a09d776844591fe150a7f7042a 100644 (file)
@@ -2,6 +2,13 @@
 
 =over 4
 
+=item B<Add flag -fpva, --function-paren-vertical-alignment>
+
+A flag -fpva, --function-paren-vertical-alignment, is added to
+prevent vertical alignment of function parens when the -sfp flag is used.
+This is on by default, so that existing formatting remains unchanged unless
+the user requests that vertical alignment not occur with -nfpva.
+
 =item B<Fix for issue git #53, do not align spaced function parens>
 
 Introducing a space before a function call paren had a side effect of
@@ -24,7 +31,7 @@ have been the default but this side-effect was missed when the -sfp parameter
 was added.  Note that parens following keywords are likewise not vertically
 aligned.
 
-5 Mar 2021.
+5 Mar 2021, 00431bf.
 
 =item B<Fix issue git#54 involving -bbp=n and -bbpi=n>
 
diff --git a/t/snippets/expect/fpva.def b/t/snippets/expect/fpva.def
new file mode 100644 (file)
index 0000000..1931ffb
--- /dev/null
@@ -0,0 +1,5 @@
+log_something_with_long_function( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep( 3, 4 );
+use Carp       ();
+use File::Spec ();
+use File::Path ();
diff --git a/t/snippets/expect/fpva.fpva1 b/t/snippets/expect/fpva.fpva1
new file mode 100644 (file)
index 0000000..0b3a299
--- /dev/null
@@ -0,0 +1,5 @@
+log_something_with_long_function ( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep            ( 3, 4 );
+use Carp       ();
+use File::Spec ();
+use File::Path ();
diff --git a/t/snippets/expect/fpva.fpva2 b/t/snippets/expect/fpva.fpva2
new file mode 100644 (file)
index 0000000..f502043
--- /dev/null
@@ -0,0 +1,5 @@
+log_something_with_long_function ( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep ( 3, 4 );
+use Carp ();
+use File::Spec ();
+use File::Path ();
diff --git a/t/snippets/fpva.in b/t/snippets/fpva.in
new file mode 100644 (file)
index 0000000..cc9022a
--- /dev/null
@@ -0,0 +1,5 @@
+log_something_with_long_function( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep( 3, 4 );
+use Carp ();
+use File::Spec ();
+use File::Path ();
diff --git a/t/snippets/fpva1.par b/t/snippets/fpva1.par
new file mode 100644 (file)
index 0000000..c93d6cc
--- /dev/null
@@ -0,0 +1 @@
+-sfp
diff --git a/t/snippets/fpva2.par b/t/snippets/fpva2.par
new file mode 100644 (file)
index 0000000..d8c8b00
--- /dev/null
@@ -0,0 +1 @@
+-sfp -nfpva
index 296c09979eeef37d227b15250ffab84ea90fde28..a2011422a32a354de0a0153c7566138daab1440c 100644 (file)
 ../snippets23.t        git47.def
 ../snippets23.t        git47.git47
 ../snippets23.t        qw.def
+../snippets24.t        git54.def
+../snippets24.t        git54.git54
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets24.t        git54.def
-../snippets24.t        git54.git54
+../snippets24.t        fpva.def
+../snippets24.t        fpva.fpva1
+../snippets24.t        fpva.fpva2
index bae30dc36f0704665e96a686d0b6dc71bb80674f..2da12fe8a686de6c67b8449f9460a1e6756dcf34 100644 (file)
@@ -3,6 +3,9 @@
 # Contents:
 #1 git54.def
 #2 git54.git54
+#3 fpva.def
+#4 fpva.fpva1
+#5 fpva.fpva2
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -21,6 +24,8 @@ BEGIN {
     ###########################################
     $rparams = {
         'def'   => "",
+        'fpva1' => "-sfp",
+        'fpva2' => "-sfp -nfpva",
         'git54' => "-bbp=3 -bbpi=2 -ci=4 -lp",
     };
 
@@ -29,6 +34,14 @@ BEGIN {
     ############################
     $rsources = {
 
+        'fpva' => <<'----------',
+log_something_with_long_function( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep( 3, 4 );
+use Carp ();
+use File::Spec ();
+use File::Path ();
+----------
+
         'git54' => <<'----------',
 # testing sensitivity to excess commas
 my $definition =>
@@ -204,6 +217,42 @@ my $list =
     );
 #2...........
         },
+
+        'fpva.def' => {
+            source => "fpva",
+            params => "def",
+            expect => <<'#3...........',
+log_something_with_long_function( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep( 3, 4 );
+use Carp       ();
+use File::Spec ();
+use File::Path ();
+#3...........
+        },
+
+        'fpva.fpva1' => {
+            source => "fpva",
+            params => "fpva1",
+            expect => <<'#4...........',
+log_something_with_long_function ( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep            ( 3, 4 );
+use Carp       ();
+use File::Spec ();
+use File::Path ();
+#4...........
+        },
+
+        'fpva.fpva2' => {
+            source => "fpva",
+            params => "fpva2",
+            expect => <<'#5...........',
+log_something_with_long_function ( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep ( 3, 4 );
+use Carp ();
+use File::Spec ();
+use File::Path ();
+#5...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};