]> git.donarmstrong.com Git - perltidy.git/commitdiff
change default from -xbtl=kt to -xbtl=k
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 21 Jun 2023 21:37:48 +0000 (14:37 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 21 Jun 2023 21:37:48 +0000 (14:37 -0700)
bin/perltidy
dev-bin/perltidy_random_setup.pl
lib/Perl/Tidy/Formatter.pm
t/snippets/expect/xbt.xbt1
t/snippets/expect/xbt.xbt2
t/snippets/xbt2.par
t/snippets28.t

index cf4a24250c950dcc50e35c98510ca5b5e60c9dbf..8b2248a6f86f37723f6ba096edb040cb2f517c87 100755 (executable)
@@ -1246,53 +1246,77 @@ There are two controls for spacing within curly braces in this scheme, namely
 B<-block-brace-tightness=n> for code block braces and B<-brace-tightness=n> for
 all other braces.
 
-Curly braces which are considered by perltidy to contain code blocks for
-formatting purposes exclude some of the code blocks used by Perl mainly for
-isolating terms. These include curly braces following a keyword where an
-indirect object might occur, or curly braces following a type symbol.  For
-example, perltidy does not mark the following braces as code block braces:
+There is a little fuzziness in this division of brace types though because the
+curly braces considered by perltidy to contain code blocks for formatting
+purposes, such as highlighting code structure, exclude some of the small code
+blocks used by Perl mainly for isolating terms.  These include curly braces
+following a keyword where an indirect object might occur, or curly braces
+following a type symbol.  For example, perltidy does not mark the following
+braces as code block braces:
 
     print {*STDERR} $message;
-    return @{$self};
+    return ${$foo};
 
-Consequently, the spacing within these small braced containers follows the flag
-B<--brace-tightness=n> rather than B<--block-brace-tightness=n>, as one might
-expect.
+Consequently, the spacing within these small braced containers by default
+follows the flag B<--brace-tightness=n> rather than
+B<--block-brace-tightness=n>, as one might expect.
 
-If desired, these small blocks can be made to instead follow the spacing
-defined by the B<--block-brace-tightness=n> flag by seting
-B<--extended-block-tightness>.
+If desired, small blocks such as these can be made to instead follow the
+spacing defined by the B<--block-brace-tightness=n> flag by seting
+B<--extended-block-tightness>.  The specific types of small blocks to which
+this parameter applies is controlled by a companion control parameter,
+described in the next section.
 
 Note that if the two flags B<-bbt=n> and B<-bt=n> have the same value
 B<n> then there would be no reason to set this flag.
 
 =item B<-xbtl=s>,   B<--extended-block-tightness-list=s>
 
-By default, the previous parameter B<-xbt> applies to curly braces preceded by
-the keywords
+The previous parameter B<-xbt> can be made to apply curly braces preceded by
+any of the keywords
 
     print printf exec system say
 
-and by the special symbols
+and/or the special symbols
 
     $ @ % & * $#
 
-This default behavior can be changed as follows.  To restrict B<-xbt> to apply
-to just the above keywords use
+The parameter string B<s> may contain a selection of these keywords and symbols
+to indicate the brace types to which B<-xbt> applies.  For convenience, all of
+the keywords can be selected with 'k', and all of the special symbols
+can be selected with 't'.  The default is equivalent to B<-xbtl='k'>, which
+selects all of the keywords.
 
-   -xbtl=k
+Examples:
 
-and to restrict it to apply to just the above special type symbols use
+   -xbtl='k'          # selects just the keywords [DEFAULT]
+   -xbtl="t"          # selects just the special type symbols
+   -xbtl="k t"        # selects all keywords and symbols, or more simply
+   -xbtl="kt"         # selects all keywords and symbols
+   -xbtl="print say"  # selects just keywords B<print> and B<say>:
 
-   -xbtl=t
+Here are some formatting examples using the default values of B<-bt=n> and
+B<-bbt=n>. Note that in these examples B<$ref> is in block braces but B<$key>
+is not.
 
-More generally, to restrict it to specific keywords or type symbols in the
-above lists, enter them in the parameter list B<s>. For example, the following
-restricts it apply to just the keywords B<print> and B<say>:
+    # default formatting
+    print {*STDERR} $message;
+    my $refalue = ${$ref}{$key};
+
+    # perltidy -xbt           or
+    # perltidy -xbt -xbtl=k
+    print { *STDERR } $message;
+    my $refalue = ${$ref}{$key};
+
+    # perltidy -xbt -xbtl=t
+    print {*STDERR} $message;
+    my $refalue = ${ $ref }{$key};
 
-   -xbtl="print say"
+    # perltidy -xbt -xbtl=kt
+    print { *STDERR } $message;
+    my $refalue = ${ $ref }{$key};
 
-Note that this parameter merely changes the way that the parameter
+Finally, note that this parameter merely changes the way that the parameter
 B<--extended-block-tightness> works. It has no effect unless
 B<--extended-block-tightness> is actually set.
 
index 878067a16259493cbb3862304edec4bf83163eec..7befb70f73c14eab6f9789f51301958f79a95c63 100755 (executable)
@@ -1126,6 +1126,7 @@ EOM
         my %option_range = (
             'format'             => [ 'tidy', 'html' ],    #, 'user' ],
             'output-line-ending' => [ 'dos',  'win', 'mac', 'unix' ],
+            'extended-block-tightness-list' => [ 'k', 't', 'kt' ],
 
             'space-backslash-quote'         => [ 0, 2 ],
             'block-brace-tightness'         => [ 0, 2 ],
index 6e9a1ea7a82814daf43c73edf70eb3eb1cf63e80..1de8556d6682b0d379da537d89c5a5583ca74847 100644 (file)
@@ -2162,6 +2162,8 @@ sub initialize_space_after_keyword {
 
 sub initialize_extended_block_tightness_list {
 
+    # Setup the control hash for --extended-block-tightness
+
     # keywords taking indirect objects:
     my @k_list = keys %is_indirect_object_taker;
 
@@ -2169,11 +2171,13 @@ sub initialize_extended_block_tightness_list {
     my @t_list = qw($ @ % & *);
     push @t_list, '$#';
 
-    # Set the default to include all keywords ant types.
+    my @all = ( @k_list, @t_list );
+
     # We will build the selection in %hash
+    # By default the option is 'on' for keywords only (-xbtl='k')
     my %hash;
-    my @all = ( @k_list, @t_list );
-    @hash{@all} = (1) x scalar(@all);
+    @hash{@k_list} = (1) x scalar(@k_list);
+    @hash{@t_list} = (0) x scalar(@t_list);
 
     # This can be overridden with -xbtl="..."
     my $long_name = 'extended-block-tightness-list';
@@ -2200,7 +2204,7 @@ sub initialize_extended_block_tightness_list {
                 @hash{@t_list} = (1) x scalar(@t_list);
             }
 
-            # 'kt' same as 'k' and 't' for convenience (same as default)
+            # 'kt' same as 'k' and 't' for convenience
             elsif ( $word eq 'kt' ) {
                 @hash{@all} = (1) x scalar(@all);
             }
@@ -2218,9 +2222,11 @@ EOM
         }
     }
 
+    # Transfer the result to the global hash
     %extended_block_tightness_list = %hash;
+
     return;
-}
+} ## end sub initialize_extended_block_tightness_list
 
 sub initialize_token_break_preferences {
 
index 1232e9f17662bc7cb900a2caeae8131a6c894172..c2b711eae3ed9fd1e3bdde92a1850a85dd639b25 100644 (file)
@@ -1,10 +1,9 @@
-print { *STDERR } ${ $data_sref };
+print { *STDERR } ${$data_sref};
 say   { *STDERR } dump $c->{cookies};
 $rc = system { "lskdfj" } "lskdfj";
 test !eval { exec { 'notaint' } $TAINT }, 'exec';
-delete ${ "$ {dest}::" }{$name};
-my @matches =
-  @{ $nodes_ref } > 1 ? @{ $nodes_ref }[ 1 .. $#{ $nodes_ref } ] : ();
-%{ $self } = %{ $project };
-*{ $name } = $sub;
-grep { defined &{ ${ "${class}::" }{$_} } } &{ "${class}::Clear" }();
+delete ${"$ {dest}::"}{$name};
+my @matches = @{$nodes_ref} > 1 ? @{$nodes_ref}[ 1 .. $#{$nodes_ref} ] : ();
+%{$self} = %{$project};
+*{$name} = $sub;
+grep { defined &{ ${"${class}::"}{$_} } } &{"${class}::Clear"}();
index c2b711eae3ed9fd1e3bdde92a1850a85dd639b25..1232e9f17662bc7cb900a2caeae8131a6c894172 100644 (file)
@@ -1,9 +1,10 @@
-print { *STDERR } ${$data_sref};
+print { *STDERR } ${ $data_sref };
 say   { *STDERR } dump $c->{cookies};
 $rc = system { "lskdfj" } "lskdfj";
 test !eval { exec { 'notaint' } $TAINT }, 'exec';
-delete ${"$ {dest}::"}{$name};
-my @matches = @{$nodes_ref} > 1 ? @{$nodes_ref}[ 1 .. $#{$nodes_ref} ] : ();
-%{$self} = %{$project};
-*{$name} = $sub;
-grep { defined &{ ${"${class}::"}{$_} } } &{"${class}::Clear"}();
+delete ${ "$ {dest}::" }{$name};
+my @matches =
+  @{ $nodes_ref } > 1 ? @{ $nodes_ref }[ 1 .. $#{ $nodes_ref } ] : ();
+%{ $self } = %{ $project };
+*{ $name } = $sub;
+grep { defined &{ ${ "${class}::" }{$_} } } &{ "${class}::Clear" }();
index 2a4dc0e383eef405048ec2fa4a614c67a44cc175..5471b127531bb26ca693c0d0cec159a4778e6ec9 100644 (file)
@@ -1 +1 @@
--xbt -xbtl=k
+-xbt -xbtl=kt
index f0c547bd91592314d6bc1487cfc745dbd7ff35b6..7bd31a190f7982bceb3b7dda7b53ae379bef60ca 100644 (file)
@@ -35,7 +35,7 @@ BEGIN {
 -olbxl='*'
 ----------
         'xbt1' => "-xbt",
-        'xbt2' => "-xbt -xbtl=k",
+        'xbt2' => "-xbt -xbtl=kt",
         'xbt3' => <<'----------',
 -xbt -bbt=2 -xbtl="print say t"
 ----------
@@ -258,16 +258,15 @@ grep { defined &{ ${"${class}::"}{$_} } } &{"${class}::Clear"}();
             source => "xbt",
             params => "xbt1",
             expect => <<'#9...........',
-print { *STDERR } ${ $data_sref };
+print { *STDERR } ${$data_sref};
 say   { *STDERR } dump $c->{cookies};
 $rc = system { "lskdfj" } "lskdfj";
 test !eval { exec { 'notaint' } $TAINT }, 'exec';
-delete ${ "$ {dest}::" }{$name};
-my @matches =
-  @{ $nodes_ref } > 1 ? @{ $nodes_ref }[ 1 .. $#{ $nodes_ref } ] : ();
-%{ $self } = %{ $project };
-*{ $name } = $sub;
-grep { defined &{ ${ "${class}::" }{$_} } } &{ "${class}::Clear" }();
+delete ${"$ {dest}::"}{$name};
+my @matches = @{$nodes_ref} > 1 ? @{$nodes_ref}[ 1 .. $#{$nodes_ref} ] : ();
+%{$self} = %{$project};
+*{$name} = $sub;
+grep { defined &{ ${"${class}::"}{$_} } } &{"${class}::Clear"}();
 #9...........
         },
 
@@ -275,15 +274,16 @@ grep { defined &{ ${ "${class}::" }{$_} } } &{ "${class}::Clear" }();
             source => "xbt",
             params => "xbt2",
             expect => <<'#10...........',
-print { *STDERR } ${$data_sref};
+print { *STDERR } ${ $data_sref };
 say   { *STDERR } dump $c->{cookies};
 $rc = system { "lskdfj" } "lskdfj";
 test !eval { exec { 'notaint' } $TAINT }, 'exec';
-delete ${"$ {dest}::"}{$name};
-my @matches = @{$nodes_ref} > 1 ? @{$nodes_ref}[ 1 .. $#{$nodes_ref} ] : ();
-%{$self} = %{$project};
-*{$name} = $sub;
-grep { defined &{ ${"${class}::"}{$_} } } &{"${class}::Clear"}();
+delete ${ "$ {dest}::" }{$name};
+my @matches =
+  @{ $nodes_ref } > 1 ? @{ $nodes_ref }[ 1 .. $#{ $nodes_ref } ] : ();
+%{ $self } = %{ $project };
+*{ $name } = $sub;
+grep { defined &{ ${ "${class}::" }{$_} } } &{ "${class}::Clear" }();
 #10...........
         },