From 880633cc084e9d787eb9f760d3851c5d660db17c Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Tue, 24 May 2022 15:27:10 -0700 Subject: [PATCH] New upstream version 20220217 --- BUGS.md | 9 - CHANGES.md | 204 +- MANIFEST | 9 +- META.json | 2 +- META.yml | 2 +- README.md | 6 +- bin/perltidy | 1105 +- docs/BugLog.html | 1082 +- docs/ChangeLog.html | 202 +- docs/Tidy.html | 103 +- docs/perltidy.html | 522 +- examples/fix-scbb-csc-bug.pl | 99 - lib/Perl/Tidy.pm | 367 +- lib/Perl/Tidy.pod | 154 +- lib/Perl/Tidy/Debugger.pm | 2 +- lib/Perl/Tidy/DevNull.pm | 2 +- lib/Perl/Tidy/Diagnostics.pm | 2 +- lib/Perl/Tidy/FileWriter.pm | 44 +- lib/Perl/Tidy/Formatter.pm | 13352 ++++++++++++------- lib/Perl/Tidy/HtmlWriter.pm | 8 +- lib/Perl/Tidy/IOScalar.pm | 2 +- lib/Perl/Tidy/IOScalarArray.pm | 2 +- lib/Perl/Tidy/IndentationItem.pm | 50 +- lib/Perl/Tidy/LineBuffer.pm | 2 +- lib/Perl/Tidy/LineSink.pm | 2 +- lib/Perl/Tidy/LineSource.pm | 2 +- lib/Perl/Tidy/Logger.pm | 92 +- lib/Perl/Tidy/Tokenizer.pm | 702 +- lib/Perl/Tidy/VerticalAligner.pm | 562 +- lib/Perl/Tidy/VerticalAligner/Alignment.pm | 21 +- lib/Perl/Tidy/VerticalAligner/Line.pm | 9 +- pm2pl | 99 +- t/.gitattributes | 1 + t/snippets17.t | 40 +- t/snippets18.t | 9 +- t/snippets19.t | 21 +- t/snippets20.t | 29 +- t/snippets22.t | 7 +- t/snippets24.t | 116 +- t/snippets25.t | 845 ++ t/snippets26.t | 263 + t/testwide-passthrough.pl.src | 5 + t/testwide-passthrough.t.SKIP | 130 + t/testwide-tidy.pl.src | 8 + t/testwide-tidy.pl.srctdy | 7 + t/testwide-tidy.t.SKIP | 131 + 46 files changed, 14231 insertions(+), 6202 deletions(-) delete mode 100755 examples/fix-scbb-csc-bug.pl create mode 100644 t/.gitattributes create mode 100644 t/snippets25.t create mode 100644 t/snippets26.t create mode 100644 t/testwide-passthrough.pl.src create mode 100644 t/testwide-passthrough.t.SKIP create mode 100644 t/testwide-tidy.pl.src create mode 100644 t/testwide-tidy.pl.srctdy create mode 100644 t/testwide-tidy.t.SKIP diff --git a/BUGS.md b/BUGS.md index a64b8ae..c88aa6e 100644 --- a/BUGS.md +++ b/BUGS.md @@ -29,15 +29,6 @@ it part of the standard Perl distribution. But for example the following line which uses double brackets to contain single brackets does not render correctly. -## Two iterations are sometimes needed - -Usually the code produced by perltidy on the first pass does not change if it -is run again, but sometimes a second pass will produce some small additional -change. This mainly happens if a major style change is made, particularly when -perltidy is untangling complex ternary statements. Use the iteration parameter -**-it=2** if it is important that the results be unchanged on subsequent passes, -but note that this doubles the run time. - ## Perltidy does not look for here-document targets inside of quoted strings For example, consider the following script diff --git a/CHANGES.md b/CHANGES.md index 8c36f59..41e92d6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,187 @@ # Perltidy Change Log +## 2022 02 17 + + - A new flag, --encode-output-strings, or -eos, has been added to resolve + issue git #83. This issue involves the interface between Perl::Tidy and + calling programs, and Code::TidyAll (tidyall) in particular. The problem + is that perltidy by default returns decoded character strings, but + tidyall expects encoded strings. This flag provides a fix for that. + + So, tidyall users who process encoded (utf8) files should update to this + version of Perl::Tidy and use -eos for tidyall. For further info see: + + https://github.com/houseabsolute/perl-code-tidyall/issues/84, and + https://github.com/perltidy/perltidy/issues/83 + + If there are other applications having utf8 problems at the interface + with Perl::Tidy, this flag probably may need to be set. + + - The default value of the new flag, --encode-output-strings, -eos, is currently + -neos BUT THIS MAY CHANGE in a future release because the current + default is inconvenient. So authors of programs which receive character + strings back from Perl::Tidy should set this flag, if necessary, + to avoid any problems when the default changes. For more information see the + above links and the Perl::Tidy man pages for example coding. + + - The possible values of the string 's' for the flag '--character-encoding=s' + have been limited to 'utf8' (or UTF-8), 'none', or 'guess'. Previously an + arbitrary encoding could also be specified, but as a result of discussions + regarding git #83 it became clear that this could cause trouble + since the output encoding was still restricted to UTF-8. Users + who need to work in other encodings can write a short program calling + Perl::Tidy with pre- and post-processing to handle encoding/decoding. + + - A new flag --break-after-labels=i, or -bal=i, was added for git #86. This + controls line breaks after labels, to provide a uniform style, as follows: + + -bal=0 follows the input line breaks [DEFAULT] + -bal=1 always break after a label + -bal=2 never break after a label + + For example: + + # perltidy -bal=1 + INIT: + { + $xx = 1.234; + } + + # perltidy -bal=2 + INIT: { + $xx = 1.234; + } + + - Fix issue git #82, an error handling something like ${bareword} in a + possible indirect object location. Perl allows this, now perltidy does too. + + - The flags -kbb=s or --keep-old-breakpoints-before=s, and its counterpart + -kba=s or --keep-old-breakpoints-after=s have expanded functionality + for the container tokens: { [ ( } ] ). The updated man pages have + details. + + - Two new flags have been added to provide finer vertical alignment control, + --valign-exclusion-list=s (-vxl=s) and --valign-inclusion-list=s (-vil=s). + This has been requested several times, most recently in git #79, and it + finally got done. For example, -vil='=>' means just align on '=>'. + + - A new flag -gal=s, --grep-alias-list=s, has been added as suggested in + git #77. This allows code blocks passed to list operator functions to + be formatted in the same way as a code block passed to grep, map, or sort. + By default, the following list operators in List::Util are included: + + all any first none notall reduce reductions + + They can be changed with the flag -gaxl=s, -grep-alias-exclusion-list=s + + - A new flag -xlp has been added which can be set to avoid most of the + limitations of the -lp flag regarding side comments, blank lines, and + code blocks. See the man pages for more info. This fixes git #64 and git #74. + The older -lp flag still works. + + - A new flag -lpil=s, --line-up-parentheses-inclusion-list=s, has been added + as an alternative to -lpxl=s, --line-up-parentheses-exclusion-list=s. + It supplies equivalent information but is much easier to describe and use. + It works for both the older -lp version and the newer -xlp. + + - The coding for the older -lp flag has been updated to avoid some problems + and limitations. The new coding allows the -lp indentation style to + mix smoothly with the standard indentation in a single file. Some problems + where -lp and -xci flags were not working well together have been fixed, such + as happened in issue rt140025. As a result of these updates some minor + changes in existing code using the -lp style may occur. + + - This version of perltidy was stress-tested for many cpu hours with + random input parameters. No failures to converge, internal fault checks, + undefined variable references or other irregularities were seen. + + - Numerous minor fixes have been made, mostly very rare formatting + instabilities found in random testing. + +## 2021 10 29 + + - No significant bugs have been found since the last release, but several + minor issues have been fixed. Vertical alignment has been improved for + lists of call args which are not contained within parens (next item). + + - Vertical alignment of function calls without parens has been improved with + the goal of making vertical alignment essentially the same with or + without parens around the call args. Some examples: + + # OLD + mkTextConfig $c, $x, $y, -anchor => 'se', $color; + mkTextConfig $c, $x + 30, $y, -anchor => 's', $color; + mkTextConfig $c, $x + 60, $y, -anchor => 'sw', $color; + mkTextConfig $c, $x, $y + 30, -anchor => 'e', $color; + + # NEW + mkTextConfig $c, $x, $y, -anchor => 'se', $color; + mkTextConfig $c, $x + 30, $y, -anchor => 's', $color; + mkTextConfig $c, $x + 60, $y, -anchor => 'sw', $color; + mkTextConfig $c, $x, $y + 30, -anchor => 'e', $color; + + # OLD + is id_2obj($id), undef, "unregistered object not retrieved"; + is scalar keys %$ob_reg, 0, "object registry empty"; + is register($obj), $obj, "object returned by register"; + is scalar keys %$ob_reg, 1, "object registry nonempty"; + is id_2obj($id), $obj, "registered object retrieved"; + + # NEW + is id_2obj($id), undef, "unregistered object not retrieved"; + is scalar keys %$ob_reg, 0, "object registry empty"; + is register($obj), $obj, "object returned by register"; + is scalar keys %$ob_reg, 1, "object registry nonempty"; + is id_2obj($id), $obj, "registered object retrieved"; + + This will cause some changes in alignment, hopefully for the better, + particularly in test code which often uses numerous parenless function + calls with functions like 'ok', 'is', 'is_deeply', .... + + - Two new parameters were added to control the block types to which the + -bl (--opening-brace-on-new-line) flag applies. The new parameters are + -block-left-list=s, or -bll=s, and --block-left-exclusion-list=s, + or -blxl=s. Previously the -bl flag was 'hardwired' to apply to + nearly all blocks. The default values of the new parameters + retain the the old default behavior but allow it to be changed. + + - The default behavior of the -bli (-brace-left-and-indent) flag has changed + slightly. Previously, if you set -bli, then the -bl flag would also + automatically be set. Consequently, block types which were not included + in the default list for -bli would get -bl formatting. This is no longer done, + and these two styles are now controlled independently. The manual describes + the controls. If you want to recover the exact previous default behavior of + the -bli then add the -bl flag. + + - A partial fix was made for issue for git #74. The -lp formatting style was + being lost when a one-line anonymous sub was followed by a closing brace. + + - Fixed issue git #73, in which the -nfpva flag was not working correctly. + Some unwanted vertical alignments of spaced function perens + were being made. + + - Updated the man pages to clarify the flags -valign and -novalign + for turning vertical alignment on and off (issue git #72). + Added parameters -vc -vsc -vbc for separately turning off vertical + alignment of code, side comments and block comments. + + - Fixed issue git #68, where a blank line following a closing code-skipping + comment, '#>>V', could be lost. + + - This version runs 10 to 15 percent faster on large files than the + previous release due to optimizations made with the help of NYTProf. + + - This version of perltidy was stress-tested for many cpu hours with + random input parameters. No instabilities, internal fault checks, + undefined variable references or other irregularities were seen. + + - Numerous minor fixes have been made, mostly very rare formatting instabilities + found in random testing. An effort has been made to minimize changes to + existing formatting that these fixes produce, but occasional changes + may occur. Many of these updates are listed at: + + https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod + ## 2021 07 17 - This release is being made mainly because of the next item, in which an @@ -16,8 +198,8 @@ comment '#<>V'. This makes code-skipping and format-skipping behave in a similar way: an opening comment without a corresponding closing comment will cause - the rest of a file to be skipped. If there is a question about which lines - are skipped, a .LOG file can be produced with the -g flag and it will have + the rest of a file to be skipped. If there is a question about which lines + are skipped, a .LOG file can be produced with the -g flag and it will have this information. - Removed the limit on -ci=n when -xci is set, reference: rt #136415. @@ -84,14 +266,14 @@ flags and the --line-up-parens flag. - Fixed issue git #54 regarding irregular application of the --break-before-paren - and similar --break-before-xxx flags, in which lists without commas were not + and similar --break-before-xxx flags, in which lists without commas were not being formatted according to these flags. - - Fixed issue git #53. A flag was added to turn off alignment of spaced function + - Fixed issue git #53. A flag was added to turn off alignment of spaced function parens. If the --space-function-paren, -sfp flag is set, a side-effect is that the spaced function parens may get vertically aligned. This can be undesirable, so a new parameter '--function-paren-vertical-alignment', or '-fpva', has been - added to turn this vertical alignment off. The default is '-fpva', so that + added to turn this vertical alignment off. The default is '-fpva', so that existing formatting is not changed. Use '-nfpva' to turn off unwanted vertical alignment. To illustrate the possibilities: @@ -102,7 +284,7 @@ # perltidy -sfp myfun ( $aaa, $b, $cc ); mylongfun ( $a, $b, $c ); - + # perltidy -sfp -nfpva myfun ( $aaa, $b, $cc ); mylongfun ( $a, $b, $c ); @@ -197,9 +379,9 @@ ## 2020 12 01 - - This release is being made primarily to make available a several new formatting - parameters, in particular -xci, -kbb=s, -kba=s, and -wnxl=s. No significant - bugs have been found since the previous release, but numerous minor issues have + - This release is being made primarily to make available a several new formatting + parameters, in particular -xci, -kbb=s, -kba=s, and -wnxl=s. No significant + bugs have been found since the previous release, but numerous minor issues have been found and fixed as listed below. - This version is about 20% faster than the previous version due to optimizations @@ -212,7 +394,7 @@ - Fixed issue git #45, -vtc=n flag was ignored when -wn was set. - - implement request RT #133649, delete-old-newlines selectively. Two parameters, + - implement request RT #133649, delete-old-newlines selectively. Two parameters, -kbb=s or --keep-old-breakpoints-before=s, and -kba=s or --keep-old-breakpoints-after=s @@ -220,7 +402,7 @@ were added to request that old breakpoints be kept before or after selected token types. For example, -kbb='=>' means that newlines before fat commas should be kept. - + - Fix git #44, fix exit status for assert-tidy/untidy. The exit status was always 0 for --assert-tidy if the user had turned off all error messages with the -quiet flag. This has been fixed. diff --git a/MANIFEST b/MANIFEST index 454c8cd..e502f89 100644 --- a/MANIFEST +++ b/MANIFEST @@ -19,7 +19,6 @@ examples/ex_mp.pl examples/filter_example.in examples/filter_example.pl examples/find_naughty.pl -examples/fix-scbb-csc-bug.pl examples/lextest examples/perlcomment.pl examples/perllinetype.pl @@ -56,6 +55,7 @@ Makefile.PL MANIFEST This list of files pm2pl README.md +t/.gitattributes t/atee.t t/filter_example.t t/snippets1.t @@ -75,6 +75,8 @@ t/snippets21.t t/snippets22.t t/snippets23.t t/snippets24.t +t/snippets25.t +t/snippets26.t t/snippets3.t t/snippets4.t t/snippets5.t @@ -86,6 +88,11 @@ t/test-eol.t t/test.t t/testsa.t t/testss.t +t/testwide-passthrough.pl.src +t/testwide-passthrough.t.SKIP +t/testwide-tidy.pl.src +t/testwide-tidy.pl.srctdy +t/testwide-tidy.t.SKIP t/testwide.pl.src t/testwide.t META.yml Module YAML meta-data (added by MakeMaker) diff --git a/META.json b/META.json index 2478d27..d289520 100644 --- a/META.json +++ b/META.json @@ -39,6 +39,6 @@ "web" : "https://github.com/perltidy/perltidy" } }, - "version" : "20210717", + "version" : "20220217", "x_serialization_backend" : "JSON::PP version 4.04" } diff --git a/META.yml b/META.yml index 9f9ba2d..07718a4 100644 --- a/META.yml +++ b/META.yml @@ -19,5 +19,5 @@ no_index: - inc resources: repository: https://github.com/perltidy/perltidy.git -version: '20210717' +version: '20220217' x_serialization_backend: 'CPAN::Meta::YAML version 0.012' diff --git a/README.md b/README.md index bc6a23e..421bc63 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -[![Build Status](https://travis-ci.com/perltidy/perltidy.svg?branch=master)](https://travis-ci.com/perltidy/perltidy) +# Build Status + ++ [![Github Actions Build Status](https://github.com/perltidy/perltidy/actions/workflows/perltest.yml/badge.svg)](https://github.com/perltidy/perltidy/actions) +* [![Travis-CI Build Status](https://travis-ci.com/perltidy/perltidy.svg?branch=master)](https://travis-ci.com/perltidy/perltidy) +* [CPAN Testers](https://www.cpantesters.org/distro/P/Perl-Tidy.html) # Welcome to Perltidy diff --git a/bin/perltidy b/bin/perltidy index 34c6b51..a24aace 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -37,8 +37,8 @@ perltidy - a perl script indenter and reformatter Perltidy reads a perl script and writes an indented, reformatted script. -Many users will find enough information in L<"EXAMPLES"> to get -started. New users may benefit from the short tutorial +Many users will find enough information in L<"EXAMPLES"> to get +started. New users may benefit from the short tutorial which can be found at http://perltidy.sourceforge.net/tutorial.html @@ -51,17 +51,17 @@ existence of an B<-html> flag. Without this flag, the output is passed through a formatter. The default formatting tries to follow the recommendations in perlstyle(1), but it can be controlled in detail with numerous input parameters, which are described in L<"FORMATTING -OPTIONS">. +OPTIONS">. When the B<-html> flag is given, the output is passed through an HTML -formatter which is described in L<"HTML OPTIONS">. +formatter which is described in L<"HTML OPTIONS">. =head1 EXAMPLES perltidy somefile.pl This will produce a file F containing the script reformatted -using the default options, which approximate the style suggested in +using the default options, which approximate the style suggested in perlstyle(1). The source file F is unchanged. perltidy *.pl @@ -91,7 +91,7 @@ GNU Coding Standards for C programs. The output will be F. Execute perltidy on file F, with 3 columns for each level of indentation (B<-i=3>) instead of the default 4 columns. There will not be any tabs in the reformatted script, except for any which already exist in comments, -pod documents, quotes, and here documents. Output will be F. +pod documents, quotes, and here documents. Output will be F. perltidy -i=3 -et=8 somefile.pl @@ -102,7 +102,7 @@ be entabbed with one tab character per 8 spaces. Execute perltidy on file F with all defaults except use "cuddled elses" (B<-ce>) and a maximum line length of 72 columns (B<-l=72>) instead of -the default 80 columns. +the default 80 columns. perltidy -g somefile.pl @@ -127,7 +127,7 @@ it will be created. If it exists, it will not be overwritten. Write an html snippet with only the PRE section to F. This is useful when code snippets are being formatted for inclusion in a -larger web page. No style sheet will be written in this case. +larger web page. No style sheet will be written in this case. perltidy -html -ss >mystyle.css @@ -145,7 +145,7 @@ The entire command line is scanned for options, and they are processed before any files are processed. As a result, it does not matter whether flags are before or after any filenames. However, the relative order of parameters is important, with later parameters overriding the -values of earlier parameters. +values of earlier parameters. For each parameter, there is a long name and a short name. The short names are convenient for keyboard input, while the long names are @@ -171,11 +171,11 @@ The following parameters concern the files which are read and written. =over 4 -=item B<-h>, B<--help> +=item B<-h>, B<--help> Show summary of usage and exit. -=item B<-o>=filename, B<--outfile>=filename +=item B<-o>=filename, B<--outfile>=filename Name of the output file (only if a single input file is being processed). If no output file is specified, and output is not @@ -193,7 +193,7 @@ request outputting to the standard output. For example, perltidy somefile.pl -st >somefile.new.pl -This option may only be used if there is just a single input file. +This option may only be used if there is just a single input file. The default is B<-nst> or B<--nostandard-output>. =item B<-se>, B<--standard-error-output> @@ -205,13 +205,13 @@ output stream instead. This directive may be negated with B<-nse>. Thus, you may place B<-se> in a F<.perltidyrc> and override it when desired with B<-nse> on the command line. -=item B<-oext>=ext, B<--output-file-extension>=ext +=item B<-oext>=ext, B<--output-file-extension>=ext Change the extension of the output file to be F instead of the default F (or F in case the -B<-html> option is used). See L. -=item B<-opath>=path, B<--output-path>=path +=item B<-opath>=path, B<--output-path>=path When perltidy creates a filename for an output file, by default it merely appends an extension to the path and basename of the input file. This @@ -237,17 +237,17 @@ or if it is being specified explicitly with the B<-o=s> parameter. Modify the input file or files in-place and save the original with the extension F<.bak>. Any existing F<.bak> file will be deleted. See next item for changing the default backup extension, and for eliminating the -backup file altogether. +backup file altogether. A B<-b> flag will be ignored if input is from standard input or goes to -standard output, or if the B<-html> flag is set. +standard output, or if the B<-html> flag is set. In particular, if you want to use both the B<-b> flag and the B<-pbp> (--perl-best-practices) flag, then you must put a B<-nst> flag after the B<-pbp> flag because it contains a B<-st> flag as one of its components, which means that output will go to the standard output stream. -=item B<-bext>=ext, B<--backup-file-extension>=ext +=item B<-bext>=ext, B<--backup-file-extension>=ext This parameter serves two purposes: (1) to change the extension of the backup file to be something other than the default F<.bak>, and (2) to indicate @@ -259,7 +259,7 @@ L. A backup file of the source is always written, but you can request that it be deleted at the end of processing if there were no errors. This is risky unless the source code is being maintained with a source code control -system. +system. To indicate that the backup should be deleted include one forward slash, B, in the extension. If any text remains after the slash is removed @@ -274,7 +274,7 @@ Here are some examples: <-bext='/backup'> F<.backup> Delete if no errors <-bext='original/'> F<.original> Delete if no errors -=item B<-w>, B<--warning-output> +=item B<-w>, B<--warning-output> Setting B<-w> causes any non-critical warning messages to be reported as errors. These include messages @@ -282,9 +282,9 @@ about possible pod problems, possibly bad starting indentation level, and cautions about indirect object usage. The default, B<-nw> or B<--nowarning-output>, is not to include these warnings. -=item B<-q>, B<--quiet> +=item B<-q>, B<--quiet> -Deactivate error messages (for running under an editor). +Deactivate error messages (for running under an editor). For example, if you use a vi-style editor, such as vim, you may execute perltidy as a filter from within the editor using something like @@ -295,7 +295,7 @@ where C represents the selected text. Without the B<-q> flag, any error message may mess up your screen, so be prepared to use your "undo" key. -=item B<-log>, B<--logfile> +=item B<-log>, B<--logfile> Save the F<.LOG> file, which has many useful diagnostics. Perltidy always creates a F<.LOG> file, but by default it is deleted unless a program bug is @@ -307,18 +307,18 @@ Set maximum interval between input code lines in the logfile. This purpose of this flag is to assist in debugging nesting errors. The value of C is optional. If you set the flag B<-g> without the value of C, it will be taken to be 1, meaning that every line will be written to the log file. This -can be helpful if you are looking for a brace, paren, or bracket nesting error. +can be helpful if you are looking for a brace, paren, or bracket nesting error. Setting B<-g> also causes the logfile to be saved, so it is not necessary to -also include B<-log>. +also include B<-log>. If no B<-g> flag is given, a value of 50 will be used, meaning that at least every 50th line will be recorded in the logfile. This helps prevent -excessively long log files. +excessively long log files. Setting a negative value of C is the same as not setting B<-g> at all. -=item B<-npro> B<--noprofile> +=item B<-npro> B<--noprofile> Ignore any F<.perltidyrc> command file. Normally, perltidy looks first in your current directory for a F<.perltidyrc> file of parameters. (The format @@ -329,7 +329,7 @@ in your home directory. If you set the B<-npro> flag, perltidy will not look for this file. -=item B<-pro=filename> or B<--profile=filename> +=item B<-pro=filename> or B<--profile=filename> To simplify testing and switching .perltidyrc files, this command may be used to specify a configuration file which will override the default @@ -338,7 +338,7 @@ name of .perltidyrc. There must not be a space on either side of the perltidy -pro=testcfg -would cause file F to be used instead of the +would cause file F to be used instead of the default F<.perltidyrc>. A pathname begins with three dots, e.g. ".../.perltidyrc", indicates that @@ -346,19 +346,19 @@ the file should be searched for starting in the current directory and working upwards. This makes it easier to have multiple projects each with their own .perltidyrc in their root directories. -=item B<-opt>, B<--show-options> +=item B<-opt>, B<--show-options> -Write a list of all options used to the F<.LOG> file. +Write a list of all options used to the F<.LOG> file. Please see B<--dump-options> for a simpler way to do this. -=item B<-f>, B<--force-read-binary> +=item B<-f>, B<--force-read-binary> Force perltidy to process binary files. To avoid producing excessive error messages, perltidy skips files identified by the system as non-text. However, valid perl scripts containing binary data may sometimes be identified as non-text, and this flag forces perltidy to process them. -=item B<-ast>, B<--assert-tidy> +=item B<-ast>, B<--assert-tidy> This flag asserts that the input and output code streams are identical, or in other words that the input code is already 'tidy' according to the formatting @@ -370,26 +370,52 @@ perltidy. This might be useful for certain code maintenance operations. Note: you will not see this message if you have error messages turned off with the -quiet flag. -=item B<-asu>, B<--assert-untidy> +=item B<-asu>, B<--assert-untidy> This flag asserts that the input and output code streams are different, or in other words that the input code is 'untidy' according to the formatting parameters. If this is not the case, an error message noting this is produced. This flag has no other effect on the functioning of perltidy. -=item B<-sal=s>, B<--sub-alias-list=s> +=item B<-sal=s>, B<--sub-alias-list=s> This flag causes one or more words to be treated the same as if they were the keyword 'sub'. The string B contains one or more alias words, separated by spaces or commas. For example, - perltidy -sal='method fun _sub M4' + perltidy -sal='method fun _sub M4' will cause the perltidy to treate the words 'method', 'fun', '_sub' and 'M4' to be treated the same as if they were 'sub'. Note that if the alias words are separated by spaces then the string of words should be placed in quotes. Note that several other parameters accept a list of keywords, including 'sub' (see L). You do not need to include any sub aliases in these lists. Just include keyword 'sub' if you wish, and all aliases are automatically included. +=item B<-gal=s>, B<--grep-alias-list=s> + +This flag allows a code block following an external 'list operator' function to be formatted as if it followed one of the builtin keywords B, B or B. The string B contains the names of one or more such list operators, separated by spaces or commas. + +By 'list operator' is meant a function which is invoked in the form + + word {BLOCK} @list + +Perltidy tries to keep code blocks for these functions intact, since they are usually short, and does not automatically break after the closing brace since a list may follow. It also does some special handling of continuation indentation. + +For example, the code block arguments to functions 'My_grep' and 'My_map' can be given formatting like 'grep' with + + perltidy -gal='My_grep My_map' + +By default, the following list operators in List::Util are automatically included: + + all any first none notall reduce reductions + +Any operators specified with B<--grep-alias-list> are added to this list. +The next parameter can be used to remove words from this default list. + +=item B<-gaxl=s>, B<--grep-alias-exclusion-list=s> + +The B<-gaxl=s> flag provides a method for removing any of the default list operators given above +by listing them in the string B. To remove all of the default operators use B<-gaxl='*'>. + =back =head1 FORMATTING OPTIONS @@ -407,7 +433,7 @@ set of F<.perltidyrc> files to avoid unwanted code tidying. See also L for a way to avoid tidying specific sections of code. -=item B<-i=n>, B<--indent-columns=n> +=item B<-i=n>, B<--indent-columns=n> Use n columns per indentation level (default n=4). @@ -415,7 +441,7 @@ Use n columns per indentation level (default n=4). The default maximum line length is n=80 characters. Perltidy will try to find line break points to keep lines below this length. However, long -quotes and side comments may cause lines to exceed this length. +quotes and side comments may cause lines to exceed this length. The default length of 80 comes from the past when this was the standard CRT screen width. Many programmers prefer to increase this to something like 120. @@ -430,9 +456,9 @@ A problem arises using a fixed maximum line length with very deeply nested code and data structures because eventually the amount of leading whitespace used for indicating indentation takes up most or all of the available line width, leaving little or no space for the actual code or data. One solution is to use -a vary long line length. Another solution is to use the B<-vmll> flag, which +a very long line length. Another solution is to use the B<-vmll> flag, which basically tells perltidy to ignore leading whitespace when measuring the line -length. +length. To be precise, when the B<-vmll> parameter is set, the maximum line length of a line of code will be M+L*I, where @@ -444,7 +470,7 @@ line of code will be M+L*I, where When this flag is set, the choice of breakpoints for a block of code should be essentially independent of its nesting depth. However, the absolute line lengths, including leading whitespace, can still be arbitrarily large. This -problem can be avoided by including the next parameter. +problem can be avoided by including the next parameter. The default is not to do this (B<-nvmll>). @@ -454,7 +480,7 @@ This flag also addresses problems with very deeply nested code and data structures. When the nesting depth exceeds the value B the leading whitespace will be reduced and start at a depth of 1 again. The result is that blocks of code will shift back to the left rather than moving arbitrarily far -to the right. This occurs cyclically to any depth. +to the right. This occurs cyclically to any depth. For example if one level of indentation equals 4 spaces (B<-i=4>, the default), and one uses B<-wc=15>, then if the leading whitespace on a line exceeds about @@ -473,7 +499,7 @@ The default is not to use this, which can also be indicated using B<-wc=0>. Using tab characters will almost certainly lead to future portability and maintenance problems, so the default and recommendation is not to use them. For those who prefer tabs, however, there are two different -options. +options. Except for possibly introducing tab indentation characters, as outlined below, perltidy does not introduce any tab characters into your file, @@ -486,13 +512,13 @@ here-documents, they will remain. =item B<-et=n>, B<--entab-leading-whitespace> This flag causes each B initial space characters to be replaced by -one tab character. +one tab character. The value of the integer B can be any value but can be coordinated with the number of spaces used for intentation. For example, B<-et=4 -ci=4 -i=4> will produce one tab for each indentation level and and one for each continuation indentation level. You may want to coordinate the value of B with what your -display software assumes for the spacing of a tab. +display software assumes for the spacing of a tab. =item B<-t>, B<--tabs> @@ -509,7 +535,7 @@ If the first line of code passed to perltidy contains leading tabs but no tab scheme is specified for the output stream then perltidy must guess how many spaces correspond to each leading tab. This number of spaces B corresponding to each leading tab of the input stream may be specified with -B<-dt=n>. The default is B. +B<-dt=n>. The default is B. This flag has no effect if a tab scheme is specified for the output stream, because then the input stream is assumed to use the same tab scheme and @@ -518,11 +544,11 @@ unstable editing). =back -=item B<-xs>, B<--extended-syntax> +=item B<-xs>, B<--extended-syntax> A problem with formatting Perl code is that some modules can introduce new syntax. This flag allows perltidy to handle certain common extensions -to the standard syntax without complaint. +to the standard syntax without complaint. For example, without this flag a structure such as the following would generate a syntax error and the braces would not be balanced: @@ -541,7 +567,7 @@ messages when debugging a script. For another method of handling extended syntax see the section L. -=item B<-io>, B<--indent-only> +=item B<-io>, B<--indent-only> This flag is used to deactivate all whitespace and line break changes within non-blank lines of code. @@ -555,10 +581,10 @@ useful when perltidy is merely being used to help find a brace error in a large script). Setting this flag is equivalent to setting B<--freeze-newlines> and -B<--freeze-whitespace>. +B<--freeze-whitespace>. If you also want to keep your existing blank lines exactly -as they are, you can add B<--freeze-blank-lines>. +as they are, you can add B<--freeze-blank-lines>. With this option perltidy is still free to modify the indenting (and outdenting) of code and comments as it normally would. If you also want to @@ -572,53 +598,75 @@ this flag is in effect. =item B<-enc=s>, B<--character-encoding=s> -This flag indicates the character encoding, if any, of the input data stream. +This flag indicates if the input data stream use a character encoding. Perltidy does not look for the encoding directives in the soure stream, such as B, and instead relies on this flag to determine the encoding. (Note that perltidy often works on snippets of code rather than complete files so it cannot rely on B directives). -The possible values for B are (1) the name of an encoding recognized by the -Encode.pm module, (2) B if no encoding is used, or (3) if -perltidy should guess. +The possible values for B are: -For example, the value B causes the stream to be read and written as -UTF-8. If the input stream cannot be decoded with a specified encoding then -processing is not done. + -enc=none if no encoding is used, or + -enc=utf8 for encoding in utf8 + -enc=guess if perltidy should guess between these two possibilities. The value B causes the stream to be processed without special encoding assumptions. This is appropriate for files which are written in single-byte -character encodings such as latin-1. +character encodings such as latin-1. + +The value B causes the stream to be read and written as +UTF-8. If the input stream cannot be decoded with this encoding then +processing is not done. The value B tells perltidy to guess between either utf8 encoding or no -encoding (meaning one character per byte). The guess uses the Encode::Guess -module and this restricted range of guesses covers the most common cases. -Testing showed that considering any greater number of encodings as guess -suspects is too risky. +encoding (meaning one character per byte). The B option uses the +Encode::Guess module which has been found to be reliable at detecting +if a file is encoded in utf8 or not. -The current default is B. +The current default is B. The abbreviations B<-utf8> or B<-UTF8> are equivalent to B<-enc=utf8>, and the -abbreviation B<-guess> is equivalent to <-enc=guess>. So to process a file +abbreviation B<-guess> is equivalent to B<-enc=guess>. So to process a file named B which is encoded in UTF-8 you can use: perltidy -utf8 file.pl or + perltidy -guess file.pl -To process a file in B you could use +or simply + + perltidy file.pl + +since B<-guess> is the default. + +To process files with an encoding other than UTF-8, it would be necessary to +write a short program which calls the Perl::Tidy module with some pre- and +post-processing to handle decoding and encoding. + +=item B<-eos=s>, B<--encode-output-strings=s> - perltidy -enc=euc-jp file.pl +This flag has been added to resolve an issue involving the interface between +Perl::Tidy and calling programs, and in particular B. +By default Perl::Tidy returns unencoded strings to the calling +program, but some programs expect encoded strings. Setting this flag causes +Perl::Tidy to return encoded output strings which it decoded. For some +background information see +L and +L. -A perltidy output file is unencoded if the input file is unencoded, and -otherwise it is encoded as B, even if the input encoding was not -B. +If you only run the B binary this flag has no effect. + +If you use B with encoded files and encounter irregularities such as +B messages you should set this flag. + +Additional information can be found in the man pages for the B module. =item B<-gcs>, B<--use-unicode-gcstring> This flag controls whether or not perltidy may use module Unicode::GCString to -obtain accurate display widths of wide characters. The default +obtain accurate display widths of wide characters. The default is B<--nouse-unicode-gcstring>. If this flag is set, and text is encoded, perltidy will look for the module @@ -702,19 +750,19 @@ reformatting complex code structures, such as deeply nested ternary statements. Continuation indentation is extra indentation spaces applied when a long line is broken. The default is n=2, illustrated here: - my $level = # -ci=2 + my $level = # -ci=2 ( $max_index_to_go >= 0 ) ? $levels_to_go[0] : $last_output_level; The same example, with n=0, is a little harder to read: - my $level = # -ci=0 + my $level = # -ci=0 ( $max_index_to_go >= 0 ) ? $levels_to_go[0] : $last_output_level; The value given to B<-ci> is also used by some commands when a small space is required. Examples are commands for outdenting labels, -B<-ola>, and control keywords, B<-okw>. +B<-ola>, and control keywords, B<-okw>. -When default values are not used, it is recommended that either +When default values are not used, it is recommended that either (1) the value B given with B<-ci=n> be no more than about one-half of the number of spaces assigned to a full indentation level on the B<-i=n> command, or @@ -758,11 +806,11 @@ improve indentation of some multi-line qw lists as shown below. ) ) -=item B<-sil=n> B<--starting-indentation-level=n> +=item B<-sil=n> B<--starting-indentation-level=n> By default, perltidy examines the input file and tries to determine the starting indentation level. While it is often zero, it may not be -zero for a code snippet being sent from an editing session. +zero for a code snippet being sent from an editing session. To guess the starting indentation level perltidy simply assumes that indentation scheme used to create the code snippet is the same as is being used @@ -777,10 +825,19 @@ guessed indentation will be wrong. If the default method does not work correctly, or you want to change the starting level, use B<-sil=n>, to force the starting level to be n. -=item B using B<-lp>, B<--line-up-parentheses> +=item B using B<--line-up-parentheses>, B<-lp> or B<--extended--line-up-parentheses> , B<-xlp> + +These flags provide an alternative indentation method for list data. The +original flag for this is B<-lp>, but it has some limitations (explained below) +which are avoided with the newer B<-xlp> flag. So B<-xlp> is probably the better +choice for new work, but the B<-lp> flag is retained to minimize changes to +existing formatting. +If you enter both B<-lp> and B<-xlp>, then B<-xlp> will be used. -By default, perltidy indents lists with 4 spaces, or whatever value -is specified with B<-i=n>. Here is a small list formatted in this way: + +In the default indentation method perltidy indents lists with 4 spaces, or +whatever value is specified with B<-i=n>. Here is a small list formatted in +this way: # perltidy (default) @month_of_year = ( @@ -788,84 +845,135 @@ is specified with B<-i=n>. Here is a small list formatted in this way: 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ); -Use the B<-lp> flag to add extra indentation to cause the data to begin -past the opening parentheses of a sub call or list, or opening square -bracket of an anonymous array, or opening curly brace of an anonymous -hash. With this option, the above list would become: +The B<-lp> or B<-xlp> flags add extra indentation to cause the data to begin +past the opening parentheses of a sub call or list, or opening square bracket +of an anonymous array, or opening curly brace of an anonymous hash. With this +option, the above list would become: - # perltidy -lp + # perltidy -lp or -xlp @month_of_year = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ); -If the available line length (see B<-l=n> ) does not permit this much +If the available line length (see B<-l=n> ) does not permit this much space, perltidy will use less. For alternate placement of the closing paren, see the next section. -This option has no effect on code BLOCKS, such as if/then/else blocks, +These flags have no effect on code BLOCKS, such as if/then/else blocks, which always use whatever is specified with B<-i=n>. -In situations where perltidy does not have complete freedom to choose line -breaks it may temporarily revert to its default indentation method. This can -occur for example if there are blank lines, block comments, multi-line quotes, -or side comments between the opening and closing parens, braces, or brackets. +Some limitiations on these flags are: -In addition, any parameter which significantly restricts the ability of -perltidy to choose newlines will conflict with B<-lp> and will cause -B<-lp> to be deactivated. These include B<-io>, B<-fnl>, B<-nanl>, and -B<-ndnl>. The reason is that the B<-lp> indentation style can require -the careful coordination of an arbitrary number of break points in -hierarchical lists, and these flags may prevent that. +=over 4 -The B<-lp> option may not be used together with the B<-t> tabs option. -It may, however, be used with the B<-et=n> tab method. +=item * +A limitation on B<-lp>, but not B<-xlp>, occurs in situations where perltidy +does not have complete freedom to choose line breaks. Then it may temporarily revert +to its default indentation method. This can occur for example if there are +blank lines, block comments, multi-line quotes, or side comments between the +opening and closing parens, braces, or brackets. It will also occur if a +multi-line anonymous sub occurs within a container since that will impose +specific line breaks (such as line breaks after statements). -=item B<-lpxl=s>, B<--line-up-parentheses-exclusion-list> +=item * -This is an experimental parameter; the details might change as experience -with it is gained. +For both the B<-lp> and B<-xlp> flags, any parameter which significantly +restricts the ability of perltidy to choose newlines will conflict with these +flags and will cause them to be deactivated. These include B<-io>, B<-fnl>, +B<-nanl>, and B<-ndnl>. -The B<-lp> indentation style works well for some types of coding but can -produce very long lines when variables have long names and/or containers are -very deeply nested. The B<-lpxl=s> flag is intended to help mitigate this problem by -providing control over the containers to which the B<-lp> indentation style is -applied. The B<-lp> flag by default is "greedy" and applies to as many -containers as possible. This flag specifies a list of things which should -B be use B<-lp> indentation. +=item * -This list is a string with space-separated items. Each item consists of up to -three pieces of information in this order: (1) an optional letter code (2) a -required container type, and (3) an optional numeric code. +The B<-lp> and B<-xlp> options may not be used together with the B<-t> tabs option. +They may, however, be used with the B<-et=n> tab method -The only required piece of information is a container type, which is one of -'(', '[', or '{'. For example the string +=back - -lpxl='[ {' +There are some potential disadvantages of this indentation method compared to +the default method that should be noted: -means do B include use -lp formatting within square-bracets or braces. The only unspecified -container is '(', so this string means that only the contents within parens will use -lp indentation. +=over 4 -An optional numeric code may follow any of the container types to further refine the selection based -on container contents. The numeric codes are: +=item * - '0' or blank: no check on contents - '1' reject -lp unless the contents is a simple list without sublists - '2' reject -lp unless the contents is a simple list without sublists, without - code blocks, and without ternary operators +The available line length can quickly be used up if variable names are +long. This can cause deeply nested code to quickly reach the line length +limit, and become badly formatted, much sooner than would occur with the +default indentation method. -For example, +=item * - -lpxl = '[ { (2' +Since the indentation depends on the lengths of variable names, small +changes in variable names can cause changes in indentation over many lines in a +file. This means that minor name changes can produce significant file +differences. This can be annoying and does not occur with the default +indentation method. -means only apply -lp to parenthesized lists which do not contain any sublists, -code blocks or ternary expressions. +=back + +Some things that can be done to minimize these problems are: + +=over 4 + +=item * + +Increase B<--maximum-line-length=n> above the default B characters if +necessary. + +=item * + +If you use B<-xlp> then long side comments can limit the indentation over +multiple lines. Consider adding the flag B<--ignore-side-comment-lengths> to +prevent this, or minimizing the use of side comments. + +=item * + +Apply this style in a limited way. By default, it applies to all list +containers (not just lists in parentheses). The next section describes how to +limit this style to, for example, just function calls. The default indentation +method will be applied elsewhere. + +=back + +=item B<-lpil=s>, B<--line-up-parentheses-inclusion-list> and B<-lpxl=s>, B<--line-up-parentheses-exclusion-list> + +The following discussion is written for B<-lp> but applies equally to the newer B<-xlp> version. +By default, the B<-lp> flag applies to as many containers as possible. +The set of containers to which the B<-lp> style applies can be reduced by +either one of these two flags: + +Use B<-lpil=s> to specify the containers to which B<-lp> applies, or -A third optional item of information which can be given for parens is an alphanumeric +use B<-lpxl=s> to specify the containers to which B<-lp> does NOT apply. + +Only one of these two flags may be used. Both flags can achieve the same +result, but the B<-lpil=s> flag is much easier to describe and use and is +recommended. The B<-lpxl=s> flag was the original implementation and is +only retained for backwards compatibility. + +This list B for these parametes is a string with space-separated items. +Each item consists of up to three pieces of information in this order: (1) an +optional letter code (2) a required container type, and (3) an optional numeric +code. + +The only required piece of information is a container type, which is one of +'(', '[', or '{'. For example the string + + -lpil='(' + +means use -lp formatting only on lists within parentheses, not lists in square-bracets or braces. +The same thing could alternatively be specified with + + -lpxl = '[ {' + +which says to exclude lists within square-brackets and braces. So what remains is lists within parentheses. + +A second optional item of information which can be given for parentheses is an alphanumeric letter which is used to limit the selection further depending on the type of token immediately before the paren. The possible letters are currently 'k', -'K', 'f', 'F', 'w', and 'W', with these meanings: +'K', 'f', 'F', 'w', and 'W', with these meanings for matching whatever precedes an opening paren: 'k' matches if the previous nonblank token is a perl builtin keyword (such as 'if', 'while'), 'K' matches if 'k' does not, meaning that the previous token is not a keyword. @@ -874,19 +982,41 @@ token immediately before the paren. The possible letters are currently 'k', 'w' matches if either 'k' or 'f' match. 'W' matches if 'w' does not. +For example: + + -lpil = 'f(' + +means only apply -lp to function calls, and + + -lpil = 'w(' + +means only apply -lp to parenthesized lists which follow a function or a keyword. + +This last example could alternatively be written using the B<-lpxl=s> flag as + + -lpxl = '[ { W(' + +which says exclude B<-lp> for lists within square-brackets, braces, and parens NOT preceded by +a keyword or function. Clearly, the B<-lpil=s> method is easier to understand. + +An optional numeric code may follow any of the container types to further refine the selection based +on container contents. The numeric codes are: + + '0' or blank: no check on contents is made + '1' exclude B<-lp> unless the contents is a simple list without sublists + '2' exclude B<-lp> unless the contents is a simple list without sublists, without + code blocks, and without ternary operators + For example, - -lpxl = '[ { F(2' + -lpil = 'f(2' -means only apply -lp to parenthesized lists which follow a function call and -which do not contain any sublists, code blocks or ternary expressions. The logic -of writing these codes is somewhat counter-intuitive because they describe what is not -getting the -lp indentation. So the 'F' indicates that non-function calls are -not getting -lp, or in other words that function calls are getting the -lp indentation. +means only apply -lp to function call lists which do not contain any sublists, +code blocks or ternary expressions. =item B<-cti=n>, B<--closing-token-indentation> -The B<-cti=n> flag controls the indentation of a line beginning with +The B<-cti=n> flag controls the indentation of a line beginning with a C<)>, C<]>, or a non-block C<}>. Such a line receives: -cti = 0 no extra indentation (default) @@ -917,10 +1047,10 @@ B is constrained to be no more than one indentation level. If desired, this control can be applied independently to each of the closing container token types. In fact, B<-cti=n> is merely an -abbreviation for B<-cpi=n -csbi=n -cbi=n>, where: +abbreviation for B<-cpi=n -csbi=n -cbi=n>, where: B<-cpi> or B<--closing-paren-indentation> controls B<)>'s, -B<-csbi> or B<--closing-square-bracket-indentation> controls B<]>'s, -B<-cbi> or B<--closing-brace-indentation> controls non-block B<}>'s. +B<-csbi> or B<--closing-square-bracket-indentation> controls B<]>'s, +B<-cbi> or B<--closing-brace-indentation> controls non-block B<}>'s. =item B<-icp>, B<--indent-closing-paren> @@ -946,7 +1076,7 @@ The default is not to do this, indicated by B<-nicb>. =item B<-nib>, B<--non-indenting-braces> Normally, lines of code contained within a pair of block braces receive one -additional level of indentation. This flag, which is enabled by default, +additional level of indentation. This flag, which is enabled by default, causes perltidy to look for opening block braces which are followed by a special side comment. This special side comment is B<#<<<> by default. If found, the code between this opening brace and its @@ -977,7 +1107,7 @@ If your code happens to have some opening braces followed by '#<<<', and you don't want this behavior, you can use B<-nnib> to deactivate it. To make it easy to remember, the default string is the same as the string for starting a B section. There is no confusion because in that case it is -for a block comment rather than a side-comment. +for a block comment rather than a side-comment. The special side comment can be changed with the next parameter. @@ -1023,7 +1153,7 @@ has been set to), if possible. This is the default. For example: fixit($i); } -Use B<-nola> to not outdent labels. +Use B<-nola> to not outdent labels. To control line breaks after labels see L. =item B @@ -1047,7 +1177,7 @@ For example, using C on the previous example gives: fixit($i); } -The default is not to do this. +The default is not to do this. =item B B<-okwl=string>, B<--outdent-keyword-list=string> @@ -1099,17 +1229,17 @@ values, 0, 1, and 2: When n is 0, there is always a space to the right of a '(' and to the left of a ')'. For n=2 there is never a space. For n=1, the default, there is a space unless the quantity within the parens is a single token, such -as an identifier or quoted string. +as an identifier or quoted string. Likewise, the parameter B<-sbt=n> or B<--square-bracket-tightness=n> controls the space within square brackets, as illustrated below. $width = $col[ $j + $k ] - $col[ $j ]; # -sbt=0 $width = $col[ $j + $k ] - $col[$j]; # -sbt=1 (default) - $width = $col[$j + $k] - $col[$j]; # -sbt=2 + $width = $col[$j + $k] - $col[$j]; # -sbt=2 Curly braces which do not contain code blocks are controlled by -the parameter B<-bt=n> or B<--brace-tightness=n>. +the parameter B<-bt=n> or B<--brace-tightness=n>. $obj->{ $parsed_sql->{ 'table' }[0] }; # -bt=0 $obj->{ $parsed_sql->{'table'}[0] }; # -bt=1 (default) @@ -1117,7 +1247,7 @@ the parameter B<-bt=n> or B<--brace-tightness=n>. And finally, curly braces which contain blocks of code are controlled by the parameter B<-bbt=n> or B<--block-brace-tightness=n> as illustrated in the -example below. +example below. %bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # -bbt=0 (default) %bf = map { $_ => -M $_ } grep {/\.deb$/} dirents '.'; # -bbt=1 @@ -1132,9 +1262,9 @@ abbreviation for the combination <-pt=n -sbt=n -bt=n -bbt=n>. The flag B<-tso> causes certain perl token sequences (secret operators) which might be considered to be a single operator to be formatted "tightly" -(without spaces). The operators currently modified by this flag are: +(without spaces). The operators currently modified by this flag are: - 0+ +0 ()x!! ~~<> ,=> =( )= + 0+ +0 ()x!! ~~<> ,=> =( )= For example the sequence B<0 +>, which converts a string to a number, would be formatted without a space: B<0+> when the B<-tso> flag is set. This @@ -1161,7 +1291,7 @@ B<-nsfs> or B<--nospace-for-semicolon> to deactivate it. =item B<-asc>, B<--add-semicolons> -Setting B<-asc> allows perltidy to add any missing optional semicolon at the end +Setting B<-asc> allows perltidy to add any missing optional semicolon at the end of a line which is followed by a closing curly brace on the next line. This is the default, and may be deactivated with B<-nasc> or B<--noadd-semicolons>. @@ -1226,12 +1356,12 @@ than fixed rules, because perltidy must try to resolve conflicts that arise between them and all of the other rules that it uses. One conflict that can arise is if, between two tokens, the left token wants a space and the right one doesn't. In this case, the token not wanting -a space takes priority. +a space takes priority. It is necessary to have a list of all token types in order to create this type of input. Such a list can be obtained by the command B<--dump-token-types>. Also try the B<-D> flag on a short snippet of code -and look at the .DEBUG file to see the tokenization. +and look at the .DEBUG file to see the tokenization. B Be sure to put these tokens in quotes to avoid having them misinterpreted by your command shell. @@ -1269,7 +1399,7 @@ unchanged in formatting. system($foo ); system($foo); -To find if a token is of type B you can use B. For the +To find if a token is of type B you can use B. For the first line above the result is 1: system($foo ); @@ -1316,7 +1446,7 @@ binary operator asymetrically with a space on the left but not on the right. When an opening paren follows a Perl keyword, no space is introduced after the keyword, unless it is (by default) one of these: - my local our and or xor eq ne if else elsif until unless + my local our and or xor eq ne if else elsif until unless while for foreach return switch case given when These defaults can be modified with two commands: @@ -1325,7 +1455,7 @@ B<-sak=s> or B<--space-after-keyword=s> adds keywords. B<-nsak=s> or B<--nospace-after-keyword=s> removes keywords. -where B is a list of keywords (in quotes if necessary). For example, +where B is a list of keywords (in quotes if necessary). For example, my ( $a, $b, $c ) = @_; # default my( $a, $b, $c ) = @_; # -nsak="my local our" @@ -1357,7 +1487,7 @@ is not to introduce a space. To cause a space to be introduced use: B<-sfp> or B<--space-function-paren> - myfunc( $a, $b, $c ); # default + myfunc( $a, $b, $c ); # default myfunc ( $a, $b, $c ); # -sfp You will probably also want to use the flag B<-skp> (previous item) too. @@ -1371,7 +1501,7 @@ reformatted with -sfp: sub filename { return $0 } In this particular case the syntax error can be removed if the line order is -reversed, so that Perl parses 'sub filename' first. +reversed, so that Perl parses 'sub filename' first. =item B<-fpva> or B<--function-paren-vertical-alignment> @@ -1434,7 +1564,7 @@ The set of keywords to which this parameter applies are by default are: if elsif unless while until for foreach -These can be changed with the parameter B<-kpitl=s> described in the next section. +These can be changed with the parameter B<-kpitl=s> described in the next section. =item B<-kpitl=string> or B<--keyword-paren-inner-tightness=string> @@ -1454,9 +1584,9 @@ follow the tightness value indicated by the B<-kpit=2> flag. 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. +or ternary expressions. - # perltidy [default formatting] + # perltidy [default formatting] $same = ( ( $aP eq $bP ) && ( $aS eq $bS ) @@ -1471,7 +1601,7 @@ a local version of vertical alignment. Here is an example involving a ternary operator: - # perltidy [default formatting] + # perltidy [default formatting] $bits = $top > 0xffff ? 32 : $top > 0xff ? 16 @@ -1587,7 +1717,7 @@ whenever possible. The default, n=0, will not do this. =item B<-iscl>, B<--ignore-side-comment-lengths> This parameter causes perltidy to ignore the length of side comments when -setting line breaks. The default, B<-niscl>, is to include the length of +setting line breaks. The default, B<-niscl>, is to include the length of side comments when breaking lines to stay within the length prescribed by the B<-l=n> maximum line length parameter. For example, the following long single line would remain intact with -l=80 and -iscl: @@ -1600,7 +1730,7 @@ whereas without the -iscl flag the line will be broken: perltidy -l=80 $vmsfile =~ s/;[\d\-]*$// ; # Clip off version number; we can use a newer version as well - + =item B<-hsc>, B<--hanging-side-comments> @@ -1614,7 +1744,7 @@ comments", which are something like this: A comment is considered to be a hanging side comment if (1) it immediately follows a line with a side comment, or another hanging side comment, and (2) there is some leading whitespace on the line. -To deactivate this feature, use B<-nhsc> or B<--nohanging-side-comments>. +To deactivate this feature, use B<-nhsc> or B<--nohanging-side-comments>. If block comments are preceded by a blank line, or have no leading whitespace, they will not be mistaken as hanging side comments. @@ -1651,7 +1781,7 @@ for the C and C blocks, because they were below the 6 line cutoff limit for adding closing side comments. This limit may be changed with the B<-csci> command, described below. -The command B<-dcsc> (or B<--delete-closing-side-comments>) reverses this +The command B<-dcsc> (or B<--delete-closing-side-comments>) reverses this process and removes these comments. Several commands are available to modify the behavior of these two basic @@ -1659,7 +1789,7 @@ commands, B<-csc> and B<-dcsc>: =over 4 -=item B<-csci=n>, or B<--closing-side-comment-interval=n> +=item B<-csci=n>, or B<--closing-side-comment-interval=n> where C is the minimum number of lines that a block must have in order for a closing side comment to be added. The default value is @@ -1678,7 +1808,7 @@ C. To illustrate: Now the C and C blocks are commented. However, now this has become very cluttered. -=item B<-cscp=string>, or B<--closing-side-comment-prefix=string> +=item B<-cscp=string>, or B<--closing-side-comment-prefix=string> where string is the prefix used before the name of the block type. The default prefix, shown above, is C<## end>. This string will be added to @@ -1687,7 +1817,7 @@ order to update, delete, and format them. Any comment identified as a closing side comment will be placed just a single space to the right of its closing brace. -=item B<-cscl=string>, or B<--closing-side-comment-list> +=item B<-cscl=string>, or B<--closing-side-comment-list> where C is a list of block types to be tagged with closing side comments. By default, all code block types preceded by a keyword or @@ -1700,7 +1830,7 @@ affected by any B<-csc> or B<-dcsc> operation: -cscl="sub : BEGIN END" -=item B<-csct=n>, or B<--closing-side-comment-maximum-text=n> +=item B<-csct=n>, or B<--closing-side-comment-maximum-text=n> The text appended to certain block types, such as an C block, is whatever lies between the keyword introducing the block, such as C, @@ -1715,7 +1845,7 @@ first block is C< ( !defined( $_[0] )...>. The existing limit of C caused this text to be truncated, as indicated by the C<...>. See the next flag for additional control of the abbreviated text. -=item B<-cscb>, or B<--closing-side-comments-balanced> +=item B<-cscb>, or B<--closing-side-comments-balanced> As discussed in the previous item, when the closing-side-comment-maximum-text limit is exceeded the comment text must @@ -1735,7 +1865,7 @@ help them by appending appropriate balancing structure: The default is B<-cscb>. -=item B<-csce=n>, or B<--closing-side-comment-else-flag=n> +=item B<-csce=n>, or B<--closing-side-comment-else-flag=n> The default, B, places the text of the opening C statement after any terminal C. @@ -1748,10 +1878,10 @@ side comments. If B is used, the results will be the same as B whenever the resulting line length is less than the maximum allowed. -=item B<-cscb>, or B<--closing-side-comments-balanced> +=item B<-cscb>, or B<--closing-side-comments-balanced> When using closing-side-comments, and the closing-side-comment-maximum-text -limit is exceeded, then the comment text must be abbreviated. +limit is exceeded, then the comment text must be abbreviated. It is terminated with three dots if the B<-cscb> flag is negated: perltidy -csc -ncscb @@ -1764,18 +1894,18 @@ flag tries to help them by appending appropriate terminal balancing structures: perltidy -csc -cscb } ## end foreach my $foo (sort { $b cmp $a ... }) -The default is B<-cscb>. +The default is B<-cscb>. -=item B<-cscw>, or B<--closing-side-comment-warnings> +=item B<-cscw>, or B<--closing-side-comment-warnings> This parameter is intended to help make the initial transition to the use of -closing side comments. +closing side comments. It causes two things to happen if a closing side comment replaces an existing, different closing side comment: first, an error message will be issued, and second, the original side comment will be placed alone on a new specially marked comment -line for later attention. +line for later attention. The intent is to avoid clobbering existing hand-written side comments which happen to match the pattern of closing side comments. This flag @@ -1783,7 +1913,7 @@ should only be needed on the first run with B<-csc>. =back -B +B =over 4 @@ -1797,7 +1927,7 @@ brace. Certain closing styles, such as the use of cuddled elses Please note that adding or deleting of closing side comments takes place only through the commands B<-csc> or B<-dcsc>. The other commands, -if used, merely modify the behavior of these two commands. +if used, merely modify the behavior of these two commands. =item * @@ -1842,9 +1972,9 @@ particularly useful for controlling how commented code is displayed. =item B<-sbc>, B<--static-block-comments> When B<-sbc> is used, a block comment with a special leading pattern, C<##> by -default, will be treated specially. +default, will be treated specially. -Comments so identified are treated as follows: +Comments so identified are treated as follows: =over 4 @@ -1856,12 +1986,12 @@ be indented, and otherwise it may be, =item * no new blank line will be -inserted before such a comment, and +inserted before such a comment, and =item * such a comment will never become -a hanging side comment. +a hanging side comment. =back @@ -1877,7 +2007,7 @@ Without this convention, the above code would become @month_of_year = ( # -nsbc 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', - + ## 'Dec', 'Nov' 'Nov', 'Dec' ); @@ -1889,8 +2019,8 @@ The default is to use B<-sbc>. This may be deactivated with B<-nsbc>. This parameter defines the prefix used to identify static block comments when the B<-sbc> parameter is set. The default prefix is C<##>, -corresponding to C<-sbcp=##>. The prefix is actually part of a perl -pattern used to match lines and it must either begin with C<#> or C<^#>. +corresponding to C<-sbcp=##>. The prefix is actually part of a perl +pattern used to match lines and it must either begin with C<#> or C<^#>. In the first case a prefix ^\s* will be added to match any leading whitespace, while in the second case the pattern will match only comments with no leading whitespace. For example, to @@ -1905,7 +2035,7 @@ be formed. A pattern which can be useful is: - -sbcp=^#{2,}[^\s#] + -sbcp=^#{2,}[^\s#] This pattern requires a static block comment to have at least one character which is neither a # nor a space. It allows a line containing only '#' @@ -1941,7 +2071,7 @@ The default is B<-nssc>. This parameter defines the prefix used to identify static side comments when the B<-ssc> parameter is set. The default prefix is C<##>, -corresponding to C<-sscp=##>. +corresponding to C<-sscp=##>. Please note that B<-sscp> merely defines the pattern used to identify static side comments; it will not be used unless the switch B<-ssc> is @@ -1994,6 +2124,13 @@ this: Additional text may appear on the special comment lines provided that it is separated from the marker by at least one space, as in the above examples. +Any number of code-skipping or format-skipping sections may appear in a file. +If an opening code-skipping or format-skipping comment is not followed by a +corresponding closing comment, then skipping continues to the end of the file. +If a closing code-skipping or format-skipping comment appears in a file but +does not follow a corresponding opening comment, then it is treated as an +ordinary comment without any special meaning. + It is recommended to use B<--code-skipping> only if you need to hide a block of an extended syntax which would produce errors if parsed by perltidy, and use B<--format-skipping> otherwise. This is because the B<--format-skipping> @@ -2046,19 +2183,19 @@ format skipping. The default is equivalent to -fsb='#<<<'. The string that you enter must begin with a # and should be in quotes as necessary to get past the command shell of your system. It is actually the leading text of a pattern that is constructed by appending a '\s', so you must also include backslashes -for characters to be taken literally rather than as patterns. +for characters to be taken literally rather than as patterns. Some examples show how example strings become patterns: -fsb='#\{\{\{' becomes /^#\{\{\{\s/ which matches #{{{ but not #{{{{ -fsb='#\*\*' becomes /^#\*\*\s/ which matches #** but not #*** - -fsb='#\*{2,}' becomes /^#\*{2,}\s/ which matches #** and #***** + -fsb='#\*{2,}' becomes /^#\*{2,}\s/ which matches #** and #***** =item B<-fse=string>, B<--format-skipping-end=string> The B<-fse=string> is the corresponding parameter used to change the ending marker for format skipping. The default is equivalent to --fse='#<<<'. +-fse='#<<<'. The beginning and ending strings may be the same, but it is preferable to make them different for clarity. @@ -2100,9 +2237,9 @@ Control>. If you do not want any changes to the line breaks within lines of code in your script, set B<-fnl>, and they will remain fixed, and the rest of the commands in -this section and sections +this section and sections L, -L. +L. You may want to use B<-noll> with this. Note: If you also want to keep your blank lines exactly @@ -2120,7 +2257,7 @@ alternatives: # -ce if ($task) { yyy(); - } else { + } else { zzz(); } @@ -2128,7 +2265,7 @@ alternatives: if ($task) { yyy(); } - else { + else { zzz(); } @@ -2137,8 +2274,8 @@ the preceding closing block brace and is followed by its own opening block brace on the same line. Other keywords and function names which are formatted with this "cuddled" style are B, B, B, B. -Other block types can be formatted by specifying their names on a -separate parameter B<-cbl>, described in a later section. +Other block types can be formatted by specifying their names on a +separate parameter B<-cbl>, described in a later section. Cuddling between a pair of code blocks requires that the closing brace of the first block start a new line. If this block is entirely on one line in the @@ -2162,14 +2299,14 @@ snippet. If there are blank lines between cuddled blocks they will be eliminated. If there are comments after the closing brace where cuddling would occur then cuddling will be prevented. If this occurs, cuddling will restart later in the -chain if possible. +chain if possible. =item B<-cb>, B<--cuddled-blocks> -This flag is equivalent to B<-ce>. +This flag is equivalent to B<-ce>. -=item B<-cbl>, B<--cuddled-block-list> +=item B<-cbl>, B<--cuddled-block-list> The built-in default cuddled block types are B. @@ -2183,7 +2320,7 @@ be set to or equivalently - -cbl=sort,map,grep + -cbl=sort,map,grep Note however that these particular block types are typically short so there might not be much opportunity for the cuddled format style. @@ -2191,13 +2328,13 @@ opportunity for the cuddled format style. Using commas avoids the need to protect spaces with quotes. As a diagnostic check, the flag B<--dump-cuddled-block-list> or B<-dcbl> can be -used to view the hash of values that are generated by this flag. +used to view the hash of values that are generated by this flag. Finally, note that the B<-cbl> flag by itself merely specifies which blocks are formatted with the cuddled format. It has no effect unless this formatting style is activated with B<-ce>. -=item B<-cblx>, B<--cuddled-block-list-exclusive> +=item B<-cblx>, B<--cuddled-block-list-exclusive> When cuddled else formatting is selected with B<-ce>, setting this flag causes perltidy to ignore its built-in defaults and rely exclusively on the block types @@ -2218,7 +2355,7 @@ to cause it to span multiple lines. This parameter controls that decision. The options are: cbo=0 Never force a short block to break. - cbo=1 If the first of a pair of blocks is broken in the input file, + cbo=1 If the first of a pair of blocks is broken in the input file, then break the second [DEFAULT]. cbo=2 Break open all blocks for maximal cuddled formatting. @@ -2232,27 +2369,53 @@ blocks. The option B produces maximal cuddling but will not allow any short blocks. -=item B<-bl>, B<--opening-brace-on-new-line> +=item B<-bl>, B<--opening-brace-on-new-line>, or B<--brace-left> -Use the flag B<-bl> to place the opening brace on a new line: +Use the flag B<-bl> to place an opening block brace on a new line: - if ( $input_file eq '-' ) # -bl - { - important_function(); + if ( $input_file eq '-' ) + { + ... } -This flag applies to all structural blocks, including named sub's (unless -the B<-sbl> flag is set -- see next item). +By default it applies to all structural blocks except B and +anonymous subs. -The default style, B<-nbl>, places an opening brace on the same line as -the keyword introducing it. For example, +The default is B<-nbl> which places an opening brace on the same line as +the keyword introducing it if possible. For example, - if ( $input_file eq '-' ) { # -nbl (default) + # default + if ( $input_file eq '-' ) { + ... + } -=item B<-sbl>, B<--opening-sub-brace-on-new-line> +When B<-bl> is set, the blocks to which this applies can be controlled with the +parameters B<--brace-left-list> and B<-brace-left-exclusion-list> described in the next sections. -The flag B<-sbl> can be used to override the value of B<-bl> for -the opening braces of named sub's. For example, +=item B<-bll=s>, B<--brace-left-list=s> + +Use this parameter to change the types of block braces for which the +B<-bl> flag applies; see L. For example, +B<-bll='if elsif else sub'> would apply it to only C +and named sub blocks. The default is all blocks, B<-bll='*'>. + +=item B<-blxl=s>, B<--brace-left-exclusion-list=s> + +Use this parameter to exclude types of block braces for which the +B<-bl> flag applies; see L. For example, +the default settings B<-bll='*'> and B<-blxl='sort map grep eval asub'> +mean all blocks except B and anonymous sub blocks. + +Note that the lists B<-bll=s> and B<-blxl=s> control the behavior of the +B<-bl> flag but have no effect unless the B<-bl> flag is set. + +=item B<-sbl>, B<--opening-sub-brace-on-new-line> + +The flag B<-sbl> provides a shortcut way to turn on B<-bl> just for named +subs. The same effect can be achieved by turning on B<-bl> +with the block list set as B<-bll='sub'>. + +For example, perltidy -sbl @@ -2268,10 +2431,9 @@ produces this result: } } -This flag is negated with B<-nsbl>. If B<-sbl> is not specified, -the value of B<-bl> is used. +This flag is negated with B<-nsbl>, which is the default. -=item B<-asbl>, B<--opening-anonymous-sub-brace-on-new-line> +=item B<-asbl>, B<--opening-anonymous-sub-brace-on-new-line> The flag B<-asbl> is like the B<-sbl> flag except that it applies to anonymous sub's instead of named subs. For example @@ -2292,31 +2454,50 @@ produces this result: This flag is negated with B<-nasbl>, and the default is B<-nasbl>. -=item B<-bli>, B<--brace-left-and-indent> +=item B<-bli>, B<--brace-left-and-indent> -The flag B<-bli> is the same as B<-bl> but in addition it causes one -unit of continuation indentation ( see B<-ci> ) to be placed before +The flag B<-bli> is similar to the B<-bl> flag but in addition it causes one +unit of continuation indentation ( see B<-ci> ) to be placed before an opening and closing block braces. -For example, +For example, perltidy -bli gives - if ( $input_file eq '-' ) # -bli + if ( $input_file eq '-' ) { important_function(); } -By default, this extra indentation occurs for blocks of type: -B, B, B, B, B, B, B, -B, B, and also with a preceding label. The next item -shows how to change this. +By default, this extra indentation occurs for block types: +B, B, B, B, B, B, B, B, and +also B and blocks preceded by a B