## 2020 01 10.01
+ - Added a parameter --logical-padding or -lop to allow logical padding
+ to be turned off. Requested by git #29. This flag is on by default.
+ The man pages have examples.
+
- Added a parameter -kpit=n to control spaces inside of parens following
certain keywords, requested in git#26. This flag is off by default.
separately.
- Added --character-encoding=guess or -guess to have perltidy guess
- if a file is encoded as -utf8 or some older single-byte encoding. This
- is useful when processing a mixture of file types, such as utf8 and
- latin-1. Also, specific encodings of input files other than utf8 may
- now be given, for example --character-encoding=euc-jp. For a
- description of the guessing method see the man pages.
+ if a file (or other input stream) is encoded as -utf8 or some
+ older single-byte encoding. This is useful when processing a mixture
+ of file types, such as utf8 and latin-1.
Please Note: The default encoding has been set to be 'guess'
instead of 'none'. I do not like to change defaults, but this seems like
- the right choice, since it should make perltidy work properly with both
- older latin-1 and newer utf8 files. I have done extensive testing and
- so far haven't found any problems.
+ the best choice, since it should make perltidy work properly with both
+ utf8 files and older latin-1 files. The guess mode uses Encode::Guess,
+ which is included in standard perl distributions, and only tries to
+ guess if a file is utf8 or not, never any other encoding. If the guess is
+ utf8, and if the file successfully decodes as utf8, then it the encoding
+ is assumed to be utf8. Otherwise, no encoding is assumed.
+ I have done extensive testing and have not detected any problems with
+ this guess method. If you do not want to use this new default guess mode,
+ or have a problem with it, you can set --character-encoding=none
+ (the previous default) or --character-encoding=utf8 (if you deal
+ with utf8 files).
+
+ - Specific encodings of input files other than utf8 may now be given, for
+ example --character-encoding=euc-jp.
- Fix for git#22, Preserve function signature on a single line. An
unwanted line break was being introduced when a closing signature paren
.pre-commit-hooks.yaml
+bbs.t
bin/perltidy
BUGS.md
CHANGES.md
examples/perlcomment.pl
examples/perllinetype.pl
examples/perlmask.pl
+examples/perltidy.DEBUG
examples/perltidy_okw.pl
examples/perltidyrc_dump.pl
examples/perlxmltok.pl
MANIFEST This list of files
pm2pl
README.md
-t/filter_example.t.SKIP
+t/atee.t
+t/filter_example.t
t/snippets1.t
t/snippets10.t
t/snippets11.t
t/snippets15.t
t/snippets16.t
t/snippets17.t
+t/snippets18.t
+t/snippets19.t
t/snippets2.t
+t/snippets20.t
+t/snippets21.t
t/snippets3.t
t/snippets4.t
t/snippets5.t
t/testss.t
t/testwide.pl.src
t/testwide.t
+t/testwide.t.tdy
the spaces inside parens following 'if', 'else', and 'while' keywords to
follow the tightness value indicated by the B<-kpit=2> flag.
+=item B<-lop> or B<--logical-padding>
+
+In the following example some extra space has been inserted on the second
+line between the two open parens. This extra space is called "logical padding"
+and is intended to help align similar things vertically in some logical
+or ternary expressions.
+
+ # perltidy [default formatting]
+ $same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+Note that this is considered to be a different operation from "vertical
+alignment" because space at just one line is being adjusted, whereas in
+"vertical alignment" the spaces at all lines are being adjusted. So it sort of
+a local version of vertical alignment.
+
+Here is an example involving a ternary operator:
+
+ # perltidy [default formatting]
+ $bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;
+
+This behavior is controlled with the flag B<--logical-padding>, which is set
+'on' by default. If it is not desired it can be turned off using
+B<--nological-padding> or B<-nlop>. The above two examples become, with
+B<-nlop>:
+
+ # perltidy -nlop
+ $same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+ # perltidy -nlop
+ $bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;
+
+
=item Trimming whitespace around C<qw> quotes
B<-tqw> or B<--trim-qw> provide the default behavior of trimming
normally be necessary, but was added for testing purposes, because in
some versions of perl, trimming C<qw> quotes changes the syntax tree.
-=item B<-sbq=n> or B<--space-backslash-quote=n>
+=item b<-sbq=n> or b<--space-backslash-quote=n>
-Lines like
+lines like
$str1=\"string1";
$str2=\'string2';
can confuse syntax highlighters unless a space is included between the backslash and the single or double quotation mark.
-This can be controlled with the value of B<n> as follows:
+this can be controlled with the value of b<n> as follows:
-sbq=0 means no space between the backslash and quote
-sbq=1 means follow the example of the source code
<h2>2020 01 10.01</h2>
-<pre><code>- Added fix for git#25, improve vertical alignment for long lists with
+<pre><code>- Added a parameter --logical-padding or -lop to allow logical padding
+ to be turned off. Requested by git #29. This flag is on by default.
+ The man pages have examples.
+
+- Added a parameter -kpit=n to control spaces inside of parens following
+ certain keywords, requested in git#26. This flag is off by default.
+
+- Added fix for git#25, improve vertical alignment for long lists with
varying numbers of items per line.
- calls to the module Perl::Tidy can now capture any output produced
separately.
- Added --character-encoding=guess or -guess to have perltidy guess
- if a file is encoded as -utf8 or some older single-byte encoding. This
- is useful when processing a mixture of file types, such as utf8 and
- latin-1. Also, specific encodings of input files other than utf8 may
- now be given, for example --character-encoding=euc-jp. For a
- description of the guessing method see the man pages.
+ if a file (or other input stream) is encoded as -utf8 or some
+ older single-byte encoding. This is useful when processing a mixture
+ of file types, such as utf8 and latin-1.
Please Note: The default encoding has been set to be 'guess'
instead of 'none'. I do not like to change defaults, but this seems like
- the right choice, since it should make perltidy work properly with both
- older latin-1 and newer utf8 files. I have done extensive testing and
- so far haven't found any problems.
+ the best choice, since it should make perltidy work properly with both
+ utf8 files and older latin-1 files. The guess mode uses Encode::Guess,
+ which is included in standard perl distributions, and only tries to
+ guess if a file is utf8 or not, never any other encoding. If the guess is
+ utf8, and if the file successfully decodes as utf8, then it the encoding
+ is assumed to be utf8. Otherwise, no encoding is assumed.
+ I have done extensive testing and have not detected any problems with
+ this guess method. If you do not want to use this new default guess mode,
+ or have a problem with it, you can set --character-encoding=none
+ (the previous default) or --character-encoding=utf8 (if you deal
+ with utf8 files).
+
+- Specific encodings of input files other than utf8 may now be given, for
+ example --character-encoding=euc-jp.
- Fix for git#22, Preserve function signature on a single line. An
unwanted line break was being introduced when a closing signature paren
<p>For example, the commands <code>-kpitl="if else while" -kpit=2</code> will cause the just the spaces inside parens following 'if', 'else', and 'while' keywords to follow the tightness value indicated by the <b>-kpit=2</b> flag.</p>
+</dd>
+<dt id="lop-or---logical-padding"><b>-lop</b> or <b>--logical-padding</b></dt>
+<dd>
+
+<p>In the following example some extra space has been inserted on the second line between the two open parens. This extra space is called "logical padding" and is intended to help align similar things vertically in some logical or ternary expressions.</p>
+
+<pre><code> # perltidy [default formatting]
+ $same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );</code></pre>
+
+<p>Note that this is considered to be a different operation from "vertical alignment" because space at just one line is being adjusted, whereas in "vertical alignment" the spaces at all lines are being adjusted. So it sort of a local version of vertical alignment.</p>
+
+<p>Here is an example involving a ternary operator:</p>
+
+<pre><code> # perltidy [default formatting]
+ $bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;</code></pre>
+
+<p>This behavior is controlled with the flag <b>--logical-padding</b>, which is set 'on' by default. If it is not desired it can be turned off using <b>--nological-padding</b> or <b>-nlop</b>. The above two examples become, with <b>-nlop</b>:</p>
+
+<pre><code> # perltidy -nlop
+ $same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+ # perltidy -nlop
+ $bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;</code></pre>
+
</dd>
<dt id="Trimming-whitespace-around-qw-quotes">Trimming whitespace around <code>qw</code> quotes</dt>
<dd>
<p><b>-ntqw</b> or <b>--notrim-qw</b> cause leading and trailing whitespace around multi-line <code>qw</code> quotes to be left unchanged. This option will not normally be necessary, but was added for testing purposes, because in some versions of perl, trimming <code>qw</code> quotes changes the syntax tree.</p>
</dd>
-<dt id="sbq-n-or---space-backslash-quote-n"><b>-sbq=n</b> or <b>--space-backslash-quote=n</b></dt>
+<dt id="b-sbq-n-or-b--space-backslash-quote-n">b<-sbq=n> or b<--space-backslash-quote=n></dt>
<dd>
-<p>Lines like</p>
+<p>lines like</p>
<pre><code> $str1=\"string1";
$str2=\'string2';</code></pre>
<p>can confuse syntax highlighters unless a space is included between the backslash and the single or double quotation mark.</p>
-<p>This can be controlled with the value of <b>n</b> as follows:</p>
+<p>this can be controlled with the value of b<n> as follows:</p>
<pre><code> -sbq=0 means no space between the backslash and quote
-sbq=1 means follow the example of the source code
$add_option->( 'delete-semicolons', 'dsm', '!' );
$add_option->( 'keyword-paren-inner-tightness', 'kpit', '=i' );
$add_option->( 'keyword-paren-inner-tightness-list', 'kpitl', '=s' );
+ $add_option->( 'logical-padding', 'lop', '!' );
$add_option->( 'nospace-after-keyword', 'nsak', '=s' );
$add_option->( 'nowant-left-space', 'nwls', '=s' );
$add_option->( 'nowant-right-space', 'nwrs', '=s' );
iterations=1
keep-old-blank-lines=1
keyword-paren-inner-tightness=1
+ logical-padding
long-block-line-count=8
look-for-autoloader
look-for-selfloader
$self->undo_ci( $ri_first, $ri_last );
- $self->set_logical_padding( $ri_first, $ri_last );
+ $self->set_logical_padding( $ri_first, $ri_last )
+ if ( $rOpts->{'logical-padding'} );
# loop to prepare each line for shipment
my $in_comma_list;
--- /dev/null
+# logical padding examples
+$same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+$bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;
+
+lc( $self->mime_attr('content-type')
+ || $self->{MIH_DefaultType}
+ || 'text/plain' );
--- /dev/null
+# logical padding examples
+$same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+$bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;
+
+lc( $self->mime_attr('content-type')
+ || $self->{MIH_DefaultType}
+ || 'text/plain' );
--- /dev/null
+# logical padding examples
+$same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+$bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;
+
+lc( $self->mime_attr('content-type')
+ || $self->{MIH_DefaultType}
+ || 'text/plain' );
../snippets9.t rt98902.def
../snippets9.t rt98902.rt98902
../snippets9.t rt99961.def
+../snippets20.t lop.def
+../snippets21.t lop.lop
#16 kpitl.def
#17 kpitl.kpitl
#18 hanging_side_comments3.def
+#19 lop.def
# To locate test #13 you can search for its name or the string '#13'
);
----------
+ 'lop' => <<'----------',
+# logical padding examples
+$same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+$bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;
+
+lc( $self->mime_attr('content-type')
+ || $self->{MIH_DefaultType}
+ || 'text/plain' );
+----------
+
'outdent' => <<'----------',
my $i;
LOOP: while ( $i = <FOTOS> ) {
}
#18...........
},
+
+ 'lop.def' => {
+ source => "lop",
+ params => "def",
+ expect => <<'#19...........',
+# logical padding examples
+$same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+$bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;
+
+lc( $self->mime_attr('content-type')
+ || $self->{MIH_DefaultType}
+ || 'text/plain' );
+#19...........
+ },
};
my $ntests = 0 + keys %{$rtests};
--- /dev/null
+# Created with: ./make_t.pl
+
+# Contents:
+#1 lop.lop
+
+# To locate test #13 you can search for its name or the string '#13'
+
+use strict;
+use Test::More;
+use Carp;
+use Perl::Tidy;
+my $rparams;
+my $rsources;
+my $rtests;
+
+BEGIN {
+
+ ###########################################
+ # BEGIN SECTION 1: Parameter combinations #
+ ###########################################
+ $rparams = { 'lop' => "-nlop", };
+
+ ############################
+ # BEGIN SECTION 2: Sources #
+ ############################
+ $rsources = {
+
+ 'lop' => <<'----------',
+# logical padding examples
+$same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+$bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;
+
+lc( $self->mime_attr('content-type')
+ || $self->{MIH_DefaultType}
+ || 'text/plain' );
+----------
+ };
+
+ ####################################
+ # BEGIN SECTION 3: Expected output #
+ ####################################
+ $rtests = {
+
+ 'lop.lop' => {
+ source => "lop",
+ params => "lop",
+ expect => <<'#1...........',
+# logical padding examples
+$same =
+ ( ( $aP eq $bP )
+ && ( $aS eq $bS )
+ && ( $aT eq $bT )
+ && ( $a->{'title'} eq $b->{'title'} )
+ && ( $a->{'href'} eq $b->{'href'} ) );
+
+$bits =
+ $top > 0xffff ? 32
+ : $top > 0xff ? 16
+ : $top > 1 ? 8
+ : 1;
+
+lc( $self->mime_attr('content-type')
+ || $self->{MIH_DefaultType}
+ || 'text/plain' );
+#1...........
+ },
+ };
+
+ my $ntests = 0 + keys %{$rtests};
+ plan tests => $ntests;
+}
+
+###############
+# EXECUTE TESTS
+###############
+
+foreach my $key ( sort keys %{$rtests} ) {
+ my $output;
+ my $sname = $rtests->{$key}->{source};
+ my $expect = $rtests->{$key}->{expect};
+ my $pname = $rtests->{$key}->{params};
+ my $source = $rsources->{$sname};
+ my $params = defined($pname) ? $rparams->{$pname} : "";
+ my $stderr_string;
+ my $errorfile_string;
+ my $err = Perl::Tidy::perltidy(
+ source => \$source,
+ destination => \$output,
+ perltidyrc => \$params,
+ argv => '', # for safety; hide any ARGV from perltidy
+ stderr => \$stderr_string,
+ errorfile => \$errorfile_string, # not used when -se flag is set
+ );
+ if ( $err || $stderr_string || $errorfile_string ) {
+ print STDERR "Error output received for test '$key'\n";
+ if ($err) {
+ print STDERR "An error flag '$err' was returned\n";
+ ok( !$err );
+ }
+ if ($stderr_string) {
+ print STDERR "---------------------\n";
+ print STDERR "<<STDERR>>\n$stderr_string\n";
+ print STDERR "---------------------\n";
+ ok( !$stderr_string );
+ }
+ if ($errorfile_string) {
+ print STDERR "---------------------\n";
+ print STDERR "<<.ERR file>>\n$errorfile_string\n";
+ print STDERR "---------------------\n";
+ ok( !$errorfile_string );
+ }
+ }
+ else {
+ if ( !is( $output, $expect, $key ) ) {
+ my $leno = length($output);
+ my $lene = length($expect);
+ if ( $leno == $lene ) {
+ print STDERR
+"#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n";
+ }
+ else {
+ print STDERR
+"#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n";
+ }
+ }
+ }
+}