]> git.donarmstrong.com Git - perltidy.git/commitdiff
added flag -olbn to control breaking nested one-line blocks
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 7 Jan 2020 01:15:16 +0000 (17:15 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 7 Jan 2020 01:15:16 +0000 (17:15 -0800)
20 files changed:
CHANGES.md
bin/perltidy
docs/ChangeLog.html
docs/Tidy.html
docs/perltidy.html
lib/Perl/Tidy.pm
lib/Perl/Tidy.pod
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/VerticalAligner.pm
t/snippets/expect/rt130394.def
t/snippets/expect/rt130394.rt130394 [new file with mode: 0644]
t/snippets/expect/rt94338.def
t/snippets/expect/side_comments1.def
t/snippets/expect/smart.def
t/snippets/packing_list.txt
t/snippets/rt130394.in
t/snippets/rt130394.par [new file with mode: 0644]
t/snippets10.t
t/snippets16.t
t/snippets9.t

index 0f8d4d7fa134b629e299f9d53948c7b630fc9e9a..d65ea3e93fc6deaebad34427396fea9d445c8210 100644 (file)
@@ -2,9 +2,24 @@
 
 ## 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.
index a858927c6ccc487475bd37cb0c431193f75e97e3..e3bd70d155209f50c6e76c695ada64403aa2f00c 100755 (executable)
@@ -3085,7 +3085,6 @@ the result is
 
 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.
@@ -3104,6 +3103,29 @@ all one-line blocks, regardless of complexity, the B<n=0> option only removes
 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
 
 
@@ -3805,6 +3827,10 @@ detected in any single file will produce this type of exit condition.
 
 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
index c01fc67cd3c22400329d5125fbaadb69b8032fe3..a9971b38edf52d5dfa8bf8834b28c381555f476d 100644 (file)
@@ -1,5 +1,25 @@
 <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.
index 562960e602785dc100f3ec527f1af1b1bbf09af8..93fc0155cb7c471690e8b42abdbe0578bd432fd7 100644 (file)
@@ -20,6 +20,7 @@
   <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>  &amp;perltidy</code></pre>
 
+<h1 id="INSTALLATION">INSTALLATION</h1>
+
+<p>On many systems, the command &#39;cpanm Perl::Tidy&#39; 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>
 
index 0dd1af27dec1c90cb2c213a0386fadf83cd5508e..8edae50bb78faadafea73527d6b98b7b630843d9 100644 (file)
@@ -49,6 +49,7 @@
   <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 &#39;cpanm Perl::Tidy&#39; 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>
 
index a107d08b868001db81355374090016e2e5f530ab..05dcebb93a390d1099fb8e3b938605228a9efa37 100644 (file)
@@ -1178,7 +1178,7 @@ EOM
 
                 # 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.                       
@@ -1881,6 +1881,7 @@ sub generate_options {
     $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
@@ -2108,6 +2109,7 @@ sub generate_options {
       nowarning-output
       character-encoding=none
       one-line-block-semicolons=1
+      one-line-block-nesting=0
       outdent-labels
       outdent-long-quotes
       outdent-long-comments
index 1e5003d99ad9442c24f0594191cb3d69bcd36dec..a98ba8dd484ecb76b5aa576249b92a19dd713b23 100644 (file)
@@ -412,6 +412,11 @@ C<write_debug_entry> in Tidy.pm.
 
   &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
index e5946c03f2975cb41ca2d947244df7f0f3fabf42..3519412e9da767f1c2d33a7ed2fb760b4ec4d6c1 100644 (file)
@@ -3690,6 +3690,8 @@ sub mark_short_nested_blocks {
     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};
@@ -11471,8 +11473,8 @@ sub mate_index_to_go {
 
 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};
@@ -15426,6 +15428,7 @@ sub sync_token_K {
     else {
         # shouldn't happen
     }
+    return;
 }
 
 {    # begin recombine_breakpoints
index 3f93196650353a855f9669d4d4ee23a15580d77f..561d6a6b06453efe0ef9488757005b81037449f6 100644 (file)
@@ -2100,9 +2100,9 @@ sub my_flush {
             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 );
index 62b9536233896387d171ffe87743330a14c37648..7c27c33f3a2cfaae53e55048c91254d2023c4c41 100644 (file)
@@ -1,2 +1,4 @@
-# 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;
+};
diff --git a/t/snippets/expect/rt130394.rt130394 b/t/snippets/expect/rt130394.rt130394
new file mode 100644 (file)
index 0000000..c48c8f5
--- /dev/null
@@ -0,0 +1,2 @@
+# rt130394: keep on one line with -olbn=1
+$factorial = sub { reduce { $a * $b } 1 .. 11 };
index e29b4264a561a80a2da5dfe2228bf7f0b58ce31e..b6eaedce21559aa79fe6be7ed5131b4a987e4e51 100644 (file)
@@ -1,2 +1,6 @@
 # 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) );
index ed598aa96a2a5d187c93695c3b1e56e96fa1a733..8bf131af23e180a2df8bf794ba7d70ddb3e68af2 100644 (file)
@@ -3,10 +3,7 @@
         {
             {
                 {
-                    {
-                        ${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
index 0e2c0a4fcccdd6b7625fbf8f812d156132d8a7dc..d02785625f604d457eefdec6869863d1eef70e1a 100644 (file)
@@ -34,7 +34,9 @@ b_const      ~~ a_const;
 { 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;
index 690938da86396068904d9901b1edb7883768496f..a2716b10979a429bb99c7369634845916afb7c0d 100644 (file)
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
+../snippets16.t        rt130394.rt130394
index 62b9536233896387d171ffe87743330a14c37648..c48c8f5b7fe1c8218a2135f17f8f6ec94e20ac13 100644 (file)
@@ -1,2 +1,2 @@
-# rt130394: keep on one line
+# rt130394: keep on one line with -olbn=1
 $factorial = sub { reduce { $a * $b } 1 .. 11 };
diff --git a/t/snippets/rt130394.par b/t/snippets/rt130394.par
new file mode 100644 (file)
index 0000000..d7b923a
--- /dev/null
@@ -0,0 +1 @@
+-olbn=1
index 143f6d8f45b07d70c48b666480a90fb5902ed4d1..2bda303f530882788e0794616bc63c19cab87e6a 100644 (file)
@@ -427,10 +427,7 @@ sub arrange_topframe {
         {
             {
                 {
-                    {
-                        ${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
@@ -532,7 +529,9 @@ b_const      ~~ a_const;
 { 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;
index 3377c69a0c219812964cfb8c9ba38ad6b60f15a1..50c331728b20c6cd1258f6c966970e0c238595b5 100644 (file)
@@ -17,6 +17,7 @@
 #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'
 
@@ -37,6 +38,7 @@ BEGIN {
         'def'      => "",
         'git10'    => "-wn -ce -cbl=sort,map,grep",
         'ndsm'     => "-ndsm",
+        'rt130394' => "-olbn=1",
         'rt131115' => "-bli",
         'spp1'     => "-spp=1",
         'spp2'     => "-spp=2",
@@ -115,7 +117,7 @@ sub Numerically {$a <=> $b};  # trapped semicolon
 ----------
 
         'rt130394' => <<'----------',
-# rt130394: keep on one line
+# rt130394: keep on one line with -olbn=1
 $factorial = sub { reduce { $a * $b } 1 .. 11 };
 ----------
 
@@ -273,8 +275,10 @@ sub head {
             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...........
         },
 
@@ -355,6 +359,15 @@ $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
   '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};
index aba445bfe1ebf485d8074312a4711d7e19aaff64..734ca6240631e4af583edc9ebaf764f462337184 100644 (file)
@@ -350,7 +350,11 @@ else     { 3; }
             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...........
         },