# CODE SECTION 13: Preparing batches for vertical alignment
###########################################################
-use constant TEST_NEW_LIST_METHOD => 0;
-
sub send_lines_to_vertical_aligner {
my ($self) = @_;
$rfield_lengths->[-1] += 2;
}
- #################################################
- # TESTING different methods for indicating a list
- #################################################
-
- # TODO:
- # - change 'is_forced_break' to 'is_list'
- # - compare list names in vertical aligner
- # - try using K of lowest level comma instead of Kbeg
- # - maybe combine the best of both list methods
-
- # Old method: Works well; a few problems, esp with side comments
- my $list_flag_old = $forced_breakpoint || $in_comma_list;
-
- # Test method: Working well but still has a few quirks
- my $list_flag_new = $self->is_list_by_K($Kbeg);
+ # List flag for old method: Works well; a few problems, esp with side
+ # comments. This will eventually be replaced with the new method.
+ my $is_forced_break = $forced_breakpoint || $in_comma_list;
- my $list_flag = TEST_NEW_LIST_METHOD ? $list_flag_new : $list_flag_old;
+ # List flag for new method: Works well but needs more testing
+ my $list_seqno = $self->is_list_by_K($Kbeg);
# send this new line down the pipe
my $rvalign_hash = {};
$rvalign_hash->{level_end} = $level_end;
$rvalign_hash->{level_adj} = $level_adj;
$rvalign_hash->{indentation} = $indentation;
- $rvalign_hash->{is_forced_break} = $list_flag;
+ $rvalign_hash->{is_forced_break} = $is_forced_break;
+ $rvalign_hash->{list_seqno} = $list_seqno;
$rvalign_hash->{outdent_long_lines} = $outdent_long_lines;
$rvalign_hash->{is_terminal_ternary} = $is_terminal_ternary;
$rvalign_hash->{is_terminal_statement} = $is_semicolon_terminated;
# 4. formatting with the -lp option is complicated, and does not
# work well with qw quotes and with -wn formatting.
# 5. a number of special situations, such as 'cuddled' formatting.
- # 6. This routine is mainly concerned with outdenting closing tokens
+ # 6. This routine is mainly concerned with outdenting closing tokens
# but note that there is some overlap with the functions of sub
# undo_ci, which was processed earlier, so care has to be taken to
# keep them coordinated.
use constant DEBUG_VALIGN => 0;
+# Flag for use during conversion to using new $list_seqno
+# to identify lists of items. The flag 'is_forced_break' will
+# be removed when conversion is complete.
+use constant TEST_LIST_SEQNO => 0;
+
sub valign_input {
# Place one line in the current vertical group.
my $level_adj = $rline_hash->{level_adj};
my $indentation = $rline_hash->{indentation};
my $is_forced_break = $rline_hash->{is_forced_break};
+ my $list_seqno = $rline_hash->{list_seqno};
my $outdent_long_lines = $rline_hash->{outdent_long_lines};
my $is_terminal_ternary = $rline_hash->{is_terminal_ternary};
my $is_terminal_statement = $rline_hash->{is_terminal_statement};
indentation => $indentation,
leading_space_count => $leading_space_count,
outdent_long_lines => $outdent_long_lines,
+ list_seqno => $list_seqno,
list_type => "",
is_hanging_side_comment => $is_hanging_side_comment,
maximum_line_length => $maximum_line_length_for_level,
rvertical_tightness_flags => $rvertical_tightness_flags,
is_terminal_ternary => $is_terminal_ternary,
j_terminal_match => $j_terminal_match,
- is_forced_break => $is_forced_break,
end_group => $break_alignment_after,
Kend => $Kend,
ci_level => $ci_level,
# --------------------------------------------------------------------
# Decide if this is a simple list of items.
- # There are 3 list types: none, comma, comma-arrow.
- # We use this below to be less restrictive in deciding what to align.
+ # We use this to be less restrictive in deciding what to align.
# --------------------------------------------------------------------
- if ($is_forced_break) {
- decide_if_list($new_line);
+ if (TEST_LIST_SEQNO) {
+ decide_if_list($new_line) if ($list_seqno);
+ }
+ else {
+ decide_if_list($new_line) if ($is_forced_break);
}
# --------------------------------------------------------------------
# Special treatment of two one-line groups isolated from other lines,
# unless they form a simple list or a terminal match. Otherwise the
# alignment can look strange in some cases.
+ my $list_type = $rlines->[$jbeg]->get_list_type();
if (
$jend == $jbeg
&& $jend_m == $jbeg_m
- && !$rlines->[$jbeg]->get_list_type()
+ && !( $list_type && !TEST_LIST_SEQNO )
&& ( $ng == 1 || $istop_mm < 0 )
&& ( $ng == $ng_max || $istop < 0 )
&& !$line->get_j_terminal_match()
)
{
- # We will just align a leading equals
- next unless ( $imax_min >= 0 && $rtokens->[0] =~ /^=\d/ );
+ # We will just align assignments and simple lists
+ next
+ unless ( $imax_min >= 0 && $rtokens->[0] =~ /^=\d/
+ || ( TEST_LIST_SEQNO && $list_type ) );
# In this case we will limit padding to one indent distance. This
# is a compromise to keep some vertical alignment but prevent large
# Previous line vars
my ( $line_m, $rtokens_m, $rpatterns_m, $rfield_lengths_m, $imax_m,
- $list_type_m );
+ $list_type_m, $ci_level_m );
# Current line vars
- my ( $line, $rtokens, $rpatterns, $rfield_lengths, $imax, $list_type );
+ my ( $line, $rtokens, $rpatterns, $rfield_lengths, $imax, $list_type,
+ $ci_level );
use constant EXPLAIN_COMPARE_PATTERNS => 0;
$rfield_lengths_m = $rfield_lengths;
$imax_m = $imax;
$list_type_m = $list_type;
+ $ci_level_m = $ci_level;
$line = $rnew_lines->[$jj];
$rtokens = $line->get_rtokens();
$rfield_lengths = $line->get_rfield_lengths();
$imax = @{$rtokens} - 2;
$list_type = $line->get_list_type();
+ $ci_level = $line->get_ci_level();
# nothing to do for first line
next if ( $jj == $jbeg );
+ my $ci_jump = $ci_level - $ci_level_m;
+
my $imax_min = $imax_m < $imax ? $imax_m : $imax;
my $imax_align = -1;
##############################
elsif ( $list_type && $list_type eq $list_type_m ) {
+ # do not align lists across a ci jump with new list method
+ if ( TEST_LIST_SEQNO && $ci_jump ) { $imax_min = -1 }
+
my $i_nomatch = $imax_min + 1;
for ( my $i = 0 ; $i <= $imax_min ; $i++ ) {
my $tok = $rtokens->[$i];
last;
}
}
+
$imax_align = $i_nomatch - 1;
}
_indentation_ => $i++,
_leading_space_count_ => $i++,
_outdent_long_lines_ => $i++,
+ _list_seqno_ => $i++,
_list_type_ => $i++,
_is_hanging_side_comment_ => $i++,
_ralignments_ => $i++,
_is_terminal_ternary_ => $i++,
_is_terminal_else_ => $i++,
_j_terminal_match_ => $i++,
- _is_forced_break_ => $i++,
_end_group_ => $i++,
_Kend_ => $i++,
_ci_level_ => $i++,
$self->[_leading_space_count_] = $ri->{leading_space_count};
$self->[_outdent_long_lines_] = $ri->{outdent_long_lines};
$self->[_list_type_] = $ri->{list_type};
+ $self->[_list_seqno_] = $ri->{list_seqno};
$self->[_is_hanging_side_comment_] = $ri->{is_hanging_side_comment};
$self->[_maximum_line_length_] = $ri->{maximum_line_length};
$self->[_rvertical_tightness_flags_] = $ri->{rvertical_tightness_flags};
$self->[_is_terminal_ternary_] = $ri->{is_terminal_ternary};
$self->[_is_terminal_else_] = $ri->{is_terminal_else};
$self->[_j_terminal_match_] = $ri->{j_terminal_match};
- $self->[_is_forced_break_] = $ri->{is_forced_break};
$self->[_end_group_] = $ri->{end_group};
$self->[_Kend_] = $ri->{Kend};
$self->[_ci_level_] = $ri->{ci_level};
sub get_indentation { return $_[0]->[_indentation_] }
sub get_Kend { return $_[0]->[_Kend_] }
sub get_ci_level { return $_[0]->[_ci_level_] }
+ sub get_list_seqno { return $_[0]->[_list_seqno_] }
sub get_imax_pair { return $_[0]->[_imax_pair_] }
return $_[0]->[_is_terminal_ternary_];
}
- sub get_is_forced_break {
- return $_[0]->[_is_forced_break_];
- }
-
sub get_leading_space_count {
return $_[0]->[_leading_space_count_];
}
}
1;
-