X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bin%2Fperltidy;h=b39c71f66005555a9b14748d435fba79f4cfc514;hb=5c180637bf79ffc2af10f6654d308ce39e2f1f67;hp=23e3ccb36d4493d2976d0e70bf87e3798bea576d;hpb=ed1fffa086693c62340599065543ee1d5c09ee8f;p=perltidy.git diff --git a/bin/perltidy b/bin/perltidy index 23e3ccb..b39c71f 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -68,7 +68,7 @@ F<.ERR>. perltidy -b file1.pl file2.pl -Modify F and F in place, and backup the originals to +Modify F and F in place, and backup the originals to F and F. If F and/or F already exist, they will be overwritten. @@ -153,8 +153,8 @@ Options may not be bundled together. In other words, options B<-q> and B<-g> may NOT be entered as B<-qg>. Option names may be terminated early as long as they are uniquely identified. -For example, instead of B<-dump-token-types>, it would be sufficient to enter -B<-dump-tok>, or even B<-dump-t>, to uniquely identify this command. +For example, instead of B<--dump-token-types>, it would be sufficient to enter +B<--dump-tok>, or even B<--dump-t>, to uniquely identify this command. =head2 I/O control @@ -170,7 +170,9 @@ Show summary of usage and exit. Name of the output file (only if a single input file is being processed). If no output file is specified, and output is not -redirected to the standard output, the output will go to F. +redirected to the standard output (see B<-st>), the output will go to +F. [Note: - does not redirect to standard output. Use +B<-st> instead.] =item B<-st>, B<--standard-output> @@ -183,7 +185,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. -The default is B<-nst> or B<-nostandard-output>. +The default is B<-nst> or B<--nostandard-output>. =item B<-se>, B<--standard-error-output> @@ -303,6 +305,11 @@ name of .perltidyrc. There must not be a space on either side 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 +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> Write a list of all options used to the F<.LOG> file. @@ -323,6 +330,15 @@ as non-text, and this flag forces perltidy to process them. =over 4 +=item B<--notidy> + +This flag disables all formatting and causes the input to be copied unchanged +to the output except for possible changes in line ending characters and any +pre- and post-filters. This can be useful in conjunction with a hierarchical +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<-l=n>, B<--maximum-line-length=n> The default maximum line length is n=80 characters. Perltidy will try @@ -376,7 +392,7 @@ does its own checking, but this option employs perl to get a "second opinion". If perl reports errors in the input file, they will not be reported in -the error output unless the B<-warning-output> flag is given. +the error output unless the B<--warning-output> flag is given. The default is B to do this type of syntax checking (although perltidy will still do as much self-checking as possible). The reason @@ -399,8 +415,10 @@ exactly what flags were passed to perl. =item B<-io>, B<--indent-only> -This flag is used to deactivate all formatting and line break changes. -When it is in effect, the only change to the script will be indentation. +This flag is used to deactivate all formatting and line break changes +within non-blank lines of code. +When it is in effect, the only change to the script will be +to the indentation and blank lines. And any flags controlling whitespace and newlines will be ignored. You might want to use this if you are perfectly happy with your whitespace and line breaks, and merely want perltidy to handle the indentation. @@ -409,7 +427,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>. =item B<-ole=s>, B<--output-line-ending=s> @@ -417,8 +438,6 @@ where s=C, C, C, or C. This flag tells perltidy to output line endings for a specific system. Normally, perltidy writes files with the line separator character of the host system. The C and C flags have an identical result. -B: This only works under unix-like systems and is ignored under -other systems. =item B<-ple>, B<--preserve-line-endings> @@ -428,8 +447,17 @@ B, B, and B line endings. It will only work if perltidy input comes from a filename (rather than stdin, for example). If perltidy has trouble determining the input file line ending, it will revert to the default behavior of using the line ending of the host system. -B: This only works under unix-like systems and is ignored under -other systems. + +=item B<-it=n>, B<--iterations=n> + +This flag causes perltidy to do B complete iterations. The reason for this +flag is that code beautification is a somewhat iterative process and in some +cases the output from perltidy can be different if it is applied a second time. +For most purposes the default of B should be satisfactory. However B +can be useful when a major style change is being made, or when code is being +beautified on check-in to a source code control system. The run time will be +approximately proportional to B, and it should seldom be necessary to use a +value greater than B. This flag has no effect when perltidy is used to generate html. =back @@ -518,6 +546,7 @@ a C<)>, C<]>, or a non-block C<}>. Such a line receives: aligns with its opening token. -cti = 2 one extra indentation level if the line looks like: ); or ]; or }; + -cti = 3 one extra indentation level always The flags B<-cti=1> and B<-cti=2> work well with the B<-lp> flag (previous section). @@ -541,9 +570,9 @@ 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: -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<-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. =item B<-icp>, B<--indent-closing-paren> @@ -553,8 +582,8 @@ equivalent B<-cti=0>. They are included for backwards compatability. =item B<-icb>, B<--indent-closing-brace> -The B<-icb> option leaves a brace which terminates a code block -indented with the same indentation as the previous line. For example, +The B<-icb> option gives one extra level of indentation to a brace which +terminates a code block . For example, if ($task) { yyy(); @@ -781,11 +810,15 @@ 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>. +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. + +B Be sure to put these tokens in quotes to avoid having them +misinterpreted by your command shell. -=item Space between keyword and opening paren +=item Space between specific keywords and opening paren -When an opening paren follows a keyword, no space is introduced after the +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 eq ne if else elsif until unless @@ -802,6 +835,31 @@ 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" +To put a space after all keywords, see the next item. + +=item Space between all keywords and opening parens + +When an opening paren follows a function or keyword, no space is introduced +after the keyword except for the keywords noted in the previous item. To +always put a space between a function or keyword and its opening paren, +use the command: + +B<-skp> or B<--space-keyword-paren> + +You will probably also want to use the flag B<-sfp> (next item) too. + +=item Space between all function names and opening parens + +When an opening paren follows a function the default 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 ); # -sfp + +You will probably also want to use the flag B<-skp> (previous item) too. + =item Trimming whitespace around C quotes B<-tqw> or B<--trim-qw> provide the default behavior of trimming @@ -852,7 +910,7 @@ If both B<-ibc> and B<-isbc> are set, then B<-isbc> takes priority. When B<-olc> is set, lines which are full-line (block) comments longer than the value B will have their indentation -removed. The default is not to do this. +removed. This is the default; use B<-nolc> to prevent outdenting. =item B<-msc=n>, B<--minimum-space-to-comment=n> @@ -860,6 +918,11 @@ Side comments look best when lined up several spaces to the right of code. Perltidy will try to keep comments at least n spaces to the right. The default is n=4 spaces. +=item B<-fpsc=n>, B<--fixed-position-side-comment=n> + +This parameter tells perltidy to line up side comments in column number B +whenever possible. The default, n=0, is not do do this. + =item B<-hsc>, B<--hanging-side-comments> By default, perltidy tries to identify and align "hanging side @@ -881,7 +944,7 @@ whitespace, they will not be mistaken as hanging side comments. A closing side comment is a special comment which perltidy can automatically create and place after the closing brace of a code block. They can be useful for code maintenance and debugging. The command -B<-csc> (or B<-closing-side-comments>) adds or updates closing side +B<-csc> (or B<--closing-side-comments>) adds or updates closing side comments. For example, here is a small code snippet sub message { @@ -917,7 +980,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 @@ -936,7 +999,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 @@ -945,7 +1008,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-string> +=item B<-cscl=string>, or B<--closing-side-comment-list-string> 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 @@ -958,7 +1021,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, @@ -970,9 +1033,30 @@ characters. Omitted text is indicated with C<...>. (Tokens, including sub names, are never truncated, however, so actual lengths may exceed this). To illustrate, in the above example, the appended text of the first block is C< ( !defined( $_[0] )...>. The existing limit of -C caused this text to be truncated, as indicated by the C<...>. +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> + +As discussed in the previous item, when the +closing-side-comment-maximum-text limit is exceeded the comment text must +be truncated. Older versions of perltidy terminated with three dots, and this +can still be achieved with -ncscb: + + perltidy -csc -ncscb + } ## end foreach my $foo (sort { $b cmp $a ... + +However this causes a problem with editors editors which cannot recognize +comments or are not configured to do so because they cannot "bounce" around in +the text correctly. The B<-cscb> flag has been added to +help them by appending appropriate balancing structure: + + perltidy -csc -cscb + } ## end foreach my $foo (sort { $b cmp $a ... }) + +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. @@ -984,8 +1068,26 @@ 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<-cscw>, or B<-closing-side-comment-warnings> +When using closing-side-comments, and the closing-side-comment-maximum-text +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 + } ## end foreach my $foo (sort { $b cmp $a ... + +This causes a problem with older editors which do not recognize comments +because they cannot "bounce" around in the text correctly. The B<-cscb> +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>. + + +=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. @@ -1107,15 +1209,30 @@ 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 first character must be a C<#> -symbol, since this must only match comments. As a simple example, to +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 identify all comments as static block comments, one would use C<-sbcp=#>. +To identify all left-adjusted comments as static block comments, use C<-sbcp='^#'>. Please note that B<-sbcp> merely defines the pattern used to identify static block comments; it will not be used unless the switch B<-sbc> is set. Also, -please be aware that this string is used in a perl regular expression which -identifies these comments, so it must enable a valid regular expression to be -formed. +please be aware that since this string is used in a perl regular expression +which identifies these comments, it must enable a valid regular expression to +be formed. + +A pattern which can be useful is: + + -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 '#' +characters to be rejected as a static block comment. Such lines are often used +at the start and end of header information in subroutines and should not be +separated from the intervening comments, which typically begin with just a +single '#'. =item B<-osbc>, B<--outdent-static-block-comments> @@ -1155,21 +1272,88 @@ expression to be formed. =back +=back + +=head2 Skipping Selected Sections of Code + +Selected lines of code may be passed verbatim to the output without any +formatting. This feature is enabled by default but can be disabled with +the B<--noformat-skipping> or B<-nfs> flag. It should be used sparingly to +avoid littering code with markers, but it might be helpful for working +around occasional problems. For example it might be useful for keeping +the indentation of old commented code unchanged, keeping indentation of +long blocks of aligned comments unchanged, keeping certain list +formatting unchanged, or working around a glitch in perltidy. + +=over 4 + +=item B<-fs>, B<--format-skipping> + +This flag, which is enabled by default, causes any code between +special beginning and ending comment markers to be passed to the +output without formatting. The default beginning marker is #<<< +and the default ending marker is #>>> but they +may be changed (see next items below). Additional text may appear on +these special comment lines provided that it is separated from the +marker by at least one space. For example + + #<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); + #>>> + +The comment markers may be placed at any location that a block comment may +appear. If they do not appear to be working, use the -log flag and examine the +F<.LOG> file. Use B<-nfs> to disable this feature. + +=item B<-fsb=string>, B<--format-skipping-begin=string> + +The B<-fsb=string> parameter may be used to change the beginning marker for +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. + +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 #***** + +=item B<-fse=string>, B<--format-skipping-end=string> + +The B<-fsb=string> is the corresponding parameter used to change the +ending marker for format skipping. The default is equivalent to +-fse='#<<<'. + =back =head2 Line Break Control +The parameters in this section control breaks after +non-blank lines of code. Blank lines are controlled +separately by parameters in the section L. + =over 4 =item B<-fnl>, B<--freeze-newlines> -If you do not want any changes to the line breaks in your script, set +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 L, -L, and -L will be ignored. You may want to use B<-noll> -with this. +L. +You may want to use B<-noll> with this. + +Note: If you also want to keep your blank lines exactly +as they are, you can use the B<-fbl> flag which is described +in the section L. =item B<-ce>, B<--cuddled-else> @@ -1201,7 +1385,7 @@ Use the flag B<-bl> to place the opening brace on a new line: important_function(); } -This flag applies to all structural blocks, including sub's (unless +This flag applies to all structural blocks, including named sub's (unless the B<-sbl> flag is set -- see next item). The default style, B<-nbl>, places an opening brace on the same line as @@ -1212,7 +1396,7 @@ the keyword introducing it. For example, =item B<-sbl>, B<--opening-sub-brace-on-new-line> The flag B<-sbl> can be used to override the value of B<-bl> for -opening sub braces. For example, +the opening braces of named sub's. For example, perltidy -sbl @@ -1231,6 +1415,27 @@ produces this result: This flag is negated with B<-nsbl>. If B<-sbl> is not specified, the value of B<-bl> is used. +=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 + + perltidy -asbl + +produces this result: + + $a = sub + { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } + }; + +This flag is negated with B<-nasbl>, and the default is B<-nasbl>. + =item B<-bli>, B<--brace-left-and-indent> The flag B<-bli> is the same as B<-bl> but in addition it causes one @@ -1257,7 +1462,7 @@ B<-blil='if elsif else'> would apply it to only C blocks. =item B<-bar>, B<--opening-brace-always-on-right> -The default style, B<-nbl> places the opening brace on a new +The default style, B<-nbl> places the opening code block brace on a new line if it does not fit on the same line as the opening keyword, like this: @@ -1277,6 +1482,32 @@ flag. In this case, the above example becomes A conflict occurs if both B<-bl> and B<-bar> are specified. +=item B<-otr>, B<--opening-token-right> and related flags + +The B<-otr> flag is a hint that perltidy should not place a break between a +comma and an opening token. For example: + + # default formatting + push @{ $self->{$module}{$key} }, + { + accno => $ref->{accno}, + description => $ref->{description} + }; + + # perltidy -otr + push @{ $self->{$module}{$key} }, { + accno => $ref->{accno}, + description => $ref->{description} + }; + +The flag B<-otr> is actually a synonym for three other flags +which can be used to control parens, hash braces, and square brackets +separately if desired: + + -opr or --opening-paren-right + -ohbr or --opening-hash-brace-right + -osbr or --opening-square-bracket-right + =item Vertical tightness of non-block curly braces, parentheses, and square brackets. These parameters control what shall be called vertical tightness. Here are the @@ -1451,12 +1682,92 @@ possible values of this string, see L For example, if we want to just apply this style to C, C, and C blocks, we could use -C. +C. There is no vertical tightness control for closing block braces; with the exception of one-line blocks, they will normally remain on a separate line. +=item B<-sot>, B<--stack-opening-tokens> and related flags + +The B<-sot> flag tells perltidy to "stack" opening tokens +when possible to avoid lines with isolated opening tokens. + +For example: + + # default + $opt_c = Text::CSV_XS->new( + { + binary => 1, + sep_char => $opt_c, + always_quote => 1, + } + ); + + # -sot + $opt_c = Text::CSV_XS->new( { + binary => 1, + sep_char => $opt_c, + always_quote => 1, + } + ); + +For detailed control of individual closing tokens the following +controls can be used: + + -sop or --stack-opening-paren + -sohb or --stack-opening-hash-brace + -sosb or --stack-opening-square-bracket + +The flag B<-sot> is a synonym for B<-sop -sohb -sosb>. + +=item B<-sct>, B<--stack-closing-tokens> and related flags + +The B<-sct> flag tells perltidy to "stack" closing tokens +when possible to avoid lines with isolated closing tokens. + +For example: + + # default + $opt_c = Text::CSV_XS->new( + { + binary => 1, + sep_char => $opt_c, + always_quote => 1, + } + ); + + # -sct + $opt_c = Text::CSV_XS->new( + { + binary => 1, + sep_char => $opt_c, + always_quote => 1, + } ); + +The B<-sct> flag is somewhat similar to the B<-vtc> flags, and in some +cases it can give a similar result. The difference is that the B<-vtc> +flags try to avoid lines with leading opening tokens by "hiding" them at +the end of a previous line, whereas the B<-sct> flag merely tries to +reduce the number of lines with isolated closing tokens by stacking them +but does not try to hide them. For example: + + # -vtc=2 + $opt_c = Text::CSV_XS->new( + { + binary => 1, + sep_char => $opt_c, + always_quote => 1, } ); + +For detailed control of the stacking of individual closing tokens the +following controls can be used: + + -scp or --stack-closing-paren + -schb or --stack-closing-hash-brace + -scsb or --stack-closing-square-bracket + +The flag B<-sct> is a synonym for B<-scp -schb -scsb>. + =item B<-dnl>, B<--delete-old-newlines> By default, perltidy first deletes all old line break locations, and then it @@ -1468,16 +1779,17 @@ points. By default, perltidy will add line breaks when necessary to create continuations of long lines and to improve the script appearance. Use -B<-nanl> or B<-noadd-newlines> to prevent any new line breaks. +B<-nanl> or B<--noadd-newlines> to prevent any new line breaks. This flag does not prevent perltidy from eliminating existing line -breaks; see B<-freeze-newlines> to completely prevent changes to line +breaks; see B<--freeze-newlines> to completely prevent changes to line break points. =item Controlling whether perltidy breaks before or after operators -Two command line parameters provide some control over whether +Four command line parameters provide some control over whether a line break should be before or after specific token types. +Two parameters give detailed control: B<-wba=s> or B<--want-break-after=s>, and @@ -1490,11 +1802,11 @@ command-line parameter always overwrites the previous one before perltidy ever sees it. By default, perltidy breaks B these token types: - % + - * / x != == >= <= =~ !~ < > | & >= < - = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x= + % + - * / x != == >= <= =~ !~ < > | & + = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x= And perltidy breaks B these token types by default: - . << >> -> && || + . << >> -> && || // To illustrate, to cause a break after a concatenation operator, C<'.'>, rather than before it, the command line would be @@ -1506,11 +1818,34 @@ math operators C<'+'>, C<'-'>, C<'/'>, and C<'*'>: -wbb="+ - / *" -These commands should work well for most of the token types that -perltidy uses (use B<--dump-token-types> for a list). However, for a -few token types there may be conflicts with hardwired logic which cause -unexpected results. One example is curly braces, which should be -controlled with the parameter B provided for that purpose. +These commands should work well for most of the token types that perltidy uses +(use B<--dump-token-types> for a list). Also try the B<-D> flag on a short +snippet of code and look at the .DEBUG file to see the tokenization. However, +for a few token types there may be conflicts with hardwired logic which cause +unexpected results. One example is curly braces, which should be controlled +with the parameter B provided for that purpose. + +B Be sure to put these tokens in quotes to avoid having them +misinterpreted by your command shell. + +Two additional parameters are available which, though they provide no further +capability, can simplify input are: + +B<-baao> or B<--break-after-all-operators>, + +B<-bbao> or B<--break-before-all-operators>. + +The -baao sets the default to be to break after all of the following operators: + + % + - * / x != == >= <= =~ !~ < > | & + = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x= + . : ? && || and or err xor + +and the B<-bbao> flag sets the default to break before all of these operators. +These can be used to define an initial break preference which can be fine-tuned +with the B<-wba> and B<-wbb> flags. For example, to break before all operators +except an B<=> one could use --bbao -wba='=' rather than listing every +single perl operator except B<=> on a -wbb flag. =back @@ -1552,7 +1887,8 @@ to retain the original style, yields 1, 4, 6, 4, 1,); A disadvantage of this flag is that all tables in the file -must already be nicely formatted. +must already be nicely formatted. For another possibility see +the -fs flag in L. =item B<-mft=n>, B<--maximum-fields-per-table=n> @@ -1655,9 +1991,9 @@ return lists, such as C and . This allows chains of these operators to be displayed one per line. Use B<-nbok> to prevent retaining these breakpoints. -=item B<-bot>, B<--break-at-old-trinary-breakpoints> +=item B<-bot>, B<--break-at-old-ternary-breakpoints> -By default, if a conditional (trinary) operator is broken at a C<:>, +By default, if a conditional (ternary) operator is broken at a C<:>, then it will remain broken. To prevent this, and thereby form longer lines, use B<-nbot>. @@ -1668,16 +2004,51 @@ maximum extent possible. This will tend to produce the longest possible containers, regardless of type, which do not exceed the line length limit. +=item B<-kis>, B<--keep-interior-semicolons> + +Use the B<-kis> flag to prevent breaking at a semicolon if +there was no break there in the input file. Normally +perltidy places a newline after each semicolon which +terminates a statement unless several statements are +contained within a one-line brace block. To illustrate, +consider the following input lines: + + dbmclose(%verb_delim); undef %verb_delim; + dbmclose(%expanded); undef %expanded; + +The default is to break after each statement, giving + + dbmclose(%verb_delim); + undef %verb_delim; + dbmclose(%expanded); + undef %expanded; + +With B the multiple statements are retained: + + dbmclose(%verb_delim); undef %verb_delim; + dbmclose(%expanded); undef %expanded; + +The statements are still subject to the specified value +of B and will be broken if this +maximum is exceeed. + =back =head2 Blank Line Control Blank lines can improve the readability of a script if they are carefully placed. Perltidy has several commands for controlling the insertion, -retention, and removal of blank lines. +retention, and removal of blank lines. =over 4 +=item B<-fbl>, B<--freeze-blank-lines> + +Set B<-fbl> if you want to the blank lines in your script to +remain exactly as they are. The rest of the parameters in +this section may then be ignored. (Note: setting the B<-fbl> flag +is equivalent to setting B<-mbl=0> and B<-kbl=2>). + =item B<-bbc>, B<--blanks-before-comments> A blank line will be introduced before a full-line comment. This is the @@ -1728,23 +2099,39 @@ a value of B<0> is equivalent to entering a very large number. =item B<-mbl=n> B<--maximum-consecutive-blank-lines=n> -This parameter specifies the maximum number of consecutive blank lines -in the output script. The default is n=1. If the input file has more -than n consecutive blank lines, the number will be reduced to n. -(This obviously does not apply to pod sections, here-documents, and quotes). +This parameter specifies the maximum number of consecutive +blank lines which will be output within code sections of a +script. The default is n=1. If the input file has more +than n consecutive blank lines, the number will be reduced +to n. If B then no blank lines will be output (unless +all old blank lines are retained with the B<-kbl=2> flag of +the next section). + +This flag obviously does not apply to pod sections, +here-documents, and quotes. + +=item B<-kbl=n>, B<--keep-old-blank-lines=n> + +The B<-kbl=n> flag gives you control over how your existing blank lines are +treated. + +The possible values of B are: + + n=0 ignore all old blank lines + n=1 stable: keep old blanks, but limited by the value of the B<-mbl=n> flag + n=2 keep all old blank lines, regardless of the value of the B<-mbl=n> flag + +The default is B. =item B<-sob>, B<--swallow-optional-blank-lines> -All blank lines not required by the above flags, B<-bbb>, B<-bbs>, and B<-bbc>, -will be deleted. (But essential blank lines above pod documents will be -retained). This is NOT the default. +This is equivalent to B and is included for compatability with +previous versions. =item B<-nsob>, B<--noswallow-optional-blank-lines> -Retain blank lines, including those which do not corresponding to flags -B<-bbb>, B<-bbs>, and B<-bbc>. This is the default. The number of -blanks retained is subject to the limit imposed by -B<--maximum-consecutive-blank-lines>, however. +This is equivalent to B and is included for compatability with +previous versions. =back @@ -1762,6 +2149,18 @@ style overrides the default style with the following parameters: -lp -bl -noll -pt=2 -bt=2 -sbt=2 -icp +=item B<-pbp>, B<--perl-best-practices> + +B<-pbp> is an abbreviation for the parameters in the book B +by Damian Conway: + + -l=78 -i=4 -ci=4 -st -se -vt=2 -cti=0 -pt=1 -bt=1 -sbt=1 -bbt=1 -nsfs -nolq + -wbb="% + - * / x != == >= <= =~ !~ < > | & = + **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=" + +Note that the -st and -se flags make perltidy act as a filter on one file only. +These can be overridden with -nst and -nse if necessary. + =back =head2 Other Controls @@ -1814,18 +2213,36 @@ named F<.perltidyrc>. If it does not find one, it will continue looking for one in other standard locations. These other locations are system-dependent, and may be displayed with -the command C. Under Unix systems, it will look for a +the command C. Under Unix systems, it will first look +for an environment variable B. Then it will look for a F<.perltidyrc> file in the home directory, and then for a system-wide file F, and then it will look for F. Note that these last two system-wide files do not have a leading dot. Further system-dependent information will be found in the INSTALL file distributed with perltidy. -This file is free format, and simply a list of parameters, just as they -would be entered on a command line. Any number of lines may be used, -with any number of parameters per line, although it may be easiest to -read with one parameter per line. Blank lines are ignored, and text -after a '#' is ignored to the end of a line. +Under Windows, perltidy will also search for a configuration file named perltidy.ini since Windows does not allow files with a leading period (.). +Use C to see the possbile locations for your system. +An example might be F. + +Another option is the use of the PERLTIDY environment variable. +The method for setting environment variables depends upon the version of +Windows that you are using. Instructions for Windows 95 and later versions can +be found here: + +http://www.netmanage.com/000/20021101_005_tcm21-6336.pdf + +Under Windows NT / 2000 / XP the PERLTIDY environment variable can be placed in +either the user section or the system section. The later makes the +configuration file common to all users on the machine. Be sure to enter the +full path of the configuration file in the value of the environment variable. +Ex. PERLTIDY=C:\Documents and Settings\perltidy.ini + +The configuation file is free format, and simply a list of parameters, just as +they would be entered on a command line. Any number of lines may be used, with +any number of parameters per line, although it may be easiest to read with one +parameter per line. Blank lines are ignored, and text after a '#' is ignored +to the end of a line. Here is an example of a F<.perltidyrc> file: @@ -1874,8 +2291,8 @@ the B<-npro> option. =item * -The commands B<-dump-options>, B<-dump-defaults>, B<-dump-long-names>, -and B<-dump-short-names>, all described below, may all be helpful. +The commands B<--dump-options>, B<--dump-defaults>, B<--dump-long-names>, +and B<--dump-short-names>, all described below, may all be helpful. =back @@ -2249,21 +2666,21 @@ located with an internet search for "HTML color tables". Besides color, two other character attributes may be set: bold, and italics. To set a token type to use bold, use the flag -B<-html-bold-xxxxxx> or B<-hbx>, where B or B are the long +B<--html-bold-xxxxxx> or B<-hbx>, where B or B are the long or short names from the above table. Conversely, to set a token type to -NOT use bold, use B<-nohtml-bold-xxxxxx> or B<-nhbx>. +NOT use bold, use B<--nohtml-bold-xxxxxx> or B<-nhbx>. Likewise, to set a token type to use an italic font, use the flag -B<-html-italic-xxxxxx> or B<-hix>, where again B or B are the +B<--html-italic-xxxxxx> or B<-hix>, where again B or B are the long or short names from the above table. And to set a token type to -NOT use italics, use B<-nohtml-italic-xxxxxx> or B<-nhix>. +NOT use italics, use B<--nohtml-italic-xxxxxx> or B<-nhix>. For example, to use bold braces and lime color, non-bold, italics keywords the following command would be used: perltidy -html -hbs -hck=00FF00 -nhbk -hik somefile.pl -The background color can be specified with B<-html-color-background=n>, +The background color can be specified with B<--html-color-background=n>, or B<-hcbg=n> for short, where n is a 6 character hex RGB value. The default color of text is the value given to B, which is black as a default. @@ -2323,11 +2740,12 @@ dot is added, and the backup file will be F . The following list shows all short parameter names which allow a prefix 'n' to produce the negated form: - D anl asc aws b bbb bbc bbs bli boc bok bol bot syn ce csc - dac dbc dcsc dnl dws dp dpro dsm dsc ddf dln dop dsn dtt dwls dwrs - f fll frm hsc html ibc icb icp iob isbc lp log lal x lsl ple pod bl - sbl okw ola oll ple pvl q opt sbc sfs ssc sts se st sob - t tac tbc toc tp tsc tqw w + D anl asc aws b bbb bbc bbs bl bli boc bok bol bot ce + csc dac dbc dcsc ddf dln dnl dop dp dpro dsc dsm dsn dtt dwls + dwrs dws f fll frm fs hsc html ibc icb icp iob isbc lal log + lp lsl ohbr okw ola oll opr opt osbr otr ple ple pod pvl q + sbc sbl schb scp scsb sct se sfp sfs skp sob sohb sop sosb sot + ssc st sts syn t tac tbc toc tp tqw tsc w x bar kis Equivalently, the prefix 'no' or 'no-' on the corresponding long names may be used. @@ -2401,7 +2819,7 @@ perlstyle(1), Perl::Tidy(3) =head1 VERSION -This man page documents perltidy version 20031021. +This man page documents perltidy version 20101217. =head1 CREDITS @@ -2426,7 +2844,7 @@ see the CHANGES file. =head1 COPYRIGHT -Copyright (c) 2000-2003 by Steve Hancock +Copyright (c) 2000-2010 by Steve Hancock =head1 LICENSE