From: Meredith Howard Date: Tue, 5 Mar 2019 06:50:18 +0000 (-0600) Subject: Add break-at-old-method-breakpoints X-Git-Tag: 20190601~11^2~2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=868248422ac8280474132dd716dd3e9901ec6283;p=perltidy.git Add break-at-old-method-breakpoints Create -bom option and docs --- diff --git a/bin/perltidy b/bin/perltidy index 9c9bfe52..33909ea3 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -2440,6 +2440,26 @@ or C, then the container will remain broken. Also, breaks at internal keywords C and C 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> 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 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 diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 543754eb..d73bda73 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -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 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 0bc780fd..d956860c 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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]