$add_option->( 'break-before-square-bracket-and-indent', 'bbsbi', '=i' );
$add_option->( 'break-before-paren', 'bbp', '=i' );
$add_option->( 'break-before-paren-and-indent', 'bbpi', '=i' );
+ $add_option->( 'brace-left-list', 'bll', '=s' );
+ $add_option->( 'brace-left-exclusion-list', 'blxl', '=s' );
########################################
$category = 6; # Controlling list formatting
# $option_range{'continuation-indentation'} = [ undef, undef ];
#---------------------------------------------------------------
- # Assign default values to the above options here, except
+ # DEFAULTS: Assign default values to the above options here, except
# for 'outfile' and 'help'.
# These settings should approximate the perlstyle(1) suggestions.
#---------------------------------------------------------------
'nhtml' => [qw(format=tidy)],
'tidy' => [qw(format=tidy)],
+ 'brace-left' => [qw(opening-brace-on-new-line)],
+
# -cb is now a synonym for -ce
'cb' => [qw(cuddled-else)],
'cuddled-blocks' => [qw(cuddled-else)],
}
}
+ ##########################################################
+ # FIXME: Old coding retained for testing but to be deleted
+ # before next release to make -bli and -bl independent.
# -bli flag implies -bl
if ( $rOpts->{'brace-left-and-indent'} ) {
$rOpts->{'opening-brace-on-new-line'} = 1;
}
+ ##########################################################
# it simplifies things if -bl is 0 rather than undefined
if ( !defined( $rOpts->{'opening-brace-on-new-line'} ) ) {
$rOpts->{'opening-brace-on-new-line'} = 0;
}
- # -sbl defaults to -bl if not defined
- if ( !defined( $rOpts->{'opening-sub-brace-on-new-line'} ) ) {
- $rOpts->{'opening-sub-brace-on-new-line'} =
- $rOpts->{'opening-brace-on-new-line'};
- }
-
if ( $rOpts->{'entab-leading-whitespace'} ) {
if ( $rOpts->{'entab-leading-whitespace'} < 0 ) {
Warn("-et=n must use a positive integer; ignoring -et\n");
# Initialized in check_options, modified by prepare_cuddled_block_types:
%want_one_line_block,
- %is_braces_left_exclude_block,
# Initialized in sub prepare_cuddled_block_types
$rcuddled_block_types,
$format_skipping_pattern_begin,
$format_skipping_pattern_end,
$non_indenting_brace_pattern,
+ $bl_exclusion_pattern,
+ $bl_pattern,
$bli_pattern,
$block_brace_vertical_tightness_pattern,
$blank_lines_after_opening_block_pattern,
}
make_bli_pattern();
+ make_bl_pattern();
make_block_brace_vertical_tightness_pattern();
make_blank_line_pattern();
make_keyword_group_list_pattern();
# They will be modified by 'prepare_cuddled_block_types'
%want_one_line_block = %is_sort_map_grep_eval;
- # Default is to exclude one-line block types from -bl formatting
- # FIXME: Eventually a flag should be added to modify this.
- %is_braces_left_exclude_block = %is_sort_map_grep_eval;
-
prepare_cuddled_block_types();
if ( $rOpts->{'dump-cuddled-block-list'} ) {
dump_cuddled_block_list(*STDOUT);
return;
}
+sub make_bl_pattern {
+
+ # Defaults block lists which match old formatting:
+ my $bl_list_string = '*';
+ my $bl_exclusion_list_string = 'sort map grep eval';
+
+ # Possible future default:
+ ##my $bl_list_string = 'if else elsif unless while for foreach do : sub';
+
+ if ( defined( $rOpts->{'brace-left-list'} )
+ && $rOpts->{'brace-left-list'} )
+ {
+ $bl_list_string = $rOpts->{'brace-left-list'};
+ }
+ if ( $bl_list_string =~ /\bsub\b/ ) {
+ $rOpts->{'opening-sub-brace-on-new-line'} ||=
+ $rOpts->{'opening-brace-on-new-line'};
+ }
+ if ( $bl_list_string =~ /\basub\b/ ) {
+ $rOpts->{'opening-anonymous-sub-brace-on-new-line'} ||=
+ $rOpts->{'opening-brace-on-new-line'};
+ }
+
+ $bl_pattern = make_block_pattern( '-bll', $bl_list_string );
+
+ # for -bl, a list with '*' turns on -sbl but not -asbl
+ if ( $bl_pattern =~ /\.\*/ ) {
+ $rOpts->{'opening-sub-brace-on-new-line'} ||=
+ $rOpts->{'opening-brace-on-new-line'};
+ }
+
+ if ( defined( $rOpts->{'brace-left-exclusion-list'} )
+ && $rOpts->{'brace-left-exclusion-list'} )
+ {
+ $bl_exclusion_list_string = $rOpts->{'brace-left-exclusion-list'};
+ if ( $bl_exclusion_list_string =~ /\bsub\b/ ) {
+ $rOpts->{'opening-sub-brace-on-new-line'} = 0;
+ }
+ if ( $bl_exclusion_list_string =~ /\basub\b/ ) {
+ $rOpts->{'opening-anonymous-sub-brace-on-new-line'} = 0;
+ }
+ }
+
+ $bl_exclusion_pattern =
+ make_block_pattern( '-blxl', $bl_exclusion_list_string );
+ return;
+}
+
sub make_bli_pattern {
# default list of block types for which -bli would apply
# the bottom of sub 'respace_tokens' which set the values of
# _KNEXT_SEQ_ITEM_. Or an error has been introduced in the
# loop control lines above.
- Fault("sequence = $type_sequence not defined at K=$KK");
+ Fault("sequence = $type_sequence not defined at K=$KK")
+ if (DEVEL_MODE);
+ next;
}
# NOTE: we must use the original levels here. They can get changed
# the bottom of sub 'respace_tokens' which set the values of
# _KNEXT_SEQ_ITEM_. Or an error has been introduced in the
# loop control lines above.
- Fault("sequence = $type_sequence not defined at K=$KK");
+ Fault("sequence = $type_sequence not defined at K=$KK")
+ if (DEVEL_MODE);
+ next;
}
# Patch: do not mark short blocks with welds.
return;
}
-# FIXME: Example future hash for controlling -bl
-my %is_bl_block;
-
-BEGIN {
- my @q = qw(if else elsif unless while for foreach do);
- @is_bl_block{@q} = (1) x scalar(@q);
-}
-
sub braces_left_setup {
# Called once per file to mark all -bl, -sbl, and -asbl containers
my $rLL = $self->[_rLL_];
return unless ( defined($rLL) && @{$rLL} );
- # We will turn on this hash for braces controlled by these flags
+ # We will turn on this hash for braces controlled by these flags:
my $rbrace_left = $self->[_rbrace_left_];
my $rblock_type_of_seqno = $self->[_rblock_type_of_seqno_];
# use -bl flag if not a sub block of any type
else {
-
- ##FIXME: if ( $block_type && $is_bl_block{$block_type} )
- if ( $rOpts_bl && !$is_braces_left_exclude_block{$block_type} ) {
+ if ( $rOpts_bl
+ && $block_type =~ /$bl_pattern/
+ && $block_type !~ /$bl_exclusion_pattern/ )
+ {
$rbrace_left->{$seqno} = 1;
}
}
$keyword_on_same_line = 0;
}
- # decide if user requested break before '{'
- my $rbrace_left = $self->[_rbrace_left_];
- my $rK_weld_left = $self->[_rK_weld_left_];
-
- # Break if requested with -bl or -bli flag
- my $want_break = $rbrace_left->{$type_sequence};
+ # Break before '{' if requested with -bl or -bli flag
+ my $want_break = $self->[_rbrace_left_]->{$type_sequence};
# But do not break if this token is welded to the left
if ( $total_weld_count
- && defined( $rK_weld_left->{$Ktoken_vars} ) )
+ && defined( $self->[_rK_weld_left_]->{$Ktoken_vars} ) )
{
$want_break = 0;
}