]> git.donarmstrong.com Git - perltidy.git/commitdiff
fixed 2 issues with -kpit option (git #26)
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 2 Jun 2020 00:04:56 +0000 (17:04 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 2 Jun 2020 00:04:56 +0000 (17:04 -0700)
lib/Perl/Tidy/Formatter.pm
t/snippets/expect/kpit.def
t/snippets/expect/kpit.kpit
t/snippets/kpit.in
t/snippets/packing_list.txt
t/snippets20.t

index 7a4cb880b7dbbb4160be60e47f0dfdc4b1694788..7adf6f575c58efcf046d2173cee759ce97b48af6 100644 (file)
@@ -2222,6 +2222,30 @@ sub set_whitespace_flags {
                 $ws = WS_NO;
             }
         }
+        elsif ( $type eq 'k' ) {
+
+           # Keyword 'foreach' is a special case for the -kpit logic since the
+           # opening paren does not always immediately follow the keyword. So
+           # we have to search forward for the paren in this case.  I have
+            # limited the search to 10 tokens ahead, just in case somebody
+            # has a big file and no opening paren.  This should be enough for
+            # all normal code.
+            if (   $token eq 'foreach'
+                && %keyword_paren_inner_tightness
+                && defined( $keyword_paren_inner_tightness{$token} )
+                && $j < $jmax )
+            {
+                my $jp = $j;
+                for ( my $inc = 1 ; $inc < 10 ; $inc++ ) {
+                    $jp++;
+                    last if ( $jp > $jmax );
+                    next unless ( $rLL->[$jp]->[_TOKEN_] eq '(' );
+                    my $seqno = $rLL->[$jp]->[_TYPE_SEQUENCE_];
+                    $set_container_ws_by_keyword->( $token, $seqno );
+                    last;
+                }
+            }
+        }
 
         my $ws_4;
         $ws_4 = $ws
@@ -9379,8 +9403,16 @@ sub pad_token {
                 # token
                 if ( $pad_spaces < 0 ) {
 
+                   # Deactivated for -kpit due to conflict. This block deletes
+                   # a space in an attempt to improve alignment in some cases,
+                   # but it may conflict with user spacing requests.  For now
+                   # it is just deactivated if the -kpit option is used, to
+                   # avoid changing existing formatting, but really it adds
+                   # little value and could eventually be completely removed.
                     if ( $pad_spaces == -1 ) {
-                        if ( $ipad > $ibeg && $types_to_go[ $ipad - 1 ] eq 'b' )
+                        if (   $ipad > $ibeg
+                            && $types_to_go[ $ipad - 1 ] eq 'b'
+                            && !%keyword_paren_inner_tightness )
                         {
                             $self->pad_token( $ipad - 1, $pad_spaces );
                         }
index 8354af2e9da1934e64fc418e8ecd3d4704f3e8da..0c628fefa24158e02df30b77b393d10674b0181f 100644 (file)
@@ -1 +1,16 @@
 if ( seek( DATA, 0, 0 ) ) { ... }
+
+# The foreach keyword may be separated from the next opening paren
+foreach $req (@bgQueue) {
+    ...;
+}
+
+# This had trouble because a later padding operation removed the inside space
+while ($CmdJob eq "" && @CmdQueue > 0 && $RunNightlyWhenIdle != 1
+    || @CmdQueue > 0
+    && $RunNightlyWhenIdle == 2
+    && $bpc->isAdminJob( $CmdQueue[0]->{host} ) )
+{
+    ...;
+}
+
index 5c640af3cb8c02d665b6446f41b101c782d4f377..fd96ddec0c7439a57d3b1e0f3e886975b2e52b83 100644 (file)
@@ -1 +1,16 @@
 if ( seek(DATA, 0, 0) ) { ... }
+
+# The foreach keyword may be separated from the next opening paren
+foreach $req ( @bgQueue ) {
+    ...;
+}
+
+# This had trouble because a later padding operation removed the inside space
+while ( $CmdJob eq "" && @CmdQueue > 0 && $RunNightlyWhenIdle != 1
+    || @CmdQueue > 0
+    && $RunNightlyWhenIdle == 2
+    && $bpc->isAdminJob($CmdQueue[0]->{host}) )
+{
+    ...;
+}
+
index 5c640af3cb8c02d665b6446f41b101c782d4f377..e22d4e7010763f75f05199b744a912481fabff30 100644 (file)
@@ -1 +1,13 @@
 if ( seek(DATA, 0, 0) ) { ... }
+
+# The foreach keyword may be separated from the next opening paren
+foreach $req(@bgQueue) {
+   ...
+}
+
+# This had trouble because a later padding operation removed the inside space
+while ($CmdJob eq "" && @CmdQueue > 0 && $RunNightlyWhenIdle != 1
+        || @CmdQueue > 0 && $RunNightlyWhenIdle == 2 && $bpc->isAdminJob($CmdQueue[0]->{host})) {
+  ... 
+}
+
index 6b456710d8ebf12dd08a03f9689784adb8158803..f68982d6f2495dcd455a7ade619e5a2d2fdfbf92 100644 (file)
 ../snippets20.t        kpit.kpit
 ../snippets20.t        kpitl.def
 ../snippets20.t        kpitl.kpitl
+../snippets20.t        hanging_side_comments3.def
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets20.t        hanging_side_comments3.def
index fe88ed0afdabe35b90f5bb1b84317824ccd37e83..7d55f2a8b9761ac6041653aa127f9b9fd908e7fb 100644 (file)
@@ -134,6 +134,18 @@ my $mapping = [
 
         'kpit' => <<'----------',
 if ( seek(DATA, 0, 0) ) { ... }
+
+# The foreach keyword may be separated from the next opening paren
+foreach $req(@bgQueue) {
+   ...
+}
+
+# This had trouble because a later padding operation removed the inside space
+while ($CmdJob eq "" && @CmdQueue > 0 && $RunNightlyWhenIdle != 1
+        || @CmdQueue > 0 && $RunNightlyWhenIdle == 2 && $bpc->isAdminJob($CmdQueue[0]->{host})) {
+  ... 
+}
+
 ----------
 
         'kpitl' => <<'----------',
@@ -501,6 +513,21 @@ my $mapping = [
             params => "def",
             expect => <<'#14...........',
 if ( seek( DATA, 0, 0 ) ) { ... }
+
+# The foreach keyword may be separated from the next opening paren
+foreach $req (@bgQueue) {
+    ...;
+}
+
+# This had trouble because a later padding operation removed the inside space
+while ($CmdJob eq "" && @CmdQueue > 0 && $RunNightlyWhenIdle != 1
+    || @CmdQueue > 0
+    && $RunNightlyWhenIdle == 2
+    && $bpc->isAdminJob( $CmdQueue[0]->{host} ) )
+{
+    ...;
+}
+
 #14...........
         },
 
@@ -509,6 +536,21 @@ if ( seek( DATA, 0, 0 ) ) { ... }
             params => "kpit",
             expect => <<'#15...........',
 if ( seek(DATA, 0, 0) ) { ... }
+
+# The foreach keyword may be separated from the next opening paren
+foreach $req ( @bgQueue ) {
+    ...;
+}
+
+# This had trouble because a later padding operation removed the inside space
+while ( $CmdJob eq "" && @CmdQueue > 0 && $RunNightlyWhenIdle != 1
+    || @CmdQueue > 0
+    && $RunNightlyWhenIdle == 2
+    && $bpc->isAdminJob($CmdQueue[0]->{host}) )
+{
+    ...;
+}
+
 #15...........
         },