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.
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' ],
'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
#
# 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
$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', '!' );
delete-old-newlines
delete-semicolons
extended-syntax
+ function-paren-vertical-alignment
fuzzy-line-length
hanging-side-comments
indent-block-comments
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.
$rOpts_add_whitespace,
$rOpts_delete_old_whitespace,
$rOpts_freeze_whitespace,
+ $rOpts_function_paren_vertical_alignment,
# Static hashes initialized in a BEGIN block
%is_assignment,
$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 = (
|| $ris_broken_container->{$seqno} <= 1 )
{
$ok = 0;
- print
- "BOOGA, $ris_broken_container->{$seqno}\n";
}
}
/^(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 ];
=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
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>
--- /dev/null
+log_something_with_long_function( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep( 3, 4 );
+use Carp ();
+use File::Spec ();
+use File::Path ();
--- /dev/null
+log_something_with_long_function ( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep ( 3, 4 );
+use Carp ();
+use File::Spec ();
+use File::Path ();
--- /dev/null
+log_something_with_long_function ( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep ( 3, 4 );
+use Carp ();
+use File::Spec ();
+use File::Path ();
--- /dev/null
+log_something_with_long_function( 'This is a log message.', 2 );
+Coro::AnyEvent::sleep( 3, 4 );
+use Carp ();
+use File::Spec ();
+use File::Path ();
--- /dev/null
+-sfp -nfpva
../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
# 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'
###########################################
$rparams = {
'def' => "",
+ 'fpva1' => "-sfp",
+ 'fpva2' => "-sfp -nfpva",
'git54' => "-bbp=3 -bbpi=2 -ci=4 -lp",
};
############################
$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 =>
);
#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};