Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Why is perltidy using indent-columns instead of continuation-indentation when breaking up a long if-line?

by torgny (Sexton)
on Jan 08, 2019 at 11:46 UTC ( [id://1228204]=note: print w/replies, xml ) Need Help??


in reply to Re: Why is perltidy using indent-columns instead of continuation-indentation when breaking up a long if-line?
in thread Why is perltidy using indent-columns instead of continuation-indentation when breaking up a long if-line?

> The way I understand it is the -ci option lets you specify what happens to lines that are only broken because they are too long. Your example will break before the && not because of line length.

Are you sure about that? My understanding was that perltidy breaks lines for the very reason that they are too long and that lines will be broken before or after the operators in wbb and wba. Otherwise, should not a line like the following (or just about any line with any of the operators wbb/wba/baao/bbao operators) be broken as well?

if ($foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz) { foo(); }

As it is, such lines are not broken. Lines like the ones in my example are only broken if their length exceed the -l=80 boundary.

  • Comment on Re^2: Why is perltidy using indent-columns instead of continuation-indentation when breaking up a long if-line?
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: Why is perltidy using indent-columns instead of continuation-indentation when breaking up a long if-line?
by Lotus1 (Vicar) on Jan 08, 2019 at 15:14 UTC
    >Are you sure about that? My understanding was that perltidy breaks lines for the very reason that they are too long ...

    I misspoke about that part. But I was on the right track. The thing I missed before is that indentation is treated differently if there is a long expression inside parentheses. There is also a difference if all the operators in an expression are the same. The examples below show what I mean. It seems to be working consistently. Have you tried running it on a large chunk of code to see how different situations are handled?

    testtidy.pl

    if ($foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $bazba +zbazbazbaz) { foo1(); } if ($foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz) { foo2(); } $foofoofoofoofoo = "abcdef ghijklmnop" . "abcdef ghijklmnop"; $foofoofoofoofoo = "abcdef ghijklmnop" . "abcdef ghijklmnop" . "abcdef + ghijklmnop"; $foofoofoofoofoo = "abcdef ghijklmnop" . "abcdef ghijklmnop" . "abcdef + ghijklmnop" . "abcdef ghijklmnop"; my $level1 = ( $max_index_to_go >= 0 ) ? $levels_to_go_12345[0] : $las +t_output_level_12345; my $level2 = ( $max_index_to_go >= 0 ) ? $levels_to_go_1234567890[0] : + $last_output_level_1234567890; while ($foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $ba +zbazbazbazbaz) { 1; } while ("abcdef ghijklmnop" . "abcdef ghijklmnop" . "abcdef ghijklmnop" + . "abcdef ghijklmnop") { 1; } ($foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $bazbazba +zbazbaz || $123456) || $bazbazbazbazbaz; ($foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $bazbazba +zbazbaz && $123456) || $bazbazbazbazbaz;

    When I run perltidy -l=80 -i=4 -ci=2 testtidy.pl it produces this:

    if ( $foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $bazbazbazbazbaz ) { foo1(); } if ( $foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz ) { foo2(); } $foofoofoofoofoo = "abcdef ghijklmnop" . "abcdef ghijklmnop"; $foofoofoofoofoo = "abcdef ghijklmnop" . "abcdef ghijklmnop" . "abcdef ghijklmnop"; $foofoofoofoofoo = "abcdef ghijklmnop" . "abcdef ghijklmnop" . "abcdef ghijklmnop" . "abcdef ghijklmnop"; my $level1 = ( $max_index_to_go >= 0 ) ? $levels_to_go_12345[0] : $last_output_le +vel_12345; my $level2 = ( $max_index_to_go >= 0 ) ? $levels_to_go_1234567890[0] : $last_output_level_1234567890; while ($foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $bazbazbazbazbaz ) { 1; } while ( "abcdef ghijklmnop" . "abcdef ghijklmnop" . "abcdef ghijklmnop" . "abcdef ghijklmnop" ) { 1; } ( $foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $bazbazb +azbazbaz || $123456 ) || $bazbazbazbazbaz; ( $foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $bazbazbazbazbaz && $123456 ) || $bazbazbazbazbaz;

    Edit: Here's one more example using a lot of parentheses. testtidy2.pl:

    (($foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $bazbazb +azbazbaz || $12345678901234567890) && $test112345123456789 ) && $test +22222233333 || $bazbazbazbazbaz || $bazbazbazbazbaz123456 && $bazbazb +azbazbaz123456789 || (($x1122334441234512345 && $x2211123451345 % $x3 +3112212345123451234 && $y111222123451234512345 || $y11122222123451234 +5 ) && ($x1234512345123456789 || $x12345612345123456789 || $x12356712 +3451234567890 && $x1234123412345 )) || $xx1122331234512345 && $xx1231 +231234512345;

    I compared running perltidy.pl with the default options and with your options and it gave the same output. If it used the continuing line spacing inside parentheses I don't think it would be as clear as this.

    ( ( $foofoofoofoofoo && $barbarbarbarbar && $bazbazbazbazbaz && $bazbazbazbazbaz || $12345678901234567890 ) && $test112345123456789 ) && $test22222233333 || $bazbazbazbazbaz || $bazbazbazbazbaz123456 && $bazbazbazbazbaz123456789 || ( ( $x1122334441234512345 && $x2211123451345 % $x33112212345123451234 && $y111222123451234512345 || $y111222221234512345 ) && ( $x1234512345123456789 || $x12345612345123456789 || $x123567123451234567890 && $x1234123412345 ) ) || $xx1122331234512345 && $xx1231231234512345;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1228204]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-24 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found