agsamek agsamek - 1 month ago 13
Perl Question

How can I prevent PerlTidy from aligning assignments but keep adding single spaces?

How can I prevent PerlTidy from aligning assignments but keep adding single spaces?

This question is similar to How can I prevent PerlTidy from aligning my assignments? but I would like single spaces to be added where directed. Due to this

-naws
switch does not work for me. I just do not want multiple spaces to be inserted. Is it possibe with perltidy or some other tool?

Perl tidy changes:

my $a = 1;
my $aa = 2;
my $aaa= 3;


into

my $a = 1;
my $aa = 2;
my $aaa = 3;


with -naws it remains unchanged:

my $a = 1;
my $aa = 2;
my $aaa= 3;


I would like this code to be formatted as:

my $a = 1;
my $aa = 2;
my $aaa = 3;

Answer

The following patch worked for me:

--- Tidy.pm.org 2009-06-16 22:00:50.000000000 +0200
+++ Tidy.pm 2010-12-28 09:43:19.625000000 +0100
@@ -12404,7 +12404,7 @@
         # accept vertical alignment.

         # nothing to do if we aren't allowed to change whitespace
-        if ( !$rOpts_add_whitespace ) {
+        if ( 1 || !$rOpts_add_whitespace ) {
             for my $i ( 0 .. $max_index_to_go ) {
                 $matching_token_to_go[$i] = '';
             }