The default is to use vertical alignment, but bertical alignment can be
completely turned of with the B<-novalign> flag.
+A lower level of control of vertical alignment is possible with three parameters
+B<-vc>, B<-vsc>, and B<-vbc>. These independently control alignment
+of code, side comments and block comments. They are described in the
+next section.
+
+The parameter B<-valign> is in fact an alias for B<-vc -vsc -vbc>, and its
+negative B<-novalign> is an alias for B<-nvc -nvsc -nvbc>.
+
+=item B<Controlling code alignment with --valign-code or -vc>
+
+The B<-vc> flag enables alignment of code symbols such as B<=>. The default is B<-vc>.
+
+=item B<Controlling side comment alignment with --valign-side-comments or -vsc>
+
+The B<-vsc> flag enables alignment of side comments and is enabled by default. If side
+comment aligment is disabled with B<-nvsc> they will appear at a fixed space from the
+preceding code token. The default is B<-vsc>
+
+=item B<Controlling block comment alignment with --valign-block-comments or -vbc>
+
+When B<-vbc> is enabled, block comments can become aligned for example if one
+comment of a consecutive sequence of comments becomes outdented due a length in
+excess of the maximum line length. If this occurs, the entire group of
+comments will remain aligned and be outdented by the same amount. This coordinated
+alignment will not occur if B<-nvbc> is set. The default is B<-vbc>.
+
=back
=head2 Other Controls
+#!/usr/bin/perl
#
###########################################################
#
# which is mainly for debugging
# scl --> short-concatenation-item-length # helps break at '.'
# recombine # for debugging line breaks
- # valign # for debugging vertical alignment
# I --> DIAGNOSTICS # for debugging [**DEACTIVATED**]
######################################################################
no-profile
npro
recombine!
- valign!
notidy
);
$add_option->( 'want-left-space', 'wls', '=s' );
$add_option->( 'want-right-space', 'wrs', '=s' );
$add_option->( 'space-prototype-paren', 'spp', '=i' );
+ $add_option->( 'valign-code', 'vc', '!' );
+ $add_option->( 'valign-block-comments', 'vbc', '!' );
+ $add_option->( 'valign-side-comments', 'vsc', '!' );
########################################
$category = 4; # Comment controls
noweld-nested-containers
recombine
nouse-unicode-gcstring
- valign
+ valign-code
+ valign-block-comments
+ valign-side-comments
short-concatenation-item-length=8
space-for-semicolon
space-backslash-quote=1
'conv' => [qw(it=4)],
'nconv' => [qw(it=1)],
+ 'valign' => [qw(vc vsc vbc)],
+ 'novalign' => [qw(nvc nvsc nvbc)],
+
# NOTE: This is a possible future shortcut. But it will remain
# deactivated until the -lpxl flag is no longer experimental.
# 'line-up-function-parentheses' => [ qw(lp), q#lpxl=[ { F(2# ],
$rOpts_tee_side_comments,
$rOpts_variable_maximum_line_length,
$rOpts_valign,
+ $rOpts_valign_code,
+ $rOpts_valign_side_comments,
$rOpts_whitespace_cycle,
# Static hashes initialized in a BEGIN block
$rOpts_tee_pod = $rOpts->{'tee-pod'};
$rOpts_tee_side_comments = $rOpts->{'tee-side-comments'};
$rOpts_valign = $rOpts->{'valign'};
+ $rOpts_valign_code = $rOpts->{'valign-code'};
+ $rOpts_valign_side_comments = $rOpts->{'valign-side-comments'};
$rOpts_variable_maximum_line_length =
$rOpts->{'variable-maximum-line-length'};
my ( $self, $ri_first, $ri_last ) = @_;
my $rspecial_side_comment_type = $self->[_rspecial_side_comment_type_];
+ my $rLL = $self->[_rLL_];
my $ralignment_type_to_go;
my $alignment_count = 0;
my $token = $tokens_to_go[$max_i];
my $KK = $K_to_go[$max_i];
- unless (
+ # Do not align various special side comments
+ my $do_not_align = (
# it is any specially marked side comment
( defined($KK) && $rspecial_side_comment_type->{$KK} )
# or it is a static side comment
- || ( $rOpts->{'static-side-comments'}
+ || ( $rOpts->{'static-side-comments'}
&& $token =~ /$static_side_comment_pattern/ )
- # or a closing side comment
- || ( $types_to_go[$i_terminal] eq '}'
+ # or a closing side comment
+ || ( $types_to_go[$i_terminal] eq '}'
&& $tokens_to_go[$i_terminal] eq '}'
&& $token =~ /$closing_side_comment_prefix_pattern/ )
- )
+ );
+
+ # - For the particular combination -vc -nvsc, we put all side comments
+ # at fixed locations. Note that we will lose hanging side comment
+ # alignments. Otherwise, hsc's can move to strange locations.
+ # - For -nvc -nvsc we will make all side comments vertical alignments
+ # because the vertical aligner will check for -nvsc and be able
+ # to reduce the final padding to the side comments for long lines.
+ # and keep hanging side comments aligned.
+ if ( !$do_not_align
+ && !$rOpts_valign_side_comments
+ && $rOpts_valign_code )
{
+
+ $do_not_align = 1;
+ my $ipad = $max_i - 1;
+ if ( $types_to_go[$ipad] eq 'b' ) {
+ my $pad_spaces =
+ $rOpts->{'minimum-space-to-comment'} -
+ $token_lengths_to_go[$ipad];
+ $self->pad_token( $ipad, $pad_spaces );
+ }
+ }
+
+ if ( !$do_not_align ) {
$ralignment_type_to_go->[$max_i] = '#';
$alignment_count++;
}
}
- # Nothing more to do if -novalign is set
- if ( !$rOpts_valign ) {
+ # Nothing more to do on this line if -nvc is set
+ if ( !$rOpts_valign_code ) {
return ( $ralignment_type_to_go, $alignment_count );
}
my $ibeg = $ri_first->[$line];
my $iend = $ri_last->[$line];
- # back up before did any side comment
+ # back up before any side comment
if ( $iend > $i_terminal ) { $iend = $i_terminal }
my $level_beg = $levels_to_go[$ibeg];
_rOpts_minimum_space_to_comment_ => $i++,
_rOpts_maximum_line_length_ => $i++,
_rOpts_variable_maximum_line_length_ => $i++,
- _rOpts_valign_ => $i++,
+ _rOpts_valign_code_ => $i++,
+ _rOpts_valign_block_comments_ => $i++,
+ _rOpts_valign_side_comments_ => $i++,
_last_level_written_ => $i++,
_last_side_comment_column_ => $i++,
$self->[_rOpts_maximum_line_length_] = $rOpts->{'maximum-line-length'};
$self->[_rOpts_variable_maximum_line_length_] =
$rOpts->{'variable-maximum-line-length'};
- $self->[_rOpts_valign_] = $rOpts->{'valign'};
+ $self->[_rOpts_valign_code_] = $rOpts->{'valign-code'};
+ $self->[_rOpts_valign_block_comments_] = $rOpts->{'valign-block-comments'};
+ $self->[_rOpts_valign_side_comments_] = $rOpts->{'valign-side-comments'};
# Batch of lines being collected
$self->[_rgroup_lines_] = [];
if ( $level < 0 ) { $level = 0 }
# do not align code across indentation level changes
- # or if vertical alignment is turned off for debugging
- if ( $level != $group_level || $is_outdented || !$self->[_rOpts_valign_] ) {
+ # or if vertical alignment is turned off
+ if (
+ $level != $group_level
+ || $is_outdented
+ || ( $is_block_comment && !$self->[_rOpts_valign_block_comments_] )
+ || ( !$is_block_comment
+ && !$self->[_rOpts_valign_side_comments_]
+ && !$self->[_rOpts_valign_code_] )
+ )
+ {
$self->_flush_group_lines( $level - $group_level );
my $short_diff = SC_LONG_LINE_DIFF / ( 1 + $alev_diff * $num5 );
goto FORGET
- if ( $line_diff > $short_diff ) || !$self->[_rOpts_valign_];
+ if ( $line_diff > $short_diff
+ || !$self->[_rOpts_valign_side_comments_] );
# RULE3: Forget a side comment if this line is at lower level and
# ends a block
+{
# simple vertical alignment of '=' and '#'
-my $lines = 0; # checksum: #lines
-my $bytes = 0; # checksum: #bytes
-my $sum = 0; # checksum: system V sum
-my $patchdata = 0; # saw patch data
-my $pos = 0; # start of patch data
-my $endkit = 0; # saw end of kit
-my $fail = 0; # failed
+# A long line to test -nvbc ... normally this will cause the previous line to move left
+ my $lines = 0; # checksum: #lines
+ my $bytes = 0; # checksum: #bytes
+ my $sum = 0; # checksum: system V sum
+ my $patchdata = 0; # saw patch data
+ my $pos = 0; # start of patch data
+ # a hanging side comment
+ my $endkit = 0; # saw end of kit
+ my $fail = 0; # failed
+}
+++ /dev/null
-# simple vertical alignment of '=' and '#'
-my $lines = 0; # checksum: #lines
-my $bytes = 0; # checksum: #bytes
-my $sum = 0; # checksum: system V sum
-my $patchdata = 0; # saw patch data
-my $pos = 0; # start of patch data
-my $endkit = 0; # saw end of kit
-my $fail = 0; # failed
-
--- /dev/null
+{
+ # simple vertical alignment of '=' and '#'
+# A long line to test -nvbc ... normally this will cause the previous line to move left
+ my $lines = 0; # checksum: #lines
+ my $bytes = 0; # checksum: #bytes
+ my $sum = 0; # checksum: system V sum
+ my $patchdata = 0; # saw patch data
+ my $pos = 0; # start of patch data
+ # a hanging side comment
+ my $endkit = 0; # saw end of kit
+ my $fail = 0; # failed
+}
+
--- /dev/null
+{
+ # simple vertical alignment of '=' and '#'
+# A long line to test -nvbc ... normally this will cause the previous line to move left
+ my $lines = 0; # checksum: #lines
+ my $bytes = 0; # checksum: #bytes
+ my $sum = 0; # checksum: system V sum
+ my $patchdata = 0; # saw patch data
+ my $pos = 0; # start of patch data
+ # a hanging side comment
+ my $endkit = 0; # saw end of kit
+ my $fail = 0; # failed
+}
+
--- /dev/null
+{
+# simple vertical alignment of '=' and '#'
+# A long line to test -nvbc ... normally this will cause the previous line to move left
+ my $lines = 0; # checksum: #lines
+ my $bytes = 0; # checksum: #bytes
+ my $sum = 0; # checksum: system V sum
+ my $patchdata = 0; # saw patch data
+ my $pos = 0; # start of patch data
+ # a hanging side comment
+ my $endkit = 0; # saw end of kit
+ my $fail = 0; # failed
+}
+
+{
# simple vertical alignment of '=' and '#'
+# A long line to test -nvbc ... normally this will cause the previous line to move left
my $lines = 0; # checksum: #lines
my $bytes = 0; # checksum: #bytes
my $sum = 0; # checksum: system V sum
my $patchdata = 0; # saw patch data
my $pos = 0; # start of patch data
+ # a hanging side comment
my $endkit = 0; # saw end of kit
my $fail = 0; # failed
+}
--- /dev/null
+-nvsc -nvbc -msc=2
../snippets24.t git51.def
../snippets24.t git51.git51
../snippets24.t pretok.def
+../snippets25.t novalign.def
+../snippets25.t novalign.novalign
../snippets3.t ce_wn1.ce_wn
../snippets3.t ce_wn1.def
../snippets3.t colin.colin
../snippets9.t rt98902.def
../snippets9.t rt98902.rt98902
../snippets9.t rt99961.def
-../snippets25.t novalign.def
-../snippets25.t novalign.novalign
+../snippets25.t novalign.novalign1
+../snippets25.t novalign.novalign2
+../snippets25.t novalign.novalign3
# Contents:
#1 novalign.def
-#2 novalign.novalign
+#2 novalign.novalign1
+#3 novalign.novalign2
+#4 novalign.novalign3
# To locate test #13 you can search for its name or the string '#13'
# BEGIN SECTION 1: Parameter combinations #
###########################################
$rparams = {
- 'def' => "",
- 'novalign' => "-novalign",
+ 'def' => "",
+ 'novalign1' => "-novalign",
+ 'novalign2' => "-nvsc -nvbc -msc=2",
+ 'novalign3' => "-nvc",
};
############################
$rsources = {
'novalign' => <<'----------',
+{
# simple vertical alignment of '=' and '#'
+# A long line to test -nvbc ... normally this will cause the previous line to move left
my $lines = 0; # checksum: #lines
my $bytes = 0; # checksum: #bytes
my $sum = 0; # checksum: system V sum
my $patchdata = 0; # saw patch data
my $pos = 0; # start of patch data
+ # a hanging side comment
my $endkit = 0; # saw end of kit
my $fail = 0; # failed
+}
----------
};
source => "novalign",
params => "def",
expect => <<'#1...........',
+{
# simple vertical alignment of '=' and '#'
-my $lines = 0; # checksum: #lines
-my $bytes = 0; # checksum: #bytes
-my $sum = 0; # checksum: system V sum
-my $patchdata = 0; # saw patch data
-my $pos = 0; # start of patch data
-my $endkit = 0; # saw end of kit
-my $fail = 0; # failed
+# A long line to test -nvbc ... normally this will cause the previous line to move left
+ my $lines = 0; # checksum: #lines
+ my $bytes = 0; # checksum: #bytes
+ my $sum = 0; # checksum: system V sum
+ my $patchdata = 0; # saw patch data
+ my $pos = 0; # start of patch data
+ # a hanging side comment
+ my $endkit = 0; # saw end of kit
+ my $fail = 0; # failed
+}
#1...........
},
- 'novalign.novalign' => {
+ 'novalign.novalign1' => {
source => "novalign",
- params => "novalign",
+ params => "novalign1",
expect => <<'#2...........',
-# simple vertical alignment of '=' and '#'
-my $lines = 0; # checksum: #lines
-my $bytes = 0; # checksum: #bytes
-my $sum = 0; # checksum: system V sum
-my $patchdata = 0; # saw patch data
-my $pos = 0; # start of patch data
-my $endkit = 0; # saw end of kit
-my $fail = 0; # failed
+{
+ # simple vertical alignment of '=' and '#'
+# A long line to test -nvbc ... normally this will cause the previous line to move left
+ my $lines = 0; # checksum: #lines
+ my $bytes = 0; # checksum: #bytes
+ my $sum = 0; # checksum: system V sum
+ my $patchdata = 0; # saw patch data
+ my $pos = 0; # start of patch data
+ # a hanging side comment
+ my $endkit = 0; # saw end of kit
+ my $fail = 0; # failed
+}
#2...........
},
+
+ 'novalign.novalign2' => {
+ source => "novalign",
+ params => "novalign2",
+ expect => <<'#3...........',
+{
+ # simple vertical alignment of '=' and '#'
+# A long line to test -nvbc ... normally this will cause the previous line to move left
+ my $lines = 0; # checksum: #lines
+ my $bytes = 0; # checksum: #bytes
+ my $sum = 0; # checksum: system V sum
+ my $patchdata = 0; # saw patch data
+ my $pos = 0; # start of patch data
+ # a hanging side comment
+ my $endkit = 0; # saw end of kit
+ my $fail = 0; # failed
+}
+
+#3...........
+ },
+
+ 'novalign.novalign3' => {
+ source => "novalign",
+ params => "novalign3",
+ expect => <<'#4...........',
+{
+# simple vertical alignment of '=' and '#'
+# A long line to test -nvbc ... normally this will cause the previous line to move left
+ my $lines = 0; # checksum: #lines
+ my $bytes = 0; # checksum: #bytes
+ my $sum = 0; # checksum: system V sum
+ my $patchdata = 0; # saw patch data
+ my $pos = 0; # start of patch data
+ # a hanging side comment
+ my $endkit = 0; # saw end of kit
+ my $fail = 0; # failed
+}
+
+#4...........
+ },
};
my $ntests = 0 + keys %{$rtests};