# This is a sufficient but not necessary condition for colon chain
my $is_colon_chain = ( $colons_in_order && @{$rcolon_list} > 2 );
+ my $Msg = "";
+
#-------------------------------------------------------
# BEGINNING of main loop to set continuation breakpoints
# Keep iterating until we reach the end
)
{
$strength -= $tiny_bias;
+ DEBUG_BREAKPOINTS && do { $Msg .= " :-bias at i=$i_test" };
}
# otherwise increase strength a bit if this token would be at the
$starting_sum;
if ( $len >= $maximum_line_length ) {
$strength += $tiny_bias;
+ DEBUG_BREAKPOINTS && do { $Msg .= " :+bias at i=$i_test" };
}
}
)
{
$self->set_forced_breakpoint($i_next_nonblank);
+ DEBUG_BREAKPOINTS
+ && do { $Msg .= " :Forced break at i=$i_next_nonblank" };
}
if (
if ( $strength < NO_BREAK - 1 ) {
$strength = $lowest_strength - $tiny_bias;
$must_break = 1;
+ DEBUG_BREAKPOINTS
+ && do { $Msg .= " :set must_break at i=$i_next_nonblank" };
}
}
)
)
{
- last if ( $i_lowest >= 0 );
+ if ( $i_lowest >= 0 ) {
+ DEBUG_BREAKPOINTS && do {
+ $Msg .= " :quit at good terminal='$next_nonblank_type'";
+ };
+ last;
+ }
}
# Avoid a break which would strand a single punctuation
)
{
$i_test = min( $imax, $inext_to_go[$i_test] );
+ DEBUG_BREAKPOINTS && do {
+ $Msg .= " :redo at i=$i_test";
+ };
redo;
}
# break at previous best break if it would have produced
# a leading alignment of certain common tokens, and it
# is different from the latest candidate break
- last
- if ($leading_alignment_type);
+ if ($leading_alignment_type) {
+ DEBUG_BREAKPOINTS && do {
+ $Msg .=
+" :last at leading_alignment='$leading_alignment_type'";
+ };
+ last;
+ }
# Force at least one breakpoint if old code had good
# break It is only called if a breakpoint is required or
# over time. A goal is to try to be sure that, if a new
# side comment is introduced into formatted text, then
# the same breakpoints will occur. scbreak.t
- last
- if (
+ if (
$i_test == $imax # we are at the end
&& !get_forced_breakpoint_count()
&& $saw_good_break # old line had good break
&& $i_lowest >= 0 # and we saw a possible break
&& $i_lowest < $imax - 1 # (but not just before this ;)
&& $strength - $lowest_strength < 0.5 * WEAK # and it's good
- );
+ )
+ {
+
+ DEBUG_BREAKPOINTS && do {
+ $Msg .= " :last at good old break\n";
+ };
+ last;
+ }
# Do not skip past an important break point in a short final
# segment. For example, without this check we would miss the
# Make this break for math operators for now
my $ir = $inext_to_go[$i_lowest];
my $il = $iprev_to_go[$ir];
- last
- if ( $types_to_go[$il] =~ /^[\/\*\+\-\%]$/
- || $types_to_go[$ir] =~ /^[\/\*\+\-\%]$/ );
+ if ( $types_to_go[$il] =~ /^[\/\*\+\-\%]$/
+ || $types_to_go[$ir] =~ /^[\/\*\+\-\%]$/ )
+ {
+ DEBUG_BREAKPOINTS && do {
+ $Msg .= " :last-noskip_short";
+ };
+ last;
+ }
}
# Update the minimum bond strength location
$lowest_next_token = $next_nonblank_token;
$lowest_next_type = $next_nonblank_type;
$i_lowest_next_nonblank = $i_next_nonblank;
- last if $must_break;
+ if ($must_break) {
+ DEBUG_BREAKPOINTS && do {
+ $Msg .= " :last-must_break";
+ };
+ last;
+ }
# set flags to remember if a break here will produce a
# leading alignment of certain common tokens
&& !$is_closing_type{$next_nonblank_type} )
{
$too_long = $next_length >= $maximum_line_length;
+ DEBUG_BREAKPOINTS && do {
+ $Msg .= " :too_long=$too_long" if ($too_long);
+ }
}
}
)
{
$too_long = 0;
+ DEBUG_BREAKPOINTS && do {
+ $Msg .= " :do_not_strand next='$next_nonblank_type'";
+ };
}
# we are done if...
- last
- if (
+ if (
# ... no more space and we have a break
$too_long && $i_lowest >= 0
# ... or no more tokens
|| $i_test == $imax
- );
+ )
+ {
+ DEBUG_BREAKPOINTS && do {
+ $Msg .=
+" :Done-too_long=$too_long or i_lowest=$i_lowest or $i_test==imax";
+ };
+ last;
+ }
}
#-------------------------------------------------------
DEBUG_BREAKPOINTS
&& print STDOUT
- "BREAK: best is i = $i_lowest strength = $lowest_strength\n";
+"BREAK: best is i = $i_lowest strength = $lowest_strength;\nReason>> $Msg\n";
+ $Msg = "";
#-------------------------------------------------------
# ?/: rule 2 : if we break at a '?', then break at its ':'
# update indentation size
if ( $i_begin <= $imax ) {
$leading_spaces = leading_spaces_to_go($i_begin);
+ DEBUG_BREAKPOINTS
+ && print STDOUT
+ "updating leading spaces to be $leading_spaces at i=$i_begin\n";
}
}
return $item;
}
+ use constant TEST_LP_FIX => 0;
+
sub set_leading_whitespace {
# This routine defines leading whitespace for the case of -lp formatting
return unless ($rOpts_line_up_parentheses);
return unless ( defined($max_index_to_go) && $max_index_to_go >= 0 );
+ # Patch created 19-Jan-2021 to fix blinkers. But causes a few differences with
+ # old formatting which need to be checked more.
+ if ( TEST_LP_FIX && $max_index_to_go > 0 && $types_to_go[$max_index_to_go] eq 'b' ) {
+
+ $leading_spaces_to_go[$max_index_to_go] =
+ $leading_spaces_to_go[ $max_index_to_go - 1 ];
+ $reduced_spaces_to_go[$max_index_to_go] =
+ $reduced_spaces_to_go[ $max_index_to_go - 1 ];
+ return;
+ }
+
my $rbreak_container = $self->[_rbreak_container_];
my $rshort_nested = $self->[_rshort_nested_];
my $rLL = $self->[_rLL_];