]> git.donarmstrong.com Git - perltidy.git/commitdiff
Add break-at-old-method-breakpoints
authorMeredith Howard <mhoward@roomag.org>
Tue, 5 Mar 2019 06:50:18 +0000 (00:50 -0600)
committerMeredith Howard <mhoward@roomag.org>
Wed, 6 Mar 2019 01:57:27 +0000 (19:57 -0600)
Create -bom option and docs

bin/perltidy
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm

index 9c9bfe529edf124e437dcc28c5111f30ccee418d..33909ea30c09090f64d543b3168d3ad272029b64 100755 (executable)
@@ -2440,6 +2440,26 @@ or C<or>, then the container will remain broken.  Also, breaks
 at internal keywords C<if> and C<unless> will normally be retained.
 To prevent this, and thus form longer lines, use B<-nbol>.
 
+=item B<-bom>,  B<--break-at-old-method-breakpoints>
+
+By default, a method call arrow C<-E<gt>> is considered a candidate for
+a breakpoint, but method chains will fill to the line width before a break is
+considered.  With B<-bom>, breaks before the arrow are preserved, so if you
+have preformatted a method chain:
+
+  my $q = $rs
+    ->related_resultset('CDs')
+    ->related_resultset('Tracks')
+    ->search({
+      'track.id' => {-ident => 'none_search.id'},
+    })->as_query;
+
+It will B<keep> these breaks, rather than become this:
+
+  my $q = $rs->related_resultset('CDs')->related_resultset('Tracks')->search({
+      'track.id' => {-ident => 'none_search.id'},
+    })->as_query;
+
 =item B<-bok>,  B<--break-at-old-keyword-breakpoints>
 
 By default, perltidy will retain a breakpoint before keywords which may
index 543754ebf014a413487802d2afaf6d5229f93c48..d73bda73502d05e7111db5812a0b468f337db5ef 100644 (file)
@@ -1781,6 +1781,7 @@ sub generate_options {
     ########################################
     $add_option->( 'break-at-old-keyword-breakpoints',   'bok', '!' );
     $add_option->( 'break-at-old-logical-breakpoints',   'bol', '!' );
+    $add_option->( 'break-at-old-method-breakpoints',    'bom', '!' );
     $add_option->( 'break-at-old-ternary-breakpoints',   'bot', '!' );
     $add_option->( 'break-at-old-attribute-breakpoints', 'boa', '!' );
     $add_option->( 'ignore-old-breakpoints',             'iob', '!' );
@@ -3643,6 +3644,7 @@ Following Old Breakpoints
  -kis    keep interior semicolons.  Allows multiple statements per line.
  -boc    break at old comma breaks: turns off all automatic list formatting
  -bol    break at old logical breakpoints: or, and, ||, && (default)
+ -bom    break at old method call breakpoints: ->
  -bok    break at old list keyword breakpoints such as map, sort (default)
  -bot    break at old conditional (ternary ?:) operator breakpoints (default)
  -boa    break at old attribute breakpoints 
index 0bc780fd2f70fa1109e63b628f448793928f3ba3..d956860c7c8a876dbd7039cba2121b2368e920f1 100644 (file)
@@ -254,6 +254,7 @@ use vars qw{
   $rOpts_break_at_old_keyword_breakpoints
   $rOpts_break_at_old_comma_breakpoints
   $rOpts_break_at_old_logical_breakpoints
+  $rOpts_break_at_old_method_breakpoints
   $rOpts_break_at_old_ternary_breakpoints
   $rOpts_break_at_old_attribute_breakpoints
   $rOpts_closing_side_comment_else_flag
@@ -5686,6 +5687,8 @@ EOM
       $rOpts->{'break-at-old-keyword-breakpoints'};
     $rOpts_break_at_old_logical_breakpoints =
       $rOpts->{'break-at-old-logical-breakpoints'};
+    $rOpts_break_at_old_method_breakpoints =
+      $rOpts->{'break-at-old-method-breakpoints'};
     $rOpts_closing_side_comment_else_flag =
       $rOpts->{'closing-side-comment-else-flag'};
     $rOpts_closing_side_comment_maximum_text =
@@ -12862,14 +12865,20 @@ sub pad_array_to_go {
                 set_forced_breakpoint( $i - 1 );
             } ## end if ( $type eq 'k' && $i...)
 
+            # 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 );
+            } ## end if ( $type eq '->' )
             # remember locations of '||'  and '&&' for possible breaks if we
             # decide this is a long logical expression.
-            if ( $type eq '||' ) {
+            elsif ( $type eq '||' ) {
                 push @{ $rand_or_list[$depth][2] }, $i;
                 ++$has_old_logical_breakpoints[$depth]
                   if ( ( $i == $i_line_start || $i == $i_line_end )
                     && $rOpts_break_at_old_logical_breakpoints );
-            } ## end if ( $type eq '||' )
+            } ## end elsif ( $type eq '||' )
             elsif ( $type eq '&&' ) {
                 push @{ $rand_or_list[$depth][3] }, $i;
                 ++$has_old_logical_breakpoints[$depth]