# FIXME: Are these always correct?
$weld_len_left_closing{$outer_seqno} = 1;
$weld_len_right_opening{$outer_seqno} = 2;
+
+ # QW PATCH 1 (Testing)
+ # undo CI for welded quotes
+ foreach my $K($Kn .. $Kt_end ) {
+ $rLL->[$K]->[_CI_LEVEL_]=0;
+ }
+
+ # Change the level of a closing qw token to be that of the outer
+ # containing token. This will allow -lp indentation to function
+ # correctly in the vertical aligner.
+ $rLL->[$Kt_end]->[_LEVEL_] = $rLL->[$K_closing]->[_LEVEL_];
}
}
return;
$is_leading, $opening_exists
);
+ my $type_beg = $types_to_go[$ibeg];
+ my $token_beg = $tokens_to_go[$ibeg];
+ my $K_beg = $K_to_go[$ibeg];
+ my $ibeg_weld_fix = $ibeg;
+
+ # QW PATCH 2 (Testing)
+ # At an isolated closing token of a qw quote which is welded to
+ # a following closing token, we will locally change its type to
+ # be the same as its token. This will allow formatting to be the
+ # same as for an ordinary closing token.
+
+ # For -lp formatting se use $ibeg_weld_fix to get around the problem
+ # that with -lp type formatting the opening and closing tokens to not
+ # have sequence numbers.
+ if ( $type_beg eq 'q' && $token_beg =~ /^[\)\}\]\>]/ ) {
+ my $K_next_nonblank = $self->K_next_code($K_beg);
+ if ( defined($K_next_nonblank) ) {
+ my $type_sequence = $rLL->[$K_next_nonblank]->[_TYPE_SEQUENCE_];
+ my $token = $rLL->[$K_next_nonblank]->[_TOKEN_];
+ my $welded = weld_len_left( $type_sequence, $token );
+ if ($welded) {
+ $ibeg_weld_fix = $ibeg + ( $K_next_nonblank - $K_beg );
+ $type_beg = $token_beg;
+ }
+ }
+ }
+
# if we are at a closing token of some type..
- if ( $types_to_go[$ibeg] =~ /^[\)\}\]R]$/ ) {
+ if ( $type_beg =~ /^[\)\}\]\>R]$/ ) {
# get the indentation of the line containing the corresponding
# opening token
$opening_indentation, $opening_offset,
$is_leading, $opening_exists
)
- = get_opening_indentation( $ibeg, $ri_first, $ri_last,
+ = get_opening_indentation( $ibeg_weld_fix, $ri_first, $ri_last,
$rindentation_list );
# First set the default behavior:
# incorrectly '(' and ')'. Corrected to be '{' and '}'
|| (
$terminal_type eq '{'
- && $types_to_go[$ibeg] eq '}'
+ && $type_beg eq '}'
&& ( $nesting_depth_to_go[$iend] + 1 ==
$nesting_depth_to_go[$ibeg] )
)
# or without ending '{' and unbalanced, such as
# such as '}->{$operator}'
|| (
- $types_to_go[$ibeg] eq '}'
+ $type_beg eq '}'
&& ( $types_to_go[$iend] eq '{'
|| $levels_to_go[$iend] < $levels_to_go[$ibeg] )
# it is the last token before a level decrease. This will allow
# a closing token to line up with its opening counterpart, and
# avoids a indentation jump larger than 1 level.
- my $K_beg = $K_to_go[$ibeg];
if ( $types_to_go[$i_terminal] =~ /^[\}\]\)R]$/
&& $i_terminal == $ibeg
&& defined($K_beg) )
# handle group(s) of CODE lines
else {
+ # LP FIX PART 1
+ # If we are trying to add extra indentation for -lp formatting,
+ # then we need to try to keep the group intact. But we have
+ # to set the $extra_indent_ok flag to zero in case some lines
+ # are output separately. We fix things up at the bottom.
+ # NOTE: this is a workaround but is tentative; we should really look to
+ # see if if extra indentation is possible.
+ my $rOpt_lp = $rOpts->{'line-up-parentheses'};
+ my $keep_group_intact = $rOpt_lp && $extra_indent_ok;
+ my $extra_indent_ok_save = $extra_indent_ok;
+ $extra_indent_ok = 0;
+
# we will rebuild alignment line group(s);
my @new_lines = @group_lines;
initialize_for_new_group();
# BEFORE this line unless both it and the previous line have side
# comments. This prevents this line from pushing side coments out
# to the right.
- elsif ( $new_line->get_jmax() == 1 ) {
+ ##elsif ( $new_line->get_jmax() == 1 ) {
+ elsif ( $new_line->get_jmax() == 1 && !$keep_group_intact) {
# There are no matching tokens, so now check side comments:
my $prev_comment = $group_lines[-1]->get_rfields()->[-1];
my_flush_code();
}
}
+
+ # LP FIX PART 2
+ # if we managed to keep the group intact for -lp formatting,
+ # restore the flag which allows extra indentation
+ if ( $keep_group_intact && @group_lines == @new_lines ) {
+ $extra_indent_ok = $extra_indent_ok_save;
+ }
my_flush_code();
}
return;