## 2019 12 03.01
+ - Added a flag to control the feature RT#130394, allow short nested blocks,
+ introduced in the previous release. This feature breaks existing RPerl
+ installations, so a control flag has been introduced and the feature is
+ off by default. The flag is:
+
+ --one-line-block-nesting=i, or -olbn=i, where:
+
+ -olbn=0 do not allow nested one-line blocks [DEFAULT]
+ -olbn=1 allow nested-one line blocks
+
- Fixed issue RT#131288: parse error for un-prototyped constant function
followed by ternary.
+ - Fixed issue RT#131360, installation documentation. Metacpan generates
+ instructions for the perltidy binary which are incorrect. The binary
+ comes with Perl::Tidy. They can both be installed with 'cpanm Perl::Tidy'
+
+
## 2019 12 03
- Fixed issue RT#131115: -bli option not working correctly.
This shows that blocks with a single statement become one-line blocks.
-
=item B<-olbs=n>, B<--one-line-block-semicolons=n>
This flag controls the placement of semicolons at the end of one-line blocks.
ending semicolons which terminate one-line blocks containing just one
semicolon. So these two options are not exact inverses.
+=item B<-olbn=n>, B<--one-line-block-nesting=n>
+
+One-line blocks which themselves contain code blocks will normally be broken
+into multiple lines. This behavior can be controlled with this flag. The
+values of n are:
+
+ n=0 do not allow nested one-line blocks [DEFAULT]
+ n=1 stable: keep existing nested-one line blocks
+
+For example, given the following line:
+
+ sub nospacesplit { map { /^\s*$/ ? () : $_ } split $_[0], $_[1] }
+
+
+the default behavior (B<-olbn=0>) is to break it into multiple lines:
+
+ sub nospacesplit {
+ map { /^\s*$/ ? () : $_ } split $_[0], $_[1];
+ }
+
+The line will be left intact with B<-olbn=1>.
+
+
=back
perlstyle(1), Perl::Tidy(3)
+=head1 INSTALLATION
+
+The perltidy binary uses the Perl::Tidy module and is installed when that module is installed. On many systems, the command 'cpanm Perl::Tidy' will install them.
+
=head1 VERSION
This man page documents perltidy version 20191203.01
<h1>Perltidy Change Log</h1>
+<h2>2019 12 03.01</h2>
+
+<pre><code>- Added a flag to control the feature RT#130394, allow short nested blocks,
+ introduced in the previous release. This feature breaks existing RPerl
+ installations, so a control flag has been introduced and the feature is
+ off by default. The flag is:
+
+ --one-line-block-nesting=i, or -olbn=i, where:
+
+ -olbn=0 do not allow nested one-line blocks [DEFAULT]
+ -olbn=1 allow nested-one line blocks
+
+- Fixed issue RT#131288: parse error for un-prototyped constant function
+ followed by ternary.
+
+- Fixed issue RT#131360, installation documentation. Metacpan generates
+ instructions for the perltidy binary which are incorrect. The binary
+ comes with Perl::Tidy. They can both be installed with 'cpanm Perl::Tidy'
+</code></pre>
+
<h2>2019 12 03</h2>
<pre><code>- Fixed issue RT#131115: -bli option not working correctly.
<li><a href="#EXAMPLES">EXAMPLES</a></li>
<li><a href="#Using-the-formatter-Callback-Object">Using the formatter Callback Object</a></li>
<li><a href="#EXPORT">EXPORT</a></li>
+ <li><a href="#INSTALLATION">INSTALLATION</a></li>
<li><a href="#VERSION">VERSION</a></li>
<li><a href="#LICENSE">LICENSE</a></li>
<li><a href="#BUG-REPORTS">BUG REPORTS</a></li>
<pre><code> &perltidy</code></pre>
+<h1 id="INSTALLATION">INSTALLATION</h1>
+
+<p>On many systems, the command 'cpanm Perl::Tidy' will install both the module Perl::Tidy and a binary perltidy.</p>
+
<h1 id="VERSION">VERSION</h1>
-<p>This man page documents Perl::Tidy version 20191203</p>
+<p>This man page documents Perl::Tidy version 20191203.01</p>
<h1 id="LICENSE">LICENSE</h1>
<li><a href="#FILES">FILES</a></li>
<li><a href="#ERROR-HANDLING">ERROR HANDLING</a></li>
<li><a href="#SEE-ALSO">SEE ALSO</a></li>
+ <li><a href="#INSTALLATION">INSTALLATION</a></li>
<li><a href="#VERSION">VERSION</a></li>
<li><a href="#BUG-REPORTS">BUG REPORTS</a></li>
<li><a href="#COPYRIGHT">COPYRIGHT</a></li>
<p>Note that the <b>n=2</b> option has no effect if adding semicolons is prohibited with the <b>-nasc</b> flag. Also not that while <b>n=2</b> adds missing semicolons to all one-line blocks, regardless of complexity, the <b>n=0</b> option only removes ending semicolons which terminate one-line blocks containing just one semicolon. So these two options are not exact inverses.</p>
+</dd>
+<dt id="olbn-n---one-line-block-nesting-n"><b>-olbn=n</b>, <b>--one-line-block-nesting=n</b></dt>
+<dd>
+
+<p>One-line blocks which themselves contain code blocks will normally be broken into multiple lines. This behavior can be controlled with this flag. The values of n are:</p>
+
+<pre><code> n=0 do not allow nested one-line blocks [DEFAULT]
+ n=1 stable: keep existing nested-one line blocks</code></pre>
+
+<p>For example, given the following line:</p>
+
+<pre><code> sub nospacesplit { map { /^\s*$/ ? () : $_ } split $_[0], $_[1] }</code></pre>
+
+<p>the default behavior (<b>-olbn=0</b>) is to break it into multiple lines:</p>
+
+<pre><code> sub nospacesplit {
+ map { /^\s*$/ ? () : $_ } split $_[0], $_[1];
+ }</code></pre>
+
+<p>The line will be left intact with <b>-olbn=1</b>.</p>
+
</dd>
</dl>
<p>perlstyle(1), Perl::Tidy(3)</p>
+<h1 id="INSTALLATION">INSTALLATION</h1>
+
+<p>The perltidy binary uses the Perl::Tidy module and is installed when that module is installed. On many systems, the command 'cpanm Perl::Tidy' will install them.</p>
+
<h1 id="VERSION">VERSION</h1>
-<p>This man page documents perltidy version 20191203</p>
+<p>This man page documents perltidy version 20191203.01</p>
<h1 id="BUG-REPORTS">BUG REPORTS</h1>
# stop iterations if errors or converged
my $stop_now = $tokenizer->report_tokenization_errors();
- $stop_now ||= $tokenizer->get_unexpected_error_count();
+ $stop_now ||= $tokenizer->get_unexpected_error_count();
if ($stop_now) {
$convergence_log_message = <<EOM;
Stopping iterations because of severe errors.
$add_option->( 'break-before-all-operators', 'bbao', '!' );
$add_option->( 'keep-interior-semicolons', 'kis', '!' );
$add_option->( 'one-line-block-semicolons', 'olbs', '=i' );
+ $add_option->( 'one-line-block-nesting', 'olbn', '=i' );
########################################
$category = 6; # Controlling list formatting
nowarning-output
character-encoding=none
one-line-block-semicolons=1
+ one-line-block-nesting=0
outdent-labels
outdent-long-quotes
outdent-long-comments
&perltidy
+=head1 INSTALLATION
+
+On many systems, the command 'cpanm Perl::Tidy' will install both the module Perl::Tidy and a binary perltidy.
+
+
=head1 VERSION
This man page documents Perl::Tidy version 20191203.01
my $rLL = $self->{rLL};
return unless ( defined($rLL) && @{$rLL} );
+ return unless ( $rOpts->{'one-line-block-nesting'} );
+
my $K_opening_container = $self->{K_opening_container};
my $K_closing_container = $self->{K_closing_container};
my $rbreak_container = $self->{rbreak_container};
sub K_mate_index {
- # Given the index K of an opening or closing container, or ?/: ternary pair,
- # return the index K of the other member of the pair.
+ # Given the index K of an opening or closing container, or ?/: ternary pair,
+ # return the index K of the other member of the pair.
my ( $self, $K ) = @_;
return unless defined($K);
my $rLL = $self->{rLL};
else {
# shouldn't happen
}
+ return;
}
{ # begin recombine_breakpoints
elsif ( $new_line->get_jmax() == 1 && !$keep_group_intact ) {
# There are no matching tokens, so now check side comments.
- # Programming note: accessing arrays with index -1 is
- # risky in Perl, but we have verified there is at least one
- # line in the group and that there is at least one field.
+ # Programming note: accessing arrays with index -1 is
+ # risky in Perl, but we have verified there is at least one
+ # line in the group and that there is at least one field.
my $prev_comment = $group_lines[-1]->get_rfields()->[-1];
my $side_comment = $new_line->get_rfields()->[-1];
my_flush_code() unless ( $side_comment && $prev_comment );
-# rt130394: keep on one line
-$factorial = sub { reduce { $a * $b } 1 .. 11 };
+# rt130394: keep on one line with -olbn=1
+$factorial = sub {
+ reduce { $a * $b } 1 .. 11;
+};
--- /dev/null
+# rt130394: keep on one line with -olbn=1
+$factorial = sub { reduce { $a * $b } 1 .. 11 };
# for-loop in a parenthesized block-map triggered an error message
-map( { foreach my $item ( '0', '1' ) { print $item} } qw(a b c) );
+map( {
+ foreach my $item ( '0', '1' ) {
+ print $item;
+ }
+} qw(a b c) );
{
{
{
- {
- ${msg} = "Hello World!";
- print "My message: ${msg}\n";
- }
+ { ${msg} = "Hello World!"; print "My message: ${msg}\n"; }
} #end level 4
} # end level 3
} # end level 2
{ 1 => 2 } ~~ { 2 => 3 };
{ 2 => 3 } ~~ { 1 => 2 };
\%main:: ~~ { map { $_ => 'x' } keys %main:: };
-{ map { $_ => 'x' } keys %main:: }
+{
+ map { $_ => 'x' } keys %main::
+}
~~ \%main::;
\%hash ~~ \%tied_hash;
\%tied_hash ~~ \%hash;
../snippets9.t rt98902.def
../snippets9.t rt98902.rt98902
../snippets9.t rt99961.def
+../snippets16.t rt130394.rt130394
-# rt130394: keep on one line
+# rt130394: keep on one line with -olbn=1
$factorial = sub { reduce { $a * $b } 1 .. 11 };
{
{
{
- {
- ${msg} = "Hello World!";
- print "My message: ${msg}\n";
- }
+ { ${msg} = "Hello World!"; print "My message: ${msg}\n"; }
} #end level 4
} # end level 3
} # end level 2
{ 1 => 2 } ~~ { 2 => 3 };
{ 2 => 3 } ~~ { 1 => 2 };
\%main:: ~~ { map { $_ => 'x' } keys %main:: };
-{ map { $_ => 'x' } keys %main:: }
+{
+ map { $_ => 'x' } keys %main::
+}
~~ \%main::;
\%hash ~~ \%tied_hash;
\%tied_hash ~~ \%hash;
#14 ndsm1.def
#15 ndsm1.ndsm
#16 rt131288.def
+#17 rt130394.rt130394
# To locate test #13 you can search for its name or the string '#13'
'def' => "",
'git10' => "-wn -ce -cbl=sort,map,grep",
'ndsm' => "-ndsm",
+ 'rt130394' => "-olbn=1",
'rt131115' => "-bli",
'spp1' => "-spp=1",
'spp2' => "-spp=2",
----------
'rt130394' => <<'----------',
-# rt130394: keep on one line
+# rt130394: keep on one line with -olbn=1
$factorial = sub { reduce { $a * $b } 1 .. 11 };
----------
source => "rt130394",
params => "def",
expect => <<'#11...........',
-# rt130394: keep on one line
-$factorial = sub { reduce { $a * $b } 1 .. 11 };
+# rt130394: keep on one line with -olbn=1
+$factorial = sub {
+ reduce { $a * $b } 1 .. 11;
+};
#11...........
},
'usage: ' . $usage . "\n";
#16...........
},
+
+ 'rt130394.rt130394' => {
+ source => "rt130394",
+ params => "rt130394",
+ expect => <<'#17...........',
+# rt130394: keep on one line with -olbn=1
+$factorial = sub { reduce { $a * $b } 1 .. 11 };
+#17...........
+ },
};
my $ntests = 0 + keys %{$rtests};
params => "def",
expect => <<'#13...........',
# for-loop in a parenthesized block-map triggered an error message
-map( { foreach my $item ( '0', '1' ) { print $item} } qw(a b c) );
+map( {
+ foreach my $item ( '0', '1' ) {
+ print $item;
+ }
+} qw(a b c) );
#13...........
},