Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by Lotus1 (Vicar)
on Jan 07, 2019 at 19:25 UTC ( #1228151=note: print w/replies, xml ) Need Help??


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

From the Perltidy documentation section 'Controlling whether perltidy breaks before or after operators':

By default, perltidy breaks after these token types: % + - * / x != == + >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= % += ^= x= And perltidy breaks before these token types by default: . << >> -> && + || //

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.(See corrections in the following nodes) From the documentation:

Code Indentation Control
-ci=n, --continuation-indentation=n
Continuation indentation is extra indentation spaces applied when a long line is broken. The default is n=2, illustrated here:

my $level = # -ci=2 ( $max_index_to_go >= 0 ) ? $levels_to_go[0] : $last_output_level;

I also found a line in the documentation that mentions a debug file. This also prints a .LOG file which gives details about the length of the lines and any warnings. "Also try the -D flag on a short snippet of code and look at the .DEBUG file to see the tokenization."

  • Comment on Re: 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^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
    > 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.

      >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
Node Status?
node history
Node Type: note [id://1228151]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2019-11-19 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (95 votes). Check out past polls.

    Notices?