]> git.donarmstrong.com Git - perltidy.git/commitdiff
updated -bom to handle cuddled style chain calls
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 25 May 2019 13:30:48 +0000 (06:30 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 25 May 2019 13:30:48 +0000 (06:30 -0700)
CHANGES.md
bin/perltidy
docs/ChangeLog.html
docs/perltidy.html
lib/Perl/Tidy/Formatter.pm
t/snippets/bom.par [new file with mode: 0644]
t/snippets/bom1.in [new file with mode: 0644]
t/snippets/expect/bom1.bom [new file with mode: 0644]
t/snippets/expect/bom1.def [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets15.t

index a1b68cb9c148dd91209b1885e03d4723263032f3..3d277eb5df00f315f5c47e654106723b959962e8 100644 (file)
@@ -2,6 +2,13 @@
 
 ## 2018 11 20.01
 
+    - added option -bom  (--break-at-old-method-breakpoints) by
+      merrillymeredith which preserves breakpoints of method chains
+
+    - merged patch to fix Windows EOL translation error with UTF-8 written by
+      Ron Ivy. This update prevents automatic conversion to 'DOS' CRLF line
+      endings.
+
     - RT #128280, added flag --one-line-block-semicolons=n (-olbs=n) 
       to control semicolons in one-line blocks.  The values of n are:
         n=0 means no semicolons termininating simple one-line blocks
index 6dc2034ff4a1cc825033409dc75f93df90fa2575..c23dad6b79a62338e44bdeb38b8bd1c3008946e8 100755 (executable)
@@ -2460,6 +2460,22 @@ It will B<keep> these breaks, rather than become this:
       'track.id' => {-ident => 'none_search.id'},
     })->as_query;
 
+This flag will also look for and keep a 'cuddled' style of calls, 
+in which lines begin with a closing paren followed by a call arrow, 
+as in this example:
+
+  my $q = $rs->related_resultset(
+      'CDs'
+  )->related_resultset(
+      'Tracks'
+  )->search( {
+      'track.id' => { -ident => 'none_search.id' },
+  } )->as_query;
+
+You may want to include the B<-weld-nested-containers> flag in this case to keep 
+nested braces and parens together, as in the last line.
+
+
 =item B<-bok>,  B<--break-at-old-keyword-breakpoints>
 
 By default, perltidy will retain a breakpoint before keywords which may
index 3a7b04ff6e92f470c8da9d3d77e1baee0dffcbae..5b326de0f7a9379ba2d21d63ec408dfd55fda4c3 100644 (file)
@@ -2,7 +2,14 @@
 
 <h2>2018 11 20.01</h2>
 
-<pre><code>- RT #128280, added flag --one-line-block-semicolons=n (-olbs=n) 
+<pre><code>- added option -bom  (--break-at-old-method-breakpoints) by
+  merrillymeredith which preserves breakpoints of method chains
+
+- merged patch to fix Windows EOL translation error with UTF-8 written by
+  Ron Ivy. This update prevents automatic conversion to 'DOS' CRLF line
+  endings.
+
+- RT #128280, added flag --one-line-block-semicolons=n (-olbs=n) 
   to control semicolons in one-line blocks.  The values of n are:
     n=0 means no semicolons termininating simple one-line blocks
     n=1 means stable; do not change from input file [DEFAULT and current]
index f2f0b8732313cb7d093b30edda3716344d525f1a..3785c316b81c45bfb1e11091683d02e597f5e721 100644 (file)
 <dt id="o-filename---outfile-filename"><b>-o</b>=filename, <b>--outfile</b>=filename</dt>
 <dd>
 
-<p>Name of the output file (only if a single input file is being processed). If no output file is specified, and output is not redirected to the standard output, the output will go to <i>filename.tdy</i>.</p>
+<p>Name of the output file (only if a single input file is being processed). If no output file is specified, and output is not redirected to the standard output (see <b>-st</b>), the output will go to <i>filename.tdy</i>. [Note: - does not redirect to standard output. Use <b>-st</b> instead.]</p>
 
 </dd>
 <dt id="st---standard-output"><b>-st</b>, <b>--standard-output</b></dt>
 
 <p>By default, if a logical expression is broken at a <code>&amp;&amp;</code>, <code>||</code>, <code>and</code>, or <code>or</code>, then the container will remain broken. Also, breaks at internal keywords <code>if</code> and <code>unless</code> will normally be retained. To prevent this, and thus form longer lines, use <b>-nbol</b>.</p>
 
+</dd>
+<dt id="bom---break-at-old-method-breakpoints"><b>-bom</b>, <b>--break-at-old-method-breakpoints</b></dt>
+<dd>
+
+<p>By default, a method call arrow <code>-&gt;</code> is considered a candidate for a breakpoint, but method chains will fill to the line width before a break is considered. With <b>-bom</b>, breaks before the arrow are preserved, so if you have preformatted a method chain:</p>
+
+<pre><code>  my $q = $rs
+    -&gt;related_resultset(&#39;CDs&#39;)
+    -&gt;related_resultset(&#39;Tracks&#39;)
+    -&gt;search({
+      &#39;track.id&#39; =&gt; {-ident =&gt; &#39;none_search.id&#39;},
+    })-&gt;as_query;</code></pre>
+
+<p>It will <b>keep</b> these breaks, rather than become this:</p>
+
+<pre><code>  my $q = $rs-&gt;related_resultset(&#39;CDs&#39;)-&gt;related_resultset(&#39;Tracks&#39;)-&gt;search({
+      &#39;track.id&#39; =&gt; {-ident =&gt; &#39;none_search.id&#39;},
+    })-&gt;as_query;</code></pre>
+
+<p>This flag will also look for and keep a &#39;cuddled&#39; style of calls, in which lines begin with a closing paren followed by a call arrow, as in this example:</p>
+
+<pre><code>  my $q = $rs-&gt;related_resultset(
+      &#39;CDs&#39;
+  )-&gt;related_resultset(
+      &#39;Tracks&#39;
+  )-&gt;search( {
+      &#39;track.id&#39; =&gt; { -ident =&gt; &#39;none_search.id&#39; },
+  } )-&gt;as_query;</code></pre>
+
+<p>You may want to include the <b>-weld-nested-containers</b> flag in this case to keep nested braces and parens together, as in the last line.</p>
+
 </dd>
 <dt id="bok---break-at-old-keyword-breakpoints"><b>-bok</b>, <b>--break-at-old-keyword-breakpoints</b></dt>
 <dd>
 
 <dl>
 
-<dt id="Around-line-2693">Around line 2693:</dt>
+<dt id="Around-line-2731">Around line 2731:</dt>
 <dd>
 
 <p>&#39;=item&#39; outside of any &#39;=over&#39;</p>
 
 </dd>
-<dt id="Around-line-2881">Around line 2881:</dt>
+<dt id="Around-line-2919">Around line 2919:</dt>
 <dd>
 
 <p>You forgot a &#39;=back&#39; before &#39;=head2&#39;</p>
 
 </dd>
-<dt id="Around-line-2939">Around line 2939:</dt>
+<dt id="Around-line-2977">Around line 2977:</dt>
 <dd>
 
 <p>&#39;=item&#39; outside of any &#39;=over&#39;</p>
 
 </dd>
-<dt id="Around-line-3020">Around line 3020:</dt>
+<dt id="Around-line-3058">Around line 3058:</dt>
 <dd>
 
 <p>You forgot a &#39;=back&#39; before &#39;=head2&#39;</p>
index 96194897f5deb29b58c6aad342ba47e9df779600..f2ab17ee3c929d6dd4684eed5e5939adc7e22ccb 100644 (file)
@@ -12867,10 +12867,36 @@ sub pad_array_to_go {
 
             # remember locations of -> if this is a pre-broken method chain
             if ( $type eq '->' ) {
-                set_forced_breakpoint($i - 1)
-                  if ( ( $i == $i_line_start )
-                    && $rOpts_break_at_old_method_breakpoints );
+##                set_forced_breakpoint($i - 1)
+##                  if ( ( $i == $i_line_start )
+##                    && $rOpts_break_at_old_method_breakpoints );
+                if ($rOpts_break_at_old_method_breakpoints) {
+
+                   # Case 1: look for lines with leading pointers
+                    if ( $i == $i_line_start ) {
+                        set_forced_breakpoint( $i - 1 );
+                    }
+
+                   # Case 2: look for cuddled pointer calls
+                    else {
+
+                       # look for old lines with leading ')->' or ') ->'
+                       # and, when found, force a break before the
+                       # opening paren and previous closing paren.
+                        if (
+                            $types_to_go[$i_line_start] eq '}'
+                            && (   $i == $i_line_start + 1
+                                || $i == $i_line_start + 2
+                                && $types_to_go[ $i - 1 ] eq 'b' )
+                          )
+                        {
+                            set_forced_breakpoint( $i_line_start - 1 );
+                            set_forced_breakpoint($mate_index_to_go[$i_line_start]);
+                        }
+                    }
+                }
             } ## end if ( $type eq '->' )
+
             # remember locations of '||'  and '&&' for possible breaks if we
             # decide this is a long logical expression.
             elsif ( $type eq '||' ) {
diff --git a/t/snippets/bom.par b/t/snippets/bom.par
new file mode 100644 (file)
index 0000000..f96505b
--- /dev/null
@@ -0,0 +1 @@
+-bom -wn
diff --git a/t/snippets/bom1.in b/t/snippets/bom1.in
new file mode 100644 (file)
index 0000000..e5b0be4
--- /dev/null
@@ -0,0 +1,11 @@
+# keep cuddled call chain with -bom
+return Mojo::Promise->resolve(
+    $query_params
+)->then(
+    &_reveal_event
+)->then(sub ($code) {
+    return $c->render(text => '', status => $code);
+})->catch(sub {
+    # 1. return error
+    return $c->render(json => {}, status => 400);
+});
diff --git a/t/snippets/expect/bom1.bom b/t/snippets/expect/bom1.bom
new file mode 100644 (file)
index 0000000..69290c4
--- /dev/null
@@ -0,0 +1,12 @@
+# keep cuddled call chain with -bom
+return Mojo::Promise->resolve(
+    $query_params
+)->then(
+    &_reveal_event
+)->then( sub ($code) {
+    return $c->render( text => '', status => $code );
+} )->catch( sub {
+
+    # 1. return error
+    return $c->render( json => {}, status => 400 );
+} );
diff --git a/t/snippets/expect/bom1.def b/t/snippets/expect/bom1.def
new file mode 100644 (file)
index 0000000..152fe33
--- /dev/null
@@ -0,0 +1,11 @@
+# keep cuddled call chain with -bom
+return Mojo::Promise->resolve($query_params)->then(&_reveal_event)->then(
+    sub ($code) {
+        return $c->render( text => '', status => $code );
+    }
+)->catch(
+    sub {
+        # 1. return error
+        return $c->render( json => {}, status => 400 );
+    }
+);
index 2fd2c11c37ed384e9f1c3b512c8f6a7143f49934..0bf4d91120b19a89ac9bddac5153f4cd7ac055b6 100644 (file)
 ../snippets15.t        olbs.def
 ../snippets15.t        olbs.olbs0
 ../snippets15.t        olbs.olbs2
+../snippets15.t        break_old_methods.break_old_methods
+../snippets15.t        break_old_methods.def
 ../snippets2.t angle.def
 ../snippets2.t arrows1.def
 ../snippets2.t arrows2.def
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets15.t        break_old_methods.break_old_methods
-../snippets15.t        break_old_methods.def
+../snippets15.t        bom1.bom
+../snippets15.t        bom1.def
index 8455c325b8fd7c0fc31e96aa16b05b4c5c4468e0..68dfef6dfb1667359711e11353069022d23ead5c 100644 (file)
@@ -8,6 +8,8 @@
 #5 olbs.olbs2
 #6 break_old_methods.break_old_methods
 #7 break_old_methods.def
+#8 bom1.bom
+#9 bom1.def
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -25,6 +27,7 @@ BEGIN {
     # BEGIN SECTION 1: Parameter combinations #
     ###########################################
     $rparams = {
+        'bom'               => "-bom -wn",
         'break_old_methods' => "--break-at-old-method-breakpoints",
         'def'               => "",
         'gnu'               => "-gnu",
@@ -37,6 +40,20 @@ BEGIN {
     ############################
     $rsources = {
 
+        'bom1' => <<'----------',
+# keep cuddled call chain with -bom
+return Mojo::Promise->resolve(
+    $query_params
+)->then(
+    &_reveal_event
+)->then(sub ($code) {
+    return $c->render(text => '', status => $code);
+})->catch(sub {
+    # 1. return error
+    return $c->render(json => {}, status => 400);
+});
+----------
+
         'break_old_methods' => <<'----------',
 my $q = $rs
    ->related_resultset('CDs')
@@ -195,6 +212,43 @@ my $q = $rs->related_resultset('CDs')->related_resultset('Tracks')->search(
 )->as_query;
 #7...........
         },
+
+        'bom1.bom' => {
+            source => "bom1",
+            params => "bom",
+            expect => <<'#8...........',
+# keep cuddled call chain with -bom
+return Mojo::Promise->resolve(
+    $query_params
+)->then(
+    &_reveal_event
+)->then( sub ($code) {
+    return $c->render( text => '', status => $code );
+} )->catch( sub {
+
+    # 1. return error
+    return $c->render( json => {}, status => 400 );
+} );
+#8...........
+        },
+
+        'bom1.def' => {
+            source => "bom1",
+            params => "def",
+            expect => <<'#9...........',
+# keep cuddled call chain with -bom
+return Mojo::Promise->resolve($query_params)->then(&_reveal_event)->then(
+    sub ($code) {
+        return $c->render( text => '', status => $code );
+    }
+)->catch(
+    sub {
+        # 1. return error
+        return $c->render( json => {}, status => 400 );
+    }
+);
+#9...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};