]> git.donarmstrong.com Git - perltidy.git/commitdiff
Updated docs for RT #128265
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 21 Jan 2019 05:02:07 +0000 (21:02 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 21 Jan 2019 05:02:07 +0000 (21:02 -0800)
bin/perltidy
docs/perltidy.html

index 9397b9a552448dbd8b29fc47c7cf5c05a8221a5d..66dee3d1c251b73e5c8fccf48dd8c66c8bab96a5 100755 (executable)
@@ -3201,6 +3201,34 @@ available line length, the formatting will violate the requested brace style.
 If this happens, reformatting the script a second time should correct
 the problem.
 
+Sometimes it might be desirable to convert a script to have one-line blocks
+whenever possible.  Although there is currently no flag for this, a simple
+workaround is to execute perltidy twice, once with the flag B<-noadd-newlines>
+and then once again with normal parameters, like this:  
+
+     cat infile | perltidy -nanl | perltidy >outfile
+
+When executed on this snippet
+
+    if ( $? == -1 ) {
+        die "failed to execute: $!\n";
+    }
+    if ( $? == -1 ) {
+        print "Had enough.\n";
+        die "failed to execute: $!\n";
+    }
+
+the result is
+
+    if ( $? == -1 ) { die "failed to execute: $!\n"; }
+    if ( $? == -1 ) {
+        print "Had enough.\n";
+        die "failed to execute: $!\n";
+    }
+
+This shows that blocks with a single statement become one-line blocks.
+
+
 =item  Debugging 
 
 The following flags are available for debugging:
index 44cbfcbf394044e838db8413c0a5fd2c4204425f..37420dffeb8c1905769eb48d57a1dd50fa940abd 100644 (file)
 
 <p>Finer control over blank placement can be achieved by using the individual parameters rather than the <b>-kgb</b> flag. The individual controls are as follows.</p>
 
-<p><b>-kgbl=s</b> or <b>--keyword-group-blanks-list=s</b>, where <b>s</b> is a quoted string, defines the set of keywords which will be formed into groups. The string is a space separated list of keywords. The default set is <b>s=&quot;use require local our my&quot;</b>, but any list of keywords may be used. Comment lines may also be included in a keyword group, even though they are not keywords. To include ordinary block comments, include the symbol <b>BC</b>. To include special block comments (which normally begin with &#39;##&#39;), include the symbol <b>SBC</b>.</p>
+<p><b>-kgbl=s</b> or <b>--keyword-group-blanks-list=s</b>, where <b>s</b> is a quoted string, defines the set of keywords which will be formed into groups. The string is a space separated list of keywords. The default set is <b>s=&quot;use require local our my&quot;</b>, but any list of keywords may be used. Comment lines may also be included in a keyword group, even though they are not keywords. To include ordinary block comments, include the symbol <b>BC</b>. To include static block comments (which normally begin with &#39;##&#39;), include the symbol <b>SBC</b>.</p>
 
 <p><b>-kgbs=s</b> or <b>--keyword-group-blanks-size=s</b>, where <b>s</b> is a string describing the number of consecutive keyword statements forming a group. If <b>s</b> is an integer then it is the minimum number required for a group. A maximum value may also be given with the format <b>s=min.max</b>, where <b>min</b> is the minimum number and <b>max</b> is the maximum number, and the min and max values are separated by one or more dots. No groups will be found if the maximum is less than the minimum. The maximum is unlimited if not given. The default is <b>s=5</b>. Some examples:</p>
 
 
 <p>Occasionally, when one-line blocks get broken because they exceed the available line length, the formatting will violate the requested brace style. If this happens, reformatting the script a second time should correct the problem.</p>
 
+<p>Sometimes it might be desirable to convert a script to have one-line blocks whenever possible. Although there is currently no flag for this, a simple workaround is to execute perltidy twice, once with the flag <b>-noadd-newlines</b> and then once again with normal parameters, like this:</p>
+
+<pre><code>     cat infile | perltidy -nanl | perltidy &gt;outfile</code></pre>
+
+<p>When executed on this snippet</p>
+
+<pre><code>    if ( $? == -1 ) {
+        die &quot;failed to execute: $!\n&quot;;
+    }
+    if ( $? == -1 ) {
+        print &quot;Had enough.\n&quot;;
+        die &quot;failed to execute: $!\n&quot;;
+    }</code></pre>
+
+<p>the result is</p>
+
+<pre><code>    if ( $? == -1 ) { die &quot;failed to execute: $!\n&quot;; }
+    if ( $? == -1 ) {
+        print &quot;Had enough.\n&quot;;
+        die &quot;failed to execute: $!\n&quot;;
+    }</code></pre>
+
+<p>This shows that blocks with a single statement become one-line blocks.</p>
+
 </dd>
 <dt id="Debugging">Debugging</dt>
 <dd>