]> git.donarmstrong.com Git - perltidy.git/commitdiff
added kgb repeat count & adjusted controls
authorSteve Hancock <perltidy@users.sourceforge.net>
Fri, 7 Dec 2018 17:27:48 +0000 (09:27 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Fri, 7 Dec 2018 17:27:48 +0000 (09:27 -0800)
bin/perltidy
docs/perltidy.html
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm

index c7e3ea79b85ed744461028973d9a0783fd45c0c0..fe53df2468b2d981ac76c5acb78128163f0761ce 100755 (executable)
@@ -2673,7 +2673,7 @@ employ these controls but they can be enabled with the following parameters:
 
 B<--keyword-group-blanks-list=s>,   or B<-kgbl=s>; B<s> is a quoted string of keywords
 
-B<--keyword-group-blanks-count=n>,  or B<-kgbc=n>; B<n> is a threshold group size
+B<--keyword-group-blanks-threshold-count=n>,  or B<-kgbt=n>; B<n> is a threshold (minimum) group size
 
 B<--keyword-group-blanks-before=n>, or B<-kgbb=n>; B<n> = (0, 1, or 2) controls a leading blank
 
@@ -2741,10 +2741,10 @@ 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="use require local
 our my sub">, but any list of keywords may be used.  
 
-B<--keyword-group-blanks-count=n>, or B<-kgbc=n>, where B<n> is the minimum
+B<--keyword-group-blanks-threshold-count=n>, or B<-kgbt=n>, where B<n> is the minimum
 number of consecutive keyword statements to which these controls apply.  The
-default is B<n=5>. The special value B<n=0> can be used to turn off all 
-searching for keyword groups.
+default is B<n=5>. The special value B<n=0> is the same as n=infinity and
+can be used to turn off all searching for keyword groups.
 
 B<--keyword-group-blanks-before=n>, or B<-kgbb=n>, specifies whether
 a blank should appear before the first line of the group, as follows:
@@ -2760,7 +2760,7 @@ scheme (0=delete, 1=stable, 2=insert).
 B<--keyword-group-blanks-inside>, or B<-kgbi>, controls
 the insertion of blank lines between the first and last statement of the entire
 group.  If there is a continuous run of a single statement type with more than
-the minimum threshold number (as specified with B<-kgbc=n>) then this
+the minimum threshold number (as specified with B<-kgbt=n>) then this
 switch causes a blank line be inserted between this
 subgroup and the others. In the example above this happened between the
 B<use> and B<my> statements.
@@ -2772,6 +2772,13 @@ collection.  Any such orignial blank lines will be deleted before any other
 insertions are made when the parameter B<-kgbd> is set.  The default is not to
 do this, B<-nkgbd>.
 
+B<--keyword-group-blanks-repeat-count=n>, or B<-kgbr=n>, where B<n> is the
+maximum number of times this logic will be applied to any file.  The special
+value B<n=0> is the same as n=infinity which means it will be applied to an
+entire script [Default].  A value B<n=1> could be used to make it apply just
+one time for example.  This might be useful for adjusting just the B<use>
+statements in the top part of a module for example.
+
 B<--keyword-group-blanks>, or B<-kgb>, is an abbreviation equivalent to setting
 B<-kgbb=1 -kgba=1 -kgbi>.  This turns on keyword group formatting with a set of
 default values.  
index 500198c8e1da5528c72b49830208cad8f7bd8782..308273b788bc0b17942e6a218791adc0b65e33ca 100644 (file)
 
 <p><b>--keyword-group-blanks-list=s</b>, or <b>-kgbl=s</b>; <b>s</b> is a quoted string of keywords</p>
 
-<p><b>--keyword-group-blanks-count=n</b>, or <b>-kgbc=n</b>; <b>n</b> is a threshold group size</p>
+<p><b>--keyword-group-blanks-threshold-count=n</b>, or <b>-kgbt=n</b>; <b>n</b> is a threshold (minimum) group size</p>
 
 <p><b>--keyword-group-blanks-before=n</b>, or <b>-kgbb=n</b>; <b>n</b> = (0, 1, or 2) controls a leading blank</p>
 
 
 <p><b>--keyword-group-blanks-list=s</b>, or <b>-kgbl=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 sub&quot;</b>, but any list of keywords may be used.</p>
 
-<p><b>--keyword-group-blanks-count=n</b>, or <b>-kgbc=n</b>, where <b>n</b> is the minimum number of consecutive keyword statements to which these controls apply. The default is <b>n=5</b>. The special value <b>n=0</b> can be used to turn off all searching for keyword groups.</p>
+<p><b>--keyword-group-blanks-threshold-count=n</b>, or <b>-kgbt=n</b>, where <b>n</b> is the minimum number of consecutive keyword statements to which these controls apply. The default is <b>n=5</b>. The special value <b>n=0</b> is the same as n=infinity and can be used to turn off all searching for keyword groups.</p>
 
 <p><b>--keyword-group-blanks-before=n</b>, or <b>-kgbb=n</b>, specifies whether a blank should appear before the first line of the group, as follows:</p>
 
 
 <p><b>--keyword-group-blanks-after=n</b>, or <b>-kgba=n</b>, likewise specifies whether a blank should appear after the last line of the group, using the same scheme (0=delete, 1=stable, 2=insert).</p>
 
-<p><b>--keyword-group-blanks-inside</b>, or <b>-kgbi</b>, controls the insertion of blank lines between the first and last statement of the entire group. If there is a continuous run of a single statement type with more than the minimum threshold number (as specified with <b>-kgbc=n</b>) then this switch causes a blank line be inserted between this subgroup and the others. In the example above this happened between the <b>use</b> and <b>my</b> statements.</p>
+<p><b>--keyword-group-blanks-inside</b>, or <b>-kgbi</b>, controls the insertion of blank lines between the first and last statement of the entire group. If there is a continuous run of a single statement type with more than the minimum threshold number (as specified with <b>-kgbt=n</b>) then this switch causes a blank line be inserted between this subgroup and the others. In the example above this happened between the <b>use</b> and <b>my</b> statements.</p>
 
 <p><b>--keyword-group-blanks-delete</b>, or <b>-kgbd</b>, controls the deletion of any blank lines that exist in the the group when it is first scanned. When statements are initially scanned, any existing blank lines are included in the collection. Any such orignial blank lines will be deleted before any other insertions are made when the parameter <b>-kgbd</b> is set. The default is not to do this, <b>-nkgbd</b>.</p>
 
+<p><b>--keyword-group-blanks-repeat-count=n</b>, or <b>-kgbr=n</b>, where <b>n</b> is the maximum number of times this logic will be applied to any file. The special value <b>n=0</b> is the same as n=infinity which means it will be applied to an entire script [Default]. A value <b>n=1</b> could be used to make it apply just one time for example. This might be useful for adjusting just the <b>use</b> statements in the top part of a module for example.</p>
+
 <p><b>--keyword-group-blanks</b>, or <b>-kgb</b>, is an abbreviation equivalent to setting <b>-kgbb=1 -kgba=1 -kgbi</b>. This turns on keyword group formatting with a set of default values.</p>
 
 <p><b>--nokeyword-group-blanks</b>, or <b>-nkgb</b>, is equivalent to <b>-kgbb=0 -kgba nkgbi</b>. This flag turns off keyword group blank lines and is the default setting.</p>
index ca7c485b505ee3fe40e6d2f31b591b82a982c72b..0755f732a7dda692b05aa023edf30f60efcff207 100644 (file)
@@ -1797,7 +1797,8 @@ sub generate_options {
 
     $add_option->( 'blanks-after-comments',       'bac',  '!' );
     $add_option->( 'keyword-group-blanks-list',   'kgbl', '=s' );
-    $add_option->( 'keyword-group-blanks-count',  'kgbc', '=i' );
+    $add_option->( 'keyword-group-blanks-threshold-count',  'kgbt', '=i' );
+    $add_option->( 'keyword-group-blanks-repeat-count',  'kgbr', '=i' );
     $add_option->( 'keyword-group-blanks-before', 'kgbb', '=i' );
     $add_option->( 'keyword-group-blanks-after',  'kgba', '=i' );
     $add_option->( 'keyword-group-blanks-inside', 'kgbi', '!' );
@@ -1936,7 +1937,8 @@ sub generate_options {
       blank-lines-before-packages=1
 
       noblanks-after-comments
-      keyword-group-blanks-count=5
+      keyword-group-blanks-threshold-count=5
+      keyword-group-blanks-repeat-count=0
       keyword-group-blanks-before=1
       keyword-group-blanks-after=1
       nokeyword-group-blanks-inside
index 749fd31352d7574fceb0b85009817c71542b281c..822517503b24fdbc2ce70f226a5b42782f56c131 100644 (file)
@@ -978,7 +978,7 @@ sub keyword_group_scan {
     my $Opt_blanks_after  = $rOpts->{'keyword-group-blanks-after'};    # '-kgba'
     my $Opt_blanks_inside = $rOpts->{'keyword-group-blanks-inside'};   # '-kgbi'
     my $Opt_blanks_delete = $rOpts->{'keyword-group-blanks-delete'};   # '-kgbd'
-    my $Opt_long_count    = $rOpts->{'keyword-group-blanks-count'};    # '-kgbc'
+    my $Opt_threshold_count    = $rOpts->{'keyword-group-blanks-threshold-count'};    # '-kgbt'
 
     # codes for $Opt_blanks_before and $Opt_blanks_after:
     # 0 = never (delete if exist)
@@ -986,7 +986,7 @@ sub keyword_group_scan {
     # 2 = always (insert if missing)
 
     return $rhash_of_desires
-      unless $Opt_long_count > 0
+      unless $Opt_threshold_count > 0
       && ( $Opt_blanks_before != 1
         || $Opt_blanks_after != 1
         || $Opt_blanks_inside
@@ -994,6 +994,8 @@ sub keyword_group_scan {
 
     my $Opt_blanks_after_comments = $rOpts->{'blanks-after-comments'};  # '-bac'
     my $Opt_pattern               = $keyword_group_list_pattern;
+    my $Opt_repeat_count =
+      $rOpts->{'keyword-group-blanks-repeat-count'};    # '-kgbr'
 
     my $rlines              = $self->{rlines};
     my $rLL                 = $self->{rLL};
@@ -1005,6 +1007,8 @@ sub keyword_group_scan {
     # These vars will contain values for the most recently seen line:
     my ( $line_type, $CODE_type, $K_first, $K_last );
 
+    my $number_of_groups_seen = 0;
+
     my $split_into_sub_groups = sub {
 
         # Here we place blanks around long sub-groups of keywords
@@ -1016,7 +1020,7 @@ sub keyword_group_scan {
         for ( my $j = 1 ; $j < @sublist ; $j++ ) {
             my $ie  = $sublist[$j]->[0] - 1;
             my $num = $sublist[ $j - 1 ]->[2];
-            if ( $num >= $Opt_long_count ) {
+            if ( $num >= $Opt_threshold_count ) {
                 $rhash_of_desires->{ $ib - 1 } = 1 unless ( $ib == $ibeg );
                 $rhash_of_desires->{$ie} = 1 unless ( $ie == $iend );
             }
@@ -1066,7 +1070,9 @@ sub keyword_group_scan {
         if ( defined($ibeg) && $ibeg >= 0 ) {
 
             # then handle sufficiently large groups
-            if ( $count >= $Opt_long_count ) {
+            if ( $count >= $Opt_threshold_count ) {
+
+               $number_of_groups_seen++;
 
                 # do any blank deletions regardless of the count
                 $delete_inner_blank_lines->();
@@ -1166,7 +1172,11 @@ sub keyword_group_scan {
     # loop over all lines of the source
     my $i = -1;
     foreach my $line_of_tokens ( @{$rlines} ) {
+
         $i++;
+        last
+          if ( $Opt_repeat_count > 0
+            && $number_of_groups_seen >= $Opt_repeat_count );
 
         $CODE_type = "";
         $K_first   = undef;