Skip Menu |

This queue is for tickets about the Perl-Tidy CPAN distribution.

Report information
The Basics
Id: 127634
Status: resolved
Priority: 0/
Queue: Perl-Tidy

People
Owner: Nobody in particular
Requestors: trichmond [...] proofpoint.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: RFE ability to add blank line before/after var definition block
Date: Tue, 13 Nov 2018 16:28:10 +0000
To: "bug-Perl-Tidy [...] rt.cpan.org" <bug-Perl-Tidy [...] rt.cpan.org>
From: Todd Richmond <trichmond [...] proofpoint.com>
Most formatters for other languages I have used have the ability to add a blank line to separate variable definitions from logic. This is often mixed with the option to delete all other blank lines to make code as compact as possible but still leave a list of variables as a separate block. Some formatters have an option to add a blank line before a variable def block as well when it is placed in the middle of a function. I tried playing with every possible option and looked through the code, but didn’t see anything related to definition blocks. Without such an option, I can’t remove other unnecessary blank lines my $b = 1; local $i = 55; if ($b) printf “$i\n”;
This would require a very clear definition of "definition block" and control logic. These are often highly intermixed in perl coding. I think the devil is in the details.
Subject: Re: [rt.cpan.org #127634] RFE ability to add blank line before/after var definition block
Date: Sat, 17 Nov 2018 20:31:06 +0000
To: "bug-Perl-Tidy [...] rt.cpan.org" <bug-Perl-Tidy [...] rt.cpan.org>
From: Todd Richmond <trichmond [...] proofpoint.com>
I'd be perfectly happy with a simple option to only add a blank line after a block of initial my/local variables. An initial block is quite common and adding blanks down in functional code is less useful Fancier code could allow blank lines before/after a block of X(configurable) my/local vars which would allow one line my variables to not have blanks added. My goal is to be able to use the delete blank lines option without destroying the initial variable blocks so that our style roughly matches C++ and other languages within the same product (for example we have a decent amount of XS code) sub x() { my $b; local $s = "string"; $b = func($s); } On 11/17/18, 12:18 PM, "Steve Hancock via RT" <bug-Perl-Tidy@rt.cpan.org> wrote: <URL: https://urldefense.proofpoint.com/v2/url?u=https-3A__rt.cpan.org_Ticket_Display.html-3Fid-3D127634&d=DwIDaQ&c=Vxt5e0Osvvt2gflwSlsJ5DmPGcPvTRKLJyp031rXjhg&r=HPS65xby-9P9SqEqfmk6niu-T7bLhV1_QCI7Ml7zCEs&m=Xf03fM-PFh1nrXn6tuW1IxphprRR3kbfOOu5sPXxxvA&s=KQEun3aHKKI_F5DNcE6YoeVuIoP-X3sBSv0cdO0R8Xk&e= > This would require a very clear definition of "definition block" and control logic. These are often highly intermixed in perl coding. I think the devil is in the details.
Subject: Re: [rt.cpan.org #127634] RFE ability to add blank line before/after var definition block
Date: Sat, 17 Nov 2018 12:44:07 -0800
To: bug-Perl-Tidy [...] rt.cpan.org
From: Steven Hancock <s7078hancock [...] gmail.com>
This is probably do-able, but these things can get very tricky. For example, there would have to be a minimum count on the number of lines. Also, when perltidy is run interactively on a section of code from an editor, it has no idea of where it is within an actual sub. On Sat, Nov 17, 2018 at 12:31 PM Todd Richmond via RT < bug-Perl-Tidy@rt.cpan.org> wrote: Show quoted text
> Queue: Perl-Tidy > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=127634 > > > I'd be perfectly happy with a simple option to only add a blank line after > a block of initial my/local variables. An initial block is quite common and > adding blanks down in functional code is less useful > > > > Fancier code could allow blank lines before/after a block of > X(configurable) my/local vars which would allow one line my variables to > not have blanks added. My goal is to be able to use the delete blank lines > option without destroying the initial variable blocks so that our style > roughly matches C++ and other languages within the same product (for > example we have a decent amount of XS code) > > > > > > sub x() { > > my $b; > > local $s = "string"; > > > > $b = func($s); > > } > > > > > > On 11/17/18, 12:18 PM, "Steve Hancock via RT" <bug-Perl-Tidy@rt.cpan.org> > wrote: > > > > <URL: > https://urldefense.proofpoint.com/v2/url?u=https-3A__rt.cpan.org_Ticket_Display.html-3Fid-3D127634&d=DwIDaQ&c=Vxt5e0Osvvt2gflwSlsJ5DmPGcPvTRKLJyp031rXjhg&r=HPS65xby-9P9SqEqfmk6niu-T7bLhV1_QCI7Ml7zCEs&m=Xf03fM-PFh1nrXn6tuW1IxphprRR3kbfOOu5sPXxxvA&s=KQEun3aHKKI_F5DNcE6YoeVuIoP-X3sBSv0cdO0R8Xk&e=
> >
> > > > This would require a very clear definition of "definition block" and > control logic. These are often highly intermixed in perl coding. I think > the devil is in the details. > > > > > >
Subject: Re: [rt.cpan.org #127634] RFE ability to add blank line before/after var definition block
Date: Sat, 17 Nov 2018 20:52:29 +0000
To: "bug-Perl-Tidy [...] rt.cpan.org" <bug-Perl-Tidy [...] rt.cpan.org>
From: Todd Richmond <trichmond [...] proofpoint.com>
Interactive mode would make it challenging to know if there should be a preceding blank line, but other formatters will never have a prefix blank if the code block starts with my/local. There is usually a blank-after-vars option that works on all var blocks and a separate blank-before-vars that only operates on subsequent blocks of > X variables On 11/17/18, 12:44 PM, "Steven Hancock via RT" <bug-Perl-Tidy@rt.cpan.org> wrote: <URL: https://urldefense.proofpoint.com/v2/url?u=https-3A__rt.cpan.org_Ticket_Display.html-3Fid-3D127634&d=DwIDaQ&c=Vxt5e0Osvvt2gflwSlsJ5DmPGcPvTRKLJyp031rXjhg&r=HPS65xby-9P9SqEqfmk6niu-T7bLhV1_QCI7Ml7zCEs&m=DNQqJCKUUz6Twvoluyf0RR8SwSmm_t_OUaUwnSvIAqw&s=h2m2yV0m2p15TxjQ9JfjYPxS-uKatWGGkPF5yZF_jjQ&e= > This is probably do-able, but these things can get very tricky. For example, there would have to be a minimum count on the number of lines. Also, when perltidy is run interactively on a section of code from an editor, it has no idea of where it is within an actual sub. On Sat, Nov 17, 2018 at 12:31 PM Todd Richmond via RT < bug-Perl-Tidy@rt.cpan.org> wrote: Show quoted text
> Queue: Perl-Tidy > Ticket <URL: https://urldefense.proofpoint.com/v2/url?u=https-3A__rt.cpan.org_Ticket_Display.html-3Fid-3D127634&d=DwIDaQ&c=Vxt5e0Osvvt2gflwSlsJ5DmPGcPvTRKLJyp031rXjhg&r=HPS65xby-9P9SqEqfmk6niu-T7bLhV1_QCI7Ml7zCEs&m=DNQqJCKUUz6Twvoluyf0RR8SwSmm_t_OUaUwnSvIAqw&s=h2m2yV0m2p15TxjQ9JfjYPxS-uKatWGGkPF5yZF_jjQ&e= > > > I'd be perfectly happy with a simple option to only add a blank line after > a block of initial my/local variables. An initial block is quite common and > adding blanks down in functional code is less useful > > > > Fancier code could allow blank lines before/after a block of > X(configurable) my/local vars which would allow one line my variables to > not have blanks added. My goal is to be able to use the delete blank lines > option without destroying the initial variable blocks so that our style > roughly matches C++ and other languages within the same product (for > example we have a decent amount of XS code) > > > > > > sub x() { > > my $b; > > local $s = "string"; > > > > $b = func($s); > > } > > > > > > On 11/17/18, 12:18 PM, "Steve Hancock via RT" <bug-Perl-Tidy@rt.cpan.org> > wrote: > > > > <URL: > https://urldefense.proofpoint.com/v2/url?u=https-3A__rt.cpan.org_Ticket_Display.html-3Fid-3D127634&d=DwIDaQ&c=Vxt5e0Osvvt2gflwSlsJ5DmPGcPvTRKLJyp031rXjhg&r=HPS65xby-9P9SqEqfmk6niu-T7bLhV1_QCI7Ml7zCEs&m=Xf03fM-PFh1nrXn6tuW1IxphprRR3kbfOOu5sPXxxvA&s=KQEun3aHKKI_F5DNcE6YoeVuIoP-X3sBSv0cdO0R8Xk&e=
> >
> > > > This would require a very clear definition of "definition block" and > control logic. These are often highly intermixed in perl coding. I think > the devil is in the details. > > > > > >
I'll write an experimental version and see how it goes. If you want to do this quickly it would be quite easy to write a one-time filter program which calls Perl::Tidy and inserts blanks. A starting point would be the file 'perl_line_type.pl' in the examples/ directory of the distribution. You would just look at lines of type 'CODE' which are returned and output extra blanks as needed. Steve
version 20190601 has a set of flags beginning with -kgb which can insert blank lines around keywords