B<--keyword-group-blanks-list=s>, or B<-kgbl=s>, where B<s> is a quoted string,
defines the set of keywords which will be formed into groups. The string is a
space separated list of keywords. The default set is B<s="use require local
-our my sub">, but any list of keywords may be used.
+our my sub">, but any list of keywords may be used. Comment lines may also be included in a keyword group, even though they are not keywords. To include ordinary block comments, include the symbol 'BC'. To include special block comments (which normally begin with '##'), include the symbol 'SBC'.
B<--keyword-group-blanks-size=s>, or B<-kgbs=s>, where B<s> is a string
describing the number of consecutive keyword statements forming a group. If
<p>Finer control over blank placement can be achieved by using the individual parameters rather than the <b>-kgb</b> flag. The individual controls are as follows.</p>
-<p><b>--keyword-group-blanks-list=s</b>, or <b>-kgbl=s</b>, where <b>s</b> is a quoted string, defines the set of keywords which will be formed into groups. The string is a space separated list of keywords. The default set is <b>s="use require local our my sub"</b>, but any list of keywords may be used.</p>
+<p><b>--keyword-group-blanks-list=s</b>, or <b>-kgbl=s</b>, where <b>s</b> is a quoted string, defines the set of keywords which will be formed into groups. The string is a space separated list of keywords. The default set is <b>s="use require local our my sub"</b>, but any list of keywords may be used. Comment lines may also be included in a keyword group, even though they are not keywords. To include ordinary block comments, include the symbol 'BC'. To include special block comments (which normally begin with '##'), include the symbol 'SBC'.</p>
<p><b>--keyword-group-blanks-size=s</b>, or <b>-kgbs=s</b>, where <b>s</b> is a string describing the number of consecutive keyword statements forming a group. If <b>s</b> is an integer then it is the minimum number required for a group. A maximum value may also be given with the format <b>s=min.max</b>, where <b>min</b> is the minimum number and <b>max</b> is the maximum number, and the min and max values are separated by one or more dots. No groups will be found if the maximum is less than the minimum. The maximum is unlimited if not given. The default is <b>s=5</b>. Some examples:</p>
$block_brace_vertical_tightness_pattern
$keyword_group_list_pattern
+ $keyword_group_list_comment_pattern
$rOpts_add_newlines
$rOpts_add_whitespace
|| $Opt_blanks_inside
|| $Opt_blanks_delete );
- my $Opt_pattern = $keyword_group_list_pattern;
+ my $Opt_pattern = $keyword_group_list_pattern;
+ my $Opt_comment_pattern = $keyword_group_list_comment_pattern;
my $Opt_repeat_count =
$rOpts->{'keyword-group-blanks-repeat-count'}; # '-kgbr'
if ( $line_text && $line_text =~ /^#/ );
}
- # Do not inseert a blank after a comment
+ # Do not insert a blank after a comment
# (this could be subject to a flag in the future)
- #if ( $Opt_blanks_after_comments != 0
- # || $code_type !~ /(BC|SBC|SBCX)/ )
if ( $code_type !~ /(BC|SBC|SBCX)/ ) {
if ( $Opt_blanks_before == INSERT ) {
$insert_blank_after->( $ibeg - 1 );
# If the keyword lines ends with an open token, find the closing token
# '$K_closing' so that we can easily skip past the contents of the
# container.
+ return if ( $K_last <= $K_first );
my $KK = $K_last;
my $type_last = $rLL->[$KK]->[_TYPE_];
my $tok_last = $rLL->[$KK]->[_TOKEN_];
# New sub-group?
if ( !@group || $token ne $group[-1]->[1] ) {
push @subgroup, scalar(@group);
- my $num = @group;
- my $oldtok = $num ? $group[-1]->[1] : "";
-
}
push @group, [ $i, $token, $count ];
my $token = $rLL->[$K_first]->[_TOKEN_];
my $ci_level = $rLL->[$K_first]->[_CI_LEVEL_];
+ # see if this is a code type we seek (i.e. comment)
+ if ( $CODE_type
+ && $Opt_comment_pattern
+ && $CODE_type =~ /$Opt_comment_pattern/o )
+ {
+
+ my $tok = $CODE_type;
+
+ # Continuing a group
+ if ( $ibeg >= 0 && $level == $level_beg ) {
+ $add_to_group->( $i, $tok, $level );
+ }
+
+ # Start new group
+ else {
+
+ # first end old group if any; we might be starting new
+ # keywords at different level
+ if ( $ibeg > 0 ) { $end_group->(); }
+ $add_to_group->( $i, $tok, $level );
+ }
+ next;
+ }
+
# See if it is a keyword we seek, but never start a group in a
# continuation line; the code may be badly formatted.
if ( $ci_level == 0
# turn any input list into a regex for recognizing selected block types.
# Here are the defaults:
- ##$keyword_group_list_pattern = '^((our|local|my|use|require|)$|sub)';
- $keyword_group_list_pattern = '^(our|local|my|use|require|)$';
+ $keyword_group_list_pattern = '^(our|local|my|use|require|)$';
+ $keyword_group_list_comment_pattern = '';
if ( defined( $rOpts->{'keyword-group-blanks-list'} )
&& $rOpts->{'keyword-group-blanks-list'} )
{
+ my @words = split /\s+/, $rOpts->{'keyword-group-blanks-list'};
+ my @keyword_list;
+ my @comment_list;
+ foreach my $word (@words) {
+ if ( $word =~ /^(BC|SBC)$/ ) {
+ push @comment_list, $word;
+ if ( $word eq 'SBC' ) { push @comment_list, 'SBCX' }
+ }
+ else {
+ push @keyword_list, $word;
+ }
+ }
$keyword_group_list_pattern =
make_block_pattern( '-kgbl', $rOpts->{'keyword-group-blanks-list'} );
+ $keyword_group_list_comment_pattern =
+ make_block_pattern( '-kgbl', join( ' ', @comment_list ) );
}
return;
}