]> git.donarmstrong.com Git - perltidy.git/commitdiff
add --indent-leading-semicolon, -ils; see git #171
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 1 Dec 2024 17:34:55 +0000 (09:34 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 1 Dec 2024 17:34:55 +0000 (09:34 -0800)
CHANGES.md
bin/perltidy
lib/Perl/Tidy.pm
lib/Perl/Tidy/Formatter.pm
t/snippets/expect/ils.def [new file with mode: 0644]
t/snippets/expect/ils.ils [new file with mode: 0644]
t/snippets/ils.in [new file with mode: 0644]
t/snippets/ils.par [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets31.t

index f0ac1b67fe0f731a1977871a4f52ea114d872ba0..0ba126cebe59d62997adeea28d1065860e0037dc 100644 (file)
@@ -2,6 +2,10 @@
 
 ## 2024 09 03.06
 
+    - Added parameter --indent-leading-semicolon, -ils; see git #171. When
+    this is negated, a line with a leading semicolon does not get the extra
+    leading continuation indentation spaces (defined with -ci=n).
+
     - Space around here doc delimiters follow spacing controls better. For
     example, a space is now added before the closing paren here:
 
index 3bd39c35bf4bcb4b69c35fc2e8d054939c7e1cfe..b69b1d07374de5a1debcbd1ae1497cf59d643ce3 100755 (executable)
@@ -1115,6 +1115,25 @@ terminates a code block .  For example,
 
 The default is not to do this, indicated by B<-nicb>.
 
+=item B<-ils>, B<--indent-leading-semicolon>
+
+A line which begins with a leading semicolon will, by default, have the extra
+number of indentation spaces defined by B<--continuation-indentation=n>.
+This extra indentation can be removed by setting B<-nils>.
+
+    # default
+    $z = sqrt( $x**2 + $y**2 )
+
+      ;    # <-- indented by ci spaces
+
+    # -nils
+    $z = sqrt( $x**2 + $y**2 )
+
+    ;    # <-- not indented by ci spaces
+
+Note that leading semicolons do not normally occur unless requested with
+B<--break-at-old-semicolon-breakpoints> or forced, for example by
+a blank line as in this example.
 
 =item B<-nib>, B<--non-indenting-braces>
 
@@ -4680,11 +4699,19 @@ The default formatting will be:
 
   $z = sqrt( $x**2 + $y**2 );
 
-The result using B<perltidy -bos> keeps the isolated semicolon:
+Using the <-bos> flag keeps the isolated semicolon:
 
+  # perltidy -bos
   $z = sqrt( $x**2 + $y**2 )
     ;
 
+The extra continuation indentation spaces on the semicolon can be
+removed by also setting B<--noindent-leading-semicolon>.
+
+  # perltidy -bos -nils
+  $z = sqrt( $x**2 + $y**2 )
+  ;
+
 The default is not to do this, B<-nbos>.
 
 
index e6ec263fba816cdf589c327319128f3ef7afa740..98492b9613844234aa400d83265ab5acb65db3af 100644 (file)
@@ -3558,6 +3558,7 @@ sub generate_options {
     $add_option->( 'outdent-labels',                       'ola',   '!' );
     $add_option->( 'outdent-long-quotes',                  'olq',   '!' );
     $add_option->( 'indent-closing-brace',                 'icb',   '!' );
+    $add_option->( 'indent-leading-semicolon',             'ils',   '!' );
     $add_option->( 'closing-token-indentation',            'cti',   '=i' );
     $add_option->( 'closing-paren-indentation',            'cpi',   '=i' );
     $add_option->( 'closing-brace-indentation',            'cbi',   '=i' );
@@ -3929,6 +3930,7 @@ sub generate_options {
       hanging-side-comments
       indent-block-comments
       indent-columns=4
+      indent-leading-semicolon
       integer-range-check=2
       interbracket-arrow-complexity=1
       iterations=1
index cabaef23d93b927b105c9ae7074e113f791866c5..42af4e3ebbe21b5df3a31859423a1bee158cbac0 100644 (file)
@@ -234,6 +234,7 @@ my (
     $rOpts_ignore_perlcritic_comments,
     $rOpts_indent_closing_brace,
     $rOpts_indent_columns,
+    $rOpts_indent_leading_semicolon,
     $rOpts_indent_only,
     $rOpts_keep_interior_semicolons,
     $rOpts_line_up_parentheses,
@@ -3336,6 +3337,7 @@ sub initialize_global_option_vars {
     $rOpts_ignore_perlcritic_comments = $rOpts->{'ignore-perlcritic-comments'};
     $rOpts_indent_closing_brace       = $rOpts->{'indent-closing-brace'};
     $rOpts_indent_columns             = $rOpts->{'indent-columns'};
+    $rOpts_indent_leading_semicolon   = $rOpts->{'indent-leading-semicolon'};
     $rOpts_indent_only                = $rOpts->{'indent-only'};
     $rOpts_keep_interior_semicolons   = $rOpts->{'keep-interior-semicolons'};
     $rOpts_line_up_parentheses        = $rOpts->{'line-up-parentheses'};
@@ -38876,6 +38878,16 @@ sub make_paren_name {
             );
         }
 
+        #-----------------------------------------
+        # Section 1B:
+        # if line starts with a non-sequenced item
+        #-----------------------------------------
+        else {
+            if ( $type_beg eq ';' && !$rOpts_indent_leading_semicolon ) {
+                $adjust_indentation = 1;
+            }
+        }
+
         #---------------------------------------------------------
         # Section 2: set indentation according to flag set above
         #
diff --git a/t/snippets/expect/ils.def b/t/snippets/expect/ils.def
new file mode 100644 (file)
index 0000000..eacf48e
--- /dev/null
@@ -0,0 +1 @@
+$z = sqrt( $x**2 + $y**2 );
diff --git a/t/snippets/expect/ils.ils b/t/snippets/expect/ils.ils
new file mode 100644 (file)
index 0000000..ed17984
--- /dev/null
@@ -0,0 +1,2 @@
+$z = sqrt( $x**2 + $y**2 )
+;
diff --git a/t/snippets/ils.in b/t/snippets/ils.in
new file mode 100644 (file)
index 0000000..ed17984
--- /dev/null
@@ -0,0 +1,2 @@
+$z = sqrt( $x**2 + $y**2 )
+;
diff --git a/t/snippets/ils.par b/t/snippets/ils.par
new file mode 100644 (file)
index 0000000..def94c9
--- /dev/null
@@ -0,0 +1 @@
+-nils -bos
index 19d8c8fc87f125751b974e1f69aa7dcabb492a68..1dcd5e7818966d82a7f8f5d208245124d1733a5d 100644 (file)
 ../snippets31.t        btct.btct2
 ../snippets31.t        btct.btct3
 ../snippets31.t        btct.def
+../snippets31.t        c424.c424
+../snippets31.t        c424.def
 ../snippets4.t gnu1.gnu
 ../snippets4.t gnu2.def
 ../snippets4.t gnu2.gnu
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets31.t        c424.c424
-../snippets31.t        c424.def
+../snippets31.t        ils.def
+../snippets31.t        ils.ils
index e45368267ddb21640c1a0f6bbad2f6bbfbee9d14..e36c5b68f6b4d0e19b05bf5df58f046074019c0c 100644 (file)
@@ -6,6 +6,8 @@
 #3 btct.def
 #4 c424.c424
 #5 c424.def
+#6 ils.def
+#7 ils.ils
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -27,6 +29,7 @@ BEGIN {
         'btct3' => "-btct=1 -atc -wtc=1",
         'c424'  => "-naws -qwaf",
         'def'   => "",
+        'ils'   => "-nils -bos",
     };
 
     ############################
@@ -53,6 +56,11 @@ $lut = byte [ [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], ];
         'c424' => <<'----------',
 my @chars = qw(   | / - \ | / - \    );
 my @chars = qw(| / - \ | / - \ );
+----------
+
+        'ils' => <<'----------',
+$z = sqrt( $x**2 + $y**2 )
+;
 ----------
     };
 
@@ -162,6 +170,23 @@ my @chars = qw(   | / - \ | / - \    );
 my @chars = qw(| / - \ | / - \ );
 #5...........
         },
+
+        'ils.def' => {
+            source => "ils",
+            params => "def",
+            expect => <<'#6...........',
+$z = sqrt( $x**2 + $y**2 );
+#6...........
+        },
+
+        'ils.ils' => {
+            source => "ils",
+            params => "ils",
+            expect => <<'#7...........',
+$z = sqrt( $x**2 + $y**2 )
+;
+#7...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};