]> git.donarmstrong.com Git - perltidy.git/blobdiff - bin/perltidy
New upstream release (closes: #613417)
[perltidy.git] / bin / perltidy
index 141f10ab023117638332ce01ca23358cbab38294..b39c71f66005555a9b14748d435fba79f4cfc514 100755 (executable)
@@ -68,7 +68,7 @@ F<.ERR>.
 
   perltidy -b file1.pl file2.pl
 
-Modify F<file1.pl> and F<file1.pl> in place, and backup the originals to
+Modify F<file1.pl> and F<file2.pl> in place, and backup the originals to
 F<file1.pl.bak> and F<file2.pl.bak>.  If F<file1.pl.bak> and/or F<file2.pl.bak>
 already exist, they will be overwritten.
 
@@ -305,6 +305,11 @@ name of .perltidyrc.  There must not be a space on either side of the
 would cause file F<testcfg> 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.  
@@ -325,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<Skipping Selected Sections of Code> 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
@@ -401,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.
@@ -411,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>
 
@@ -429,6 +448,17 @@ 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.
 
+=item B<-it=n>,   B<--iterations=n>
+
+This flag causes perltidy to do B<n> 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<n=1> should be satisfactory.  However B<n=2>
+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<n>, and it should seldom be necessary to use a
+value greater than B<n=2>.  This flag has no effect when perltidy is used to generate html.
+
 =back
 
 =head2 Code Indentation Control
@@ -888,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<n>
+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
@@ -998,7 +1033,28 @@ 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<n=20> caused this text to be truncated, as indicated by the C<...>.
+C<n=20> 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> 
 
@@ -1012,6 +1068,24 @@ side comments.
 
 If B<n=1> is used, the results will be the same as B<n=2> whenever the
 resulting line length is less than the maximum allowed.
+=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.  
+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> 
 
@@ -1149,6 +1223,17 @@ 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>
 
 The command B<-osbc> will will cause static block comments to be outdented by 2
@@ -1249,17 +1334,26 @@ ending marker for format skipping.  The default is equivalent to
 
 =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<Blank Line
+Control>.
+
 =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<Controlling List Formatting>,
-L<Retaining or Ignoring Existing Line Breaks>, and
-L<Blank Line Control> will be ignored.  You may want to use B<-noll>
-with this.
+L<Retaining or Ignoring Existing Line Breaks>. 
+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<Blank Line Control>.
 
 =item B<-ce>,   B<--cuddled-else>
 
@@ -1291,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
@@ -1302,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
 
@@ -1321,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 
@@ -1573,7 +1688,7 @@ 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-token> and related flags
+=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.
@@ -1606,7 +1721,7 @@ controls can be used:
 
 The flag B<-sot> is a synonym for B<-sop -sohb -sosb>.
 
-=item B<-sct>,  B<--stack-closing-token> and related flags
+=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.
@@ -1672,8 +1787,9 @@ 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
 
@@ -1712,6 +1828,25 @@ with the parameter B<bl> provided for that purpose.
 B<WARNING> 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
 
 =head2 Controlling List Formatting
@@ -1869,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<perltidy -kis> 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<maximum-line-length> 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
@@ -1929,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<n=0> 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<n> 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<n=1>.  
 
 =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<kbl=0> 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<kbl=1> and is included for compatability with
+previous versions.
 
 =back
 
@@ -2027,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<perltidy -dpro>.  Under Unix systems, it will look for a
+the command C<perltidy -dpro>.  Under Unix systems, it will first look
+for an environment variable B<PERLTIDY>.  Then it will look for a
 F<.perltidyrc> file in the home directory, and then for a system-wide
 file F</usr/local/etc/perltidyrc>, and then it will look for
 F</etc/perltidyrc>.  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<perltidy -dpro> to see the possbile locations for your system.
+An example might be F<C:\Documents and Settings\All Users\perltidy.ini>.
+
+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:
 
@@ -2541,7 +2745,7 @@ The following list shows all short parameter names which allow a prefix
  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
+ 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.
@@ -2615,7 +2819,7 @@ perlstyle(1), Perl::Tidy(3)
 
 =head1 VERSION
 
-This man page documents perltidy version 20070424.
+This man page documents perltidy version 20101217.
 
 =head1 CREDITS
 
@@ -2640,7 +2844,7 @@ see the CHANGES file.
 
 =head1 COPYRIGHT
 
-Copyright (c) 2000-2006 by Steve Hancock
+Copyright (c) 2000-2010 by Steve Hancock
 
 =head1 LICENSE