$rOpts_delete_closing_side_comments,
$rOpts_delete_old_whitespace,
$rOpts_delete_side_comments,
+ $rOpts_extended_continuation_indentation,
$rOpts_format_skipping,
$rOpts_freeze_whitespace,
$rOpts_function_paren_vertical_alignment,
$rOpts_delete_closing_side_comments =
$rOpts->{'delete-closing-side-comments'};
$rOpts_delete_old_whitespace = $rOpts->{'delete-old-whitespace'};
- $rOpts_delete_side_comments = $rOpts->{'delete-side-comments'};
- $rOpts_format_skipping = $rOpts->{'format-skipping'};
- $rOpts_freeze_whitespace = $rOpts->{'freeze-whitespace'};
+ $rOpts_extended_continuation_indentation =
+ $rOpts->{'extended-continuation-indentation'};
+ $rOpts_delete_side_comments = $rOpts->{'delete-side-comments'};
+ $rOpts_format_skipping = $rOpts->{'format-skipping'};
+ $rOpts_freeze_whitespace = $rOpts->{'freeze-whitespace'};
$rOpts_function_paren_vertical_alignment =
$rOpts->{'function-paren-vertical-alignment'};
$rOpts_fuzzy_line_length = $rOpts->{'fuzzy-line-length'};
$self->bli_adjustment();
$self->extended_ci()
- if ( $rOpts->{'extended-continuation-indentation'} );
+ if ($rOpts_extended_continuation_indentation);
# Now clip any adjusted levels to be non-negative
$self->clip_adjusted_levels();
# Give multiline qw lists extra indentation instead of CI. This option
# works well but is currently only activated when the -xci flag is set.
# The reason is to avoid unexpected changes in formatting.
- if ( $rOpts->{'extended-continuation-indentation'} ) {
+ if ($rOpts_extended_continuation_indentation) {
while ( my ( $qw_seqno, $rKrange ) =
each %{$rKrange_multiline_qw_by_seqno} )
{
my $guessed_indentation_level =
$line_of_tokens->{_guessed_indentation_level};
- ######################################
+ # ------------------------------------
# Handle a block (full-line) comment..
- ######################################
+ # ------------------------------------
if ($is_comment) {
if ( $rOpts->{'delete-block-comments'} ) {
|| $guessed_indentation_level == 0
&& $rtok_first->[_TYPE_] eq 'Q' );
- ##########################
+ # -----------------------
# Handle indentation-only
- ##########################
+ # -----------------------
# NOTE: In previous versions we sent all qw lines out immediately here.
# No longer doing this: also write a line which is entirely a 'qw' list
return;
}
- ############################
+ # --------------------------
# Handle all other lines ...
- ############################
+ # --------------------------
# If we just saw the end of an elsif block, write nag message
# if we do not see another elseif or an else.
}
}
+ # -------------------------------------
# loop to process the tokens one-by-one
+ # -------------------------------------
# We do not want a leading blank if the previous batch just got output
if ( $max_index_to_go < 0 && $rLL->[$K_first]->[_TYPE_] eq 'b' ) {
}
}
- # Get next nonblank on this line
- my $next_nonblank_token = '';
- my $next_nonblank_token_type = 'b';
+ # Find next nonblank token on this line and look for a side comment
my $Knnb;
+
+ # if before last token ...
if ( $Ktoken_vars < $K_last ) {
$Knnb = $Ktoken_vars + 1;
- if ( $rLL->[$Knnb]->[_TYPE_] eq 'b'
- && $Knnb < $K_last )
+ if ( $Knnb < $K_last
+ && $rLL->[$Knnb]->[_TYPE_] eq 'b' )
{
$Knnb++;
}
- $next_nonblank_token = $rLL->[$Knnb]->[_TOKEN_];
- $next_nonblank_token_type = $rLL->[$Knnb]->[_TYPE_];
- }
- # Do not allow breaks which would promote a side comment to a
- # block comment. In order to allow a break before an opening
- # or closing BLOCK, followed by a side comment, those sections
- # of code will handle this flag separately.
- $side_comment_follows = ( $next_nonblank_token_type eq '#' );
+ if ( $rLL->[$Knnb]->[_TYPE_] eq '#' ) {
+ $side_comment_follows = 1;
- if ( $side_comment_follows
- && !$is_opening_BLOCK
- && !$is_closing_BLOCK )
- {
- $no_internal_newlines = 1;
+ # Do not allow breaks which would promote a side comment to
+ # a block comment. In order to allow a break before an
+ # opening or closing BLOCK, followed by a side comment,
+ # those sections of code will handle this flag separately.
+ if ( !$is_opening_BLOCK
+ && !$is_closing_BLOCK )
+ {
+ $no_internal_newlines = 1;
+ }
+ }
+ else {
+ $side_comment_follows = undef;
+ }
}
- # We're mainly going to handle breaking for code BLOCKS at this
- # (top) level. Other indentation breaks will be handled by
- # sub scan_list, which is better suited to dealing with them.
+ # if at last token ...
+ else {
+ $side_comment_follows = undef;
+
+ # --------------------
+ # handle side comments
+ # --------------------
+ if ( $type eq '#' ) {
+ $self->store_token_to_go( $Ktoken_vars, $rtoken_vars );
+ next;
+ }
+ }
- # --------------------------
- # handle blanks and comments
- # --------------------------
- if ( $type eq 'b' || $type eq '#' ) {
+ # -------------
+ # handle blanks
+ # -------------
+ if ( $type eq 'b' ) {
$self->store_token_to_go( $Ktoken_vars, $rtoken_vars );
next;
}
# ----------------
if ( $type eq ';' ) {
+ my $next_nonblank_token_type = 'b';
+ my $next_nonblank_token = '';
+ if ( defined($Knnb) ) {
+ $next_nonblank_token = $rLL->[$Knnb]->[_TOKEN_];
+ $next_nonblank_token_type = $rLL->[$Knnb]->[_TYPE_];
+ }
+
my $break_before_semicolon = ( $Ktoken_vars == $K_first )
&& $rOpts_break_at_old_semicolon_breakpoints;
# ----------
elsif ($is_closing_BLOCK) {
+ my $next_nonblank_token_type = 'b';
+ my $next_nonblank_token = '';
+ if ( defined($Knnb) ) {
+ $next_nonblank_token = $rLL->[$Knnb]->[_TOKEN_];
+ $next_nonblank_token_type = $rLL->[$Knnb]->[_TYPE_];
+ }
+
# If there is a pending one-line block ..
if ( $index_start_one_line_block != UNDEFINED_INDEX ) {
$self->store_token_to_go( $Ktoken_vars, $rtoken_vars );
}
- # remember two previous nonblank OUTPUT tokens
+ # remember two previous nonblank, non-comment OUTPUT tokens
$K_last_last_nonblank_code = $K_last_nonblank_code;
$K_last_nonblank_code = $Ktoken_vars;
- } # end of loop over all tokens in this 'line_of_tokens'
+ } ## end of loop over all tokens in this line
my $type = $rLL->[$K_last]->[_TYPE_];
my $break_flag = $self->[_rbreak_after_Klast_]->{$K_last};
$length_tol_boost = 0;
if ($rOpts_line_up_parentheses) {
- if ( $rOpts->{'extended-continuation-indentation'} ) {
+ if ($rOpts_extended_continuation_indentation) {
$length_tol += 2;
$length_tol_boost = 0; # was 1 for FIX2, 0 for FIX3
}
}
# The -xci option alone also needs a slightly larger tol for non-lists
- elsif ( $rOpts->{'extended-continuation-indentation'} ) {
+ elsif ($rOpts_extended_continuation_indentation) {
$length_tol_boost = 0; # was 1 for FIX2, 0 for FIX3
}
return;
$self->flush_vertical_aligner();
}
- $self->undo_ci( $ri_first, $ri_last, $rix_seqno_controlling_ci );
+ $self->undo_ci( $ri_first, $ri_last, $rix_seqno_controlling_ci )
+ if ( $n_last_line > 0 || $rOpts_extended_continuation_indentation );
$self->set_logical_padding( $ri_first, $ri_last, $peak_batch_size,
$starting_in_quote )
# Workaround for problem c007, in which the combination -lp -xci
# can produce a "Program bug" message in unusual circumstances.
my $skip_SECTION_1 = $rOpts_line_up_parentheses
- && $rOpts->{'extended-continuation-indentation'};
+ && $rOpts_extended_continuation_indentation;
foreach my $line ( 0 .. $max_line ) {