From: Steve Hancock Date: Wed, 21 Jun 2023 21:37:48 +0000 (-0700) Subject: change default from -xbtl=kt to -xbtl=k X-Git-Tag: 20230309.04~6 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=764c626dcf078e908cefeb660398225a9e19a35f;p=perltidy.git change default from -xbtl=kt to -xbtl=k --- diff --git a/bin/perltidy b/bin/perltidy index cf4a2425..8b2248a6 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -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 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 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 and B: - -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. For example, the following -restricts it apply to just the keywords B and B: + # 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. diff --git a/dev-bin/perltidy_random_setup.pl b/dev-bin/perltidy_random_setup.pl index 878067a1..7befb70f 100755 --- a/dev-bin/perltidy_random_setup.pl +++ b/dev-bin/perltidy_random_setup.pl @@ -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 ], diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 6e9a1ea7..1de8556d 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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 { diff --git a/t/snippets/expect/xbt.xbt1 b/t/snippets/expect/xbt.xbt1 index 1232e9f1..c2b711ea 100644 --- a/t/snippets/expect/xbt.xbt1 +++ b/t/snippets/expect/xbt.xbt1 @@ -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"}(); diff --git a/t/snippets/expect/xbt.xbt2 b/t/snippets/expect/xbt.xbt2 index c2b711ea..1232e9f1 100644 --- a/t/snippets/expect/xbt.xbt2 +++ b/t/snippets/expect/xbt.xbt2 @@ -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" }(); diff --git a/t/snippets/xbt2.par b/t/snippets/xbt2.par index 2a4dc0e3..5471b127 100644 --- a/t/snippets/xbt2.par +++ b/t/snippets/xbt2.par @@ -1 +1 @@ --xbt -xbtl=k +-xbt -xbtl=kt diff --git a/t/snippets28.t b/t/snippets28.t index f0c547bd..7bd31a19 100644 --- a/t/snippets28.t +++ b/t/snippets28.t @@ -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........... },