specified with B<-bm='move'>. The difference is that the older implementation
made the backup by moving the input file to the backup file, and the newer
implementation makes the backup by copying the input file. The newer
-implemenation preserves the file system B<inode> value. This may avoid
+implementation preserves the file system B<inode> value. This may avoid
problems with other software running simultaneously. This change was made
as part of issue B<git #103> at github.
=item B<--want-trailing-commas=s> or B<-wtc=s>, B<--add-trailing-commas> or B<-atc>, and B<--delete-trailing-commas> or B<-dtc>
A trailing comma is a comma following the last item of a list. Perl allows
-trailing commas but they are not required. So using them is optional, but they
-can be useful. In particular, having a comma at the end of each line of a list
-can simplify the use of an editor to reorder or add new lines.
-
-By default, perltidy does not add or delete commas, but it is possible to
-manipulate trailing commas with the following set of three related parameters:
+trailing commas but they are not required. By default, perltidy does not add
+or delete trailing commas, but it is possible to manipulate them with the
+following set of three related parameters:
--want-trailing-commas=s, -wtc=s - defines where trailing commas are wanted
--add-trailing-commas, -atc - gives permission to add trailing commas to match the style wanted
s=1 or * : every list should have a trailing comma
s=m a multi-line list should have a trailing commas
s=b trailing commas should be 'bare' (comma followed by newline)
- s=h trailing commas should be 'bare' for lists of key=>value pairs, or other lists with about one comma per line.
- s=' ', or -wtc not defined : leave trailing commas unchanged [DEFAULT].
+ s=h lists of key=>value pairs, with about one one '=>' and one ',' per line,
+ with a bare trailing comma
+ s=i lists with about one comma per line, with a bare trailing comma
+ s=' ' or -wtc not defined : leave trailing commas unchanged [DEFAULT].
This parameter by itself only indicates the where trailing commas are
wanted. Perltidy only adds these trailing commas if the flag B<--add-trailing-commas>, or B<-atc> is set. And perltidy only removes unwanted trailing commas
Here are some example parameter combinations and their meanings
-wtc=0 -dtc : delete all trailing commas
- -wtc=1 -atc : put trailing commas on all lists
- -wtc=m -atc : all multi-line lists get trailing commas, and
+ -wtc=1 -atc : all lists get trailing commas
+ -wtc=m -atc : all multi-line lists get trailing commas, but
single line lists remain unchanged.
- -wtc=m -dtc : multi-line lists remain unchanged, and
+ -wtc=m -dtc : multi-line lists remain unchanged, but
any trailing commas on single line lists are removed.
-wtc=m -atc -dtc : all multi-line lists get trailing commas, and
any trailing commas on single line lists are removed.
When using these parameters for the first time it is a good idea to practice
on some test scripts and verify that the results are as expected.
+=item *
+
+Since the default behavior is not to add or delete commas, these parameters
+can be useful on a temporary basis for reformatting a script.
+
=back
=item B<-dwic>, B<--delete-weld-interfering-commas>
By default, a method call arrow C<-E<gt>> is considered a candidate for
a breakpoint, but method chains will fill to the line width before a break is
considered. With B<-bom>, breaks before the arrow are preserved, so if you
-have preformatted a method chain:
+have pre-formatted a method chain:
my $q = $rs
->related_resultset('CDs')
# This routine must be called after the alpha and beta stress levels
# have been defined.
- my $rvalid_flags = [qw(0 1 * m b h)];
+ my $rvalid_flags = [qw(0 1 * m b h i)];
my $option = $rOpts->{'want-trailing-commas'};
# List of $trailing_comma_style values:
# undef stable: do not change
- # '0' never want trailing commas
- # '* or 1' always want trailing commas
- # 'm' want multiline trailing commas
- # (i.e., opening and closing tokens are on different lines)
- # 'b' want bare trailing commas ( followed by newline )
- # 'h' add a bare trailing comma to a stable list with about
- # one comma per line (such as Hash list of key=>value pairs).
+ # '0' : no list should have a trailing comma
+ # '1' or '*' : every list should have a trailing comma
+ # 'm' a multi-line list should have a trailing commas
+ # 'b' trailing commas should be 'bare' (comma followed by newline)
+ # 'h' lists of key=>value pairs should have a bare trailing comma
+ # 'i' same as s=h but also include any list with about one comma per line
+ # ' ' or -wtc not defined : leave trailing commas unchanged [DEFAULT].
+
+ # Note: an interesting generalization would be to let an upper case
+ # letter denote the negation of styles 'm', 'b', 'h', 'i'. This might
+ # be useful for undoing operations. It would be implemented as a wrapper
+ # around this routine.
#-----------------------------------------
# No style defined : do not add or delete
#------------------------------------------------------------------
# 'h' matches a bare stable list of key=>values ('h' is for 'Hash')
- # or stable single field lists with about 1 comma per line.
+ # 'i' same as 'h' but also matches stable single field lists with about 1
+ # comma per line.
#------------------------------------------------------------------
- elsif ( $trailing_comma_style eq 'h' ) {
+ elsif ( $trailing_comma_style eq 'h' || $trailing_comma_style eq 'i' ) {
# This is a minimal style which can put trailing commas where
# they are most useful - at the end of simple lists which might,
}
#---------------------------------------------------------
- # Style 'h', Section 1: check for a stable key=>value list
+ # Styles 'h' and 'i': check for a stable key=>value list
#---------------------------------------------------------
my $fat_comma_count = $rtype_count->{'=>'};
}
#--------------------------------------------------------------
- # Style 'h', Section 2: check for a stable single-field list of
+ # Style 'i': check for a stable single-field list of
# items stabilized by blank lines, comments, or the -boc flag
#--------------------------------------------------------------
- elsif (
+ if ( !$match && $trailing_comma_style eq 'i' ) {
# We are looking for lists with <= 1 comma per line
- $line_diff > $comma_count && ( $is_permanently_broken
- || $rOpts_break_at_old_comma_breakpoints )
- )
- {
- $match = 1;
+ if (
+ $line_diff > $comma_count
+ && ( $is_permanently_broken
+ || $rOpts_break_at_old_comma_breakpoints )
+ )
+ {
+ $match = 1;
+ }
}
}
--- /dev/null
+# both single and multiple line lists:
+@LoL = (
+ [ "fred", "barney" ],
+ [ "george", "jane", "elroy" ],
+ [ "homer", "marge", "bart" ] );
+
+# single line
+( $name, $body ) = ( $2, $3 );
+
+# multiline, but not bare
+$text = $main->Scrolled( TextUndo, $yyy, $zzz, $wwwww,
+ selectbackgroundxxxxx => 'yellow' );
+
+# this will pass for 'h'
+my $new = {
+ %$item,
+ text => $leaf,
+ color => 'green',
+};
+
+# and this
+my @list = (
+
+ $xx,
+ $yy );
+
+# does not match 'h'
+$c1->create(
+ 'rectangle', 40, 60, 80, 80,
+ -fill => 'red',
+ -tags => 'rectangle' );
+
+$dasm_frame->Button(
+ -text => 'Locate',
+ -command => sub {
+ $target_binary = $fs->Show( -popover => 'cursor', -create => 1 );
+ } )->pack( -side => 'left' );
+
+my $no_index_1_1 =
+ { 'map' => { ':key' => { name => \&string, list => { value => \&string } } }
+ };
+
../snippets27.t wtc.wtc4
../snippets27.t wtc.wtc5
../snippets27.t wtc.wtc6
+../snippets27.t dwic.def
+../snippets27.t dwic.dwic
../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
-../snippets27.t dwic.def
-../snippets27.t dwic.dwic
+../snippets27.t wtc.wtc7
--wtc=h -atc -dtc -vtc=2
+-wtc=i -atc -dtc -vtc=2
--- /dev/null
+-wtc=h -atc -dtc -vtc=2
#6 wtc.wtc6
#7 dwic.def
#8 dwic.dwic
+#9 wtc.wtc7
# To locate test #13 you can search for its name or the string '#13'
'wtc3' => "-wtc=m -atc",
'wtc4' => "-wtc=m -atc -dtc",
'wtc5' => "-wtc=b -atc -dtc -vtc=2",
- 'wtc6' => "-wtc=h -atc -dtc -vtc=2",
+ 'wtc6' => "-wtc=i -atc -dtc -vtc=2",
+ 'wtc7' => "-wtc=h -atc -dtc -vtc=2",
};
############################
) ] );
#8...........
},
+
+ 'wtc.wtc7' => {
+ source => "wtc",
+ params => "wtc7",
+ expect => <<'#9...........',
+# both single and multiple line lists:
+@LoL = (
+ [ "fred", "barney" ],
+ [ "george", "jane", "elroy" ],
+ [ "homer", "marge", "bart" ] );
+
+# single line
+( $name, $body ) = ( $2, $3 );
+
+# multiline, but not bare
+$text = $main->Scrolled( TextUndo, $yyy, $zzz, $wwwww,
+ selectbackgroundxxxxx => 'yellow' );
+
+# this will pass for 'h'
+my $new = {
+ %$item,
+ text => $leaf,
+ color => 'green',
+};
+
+# and this
+my @list = (
+
+ $xx,
+ $yy );
+
+# does not match 'h'
+$c1->create(
+ 'rectangle', 40, 60, 80, 80,
+ -fill => 'red',
+ -tags => 'rectangle' );
+
+$dasm_frame->Button(
+ -text => 'Locate',
+ -command => sub {
+ $target_binary = $fs->Show( -popover => 'cursor', -create => 1 );
+ } )->pack( -side => 'left' );
+
+my $no_index_1_1 =
+ { 'map' => { ':key' => { name => \&string, list => { value => \&string } } }
+ };
+
+#9...........
+ },
};
my $ntests = 0 + keys %{$rtests};