Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Perltidy indents too much when there are stacked opening tokens

by will_ (Scribe)
on Oct 20, 2014 at 13:56 UTC ( [id://1104442]=perlquestion: print w/replies, xml ) Need Help??

will_ has asked for the wisdom of the Perl Monks concerning the following question:

Perltidy seems to think that this code:
sub discover { return [ { 'name' => $name, 'version' => $VERSION, } ]; }
...would look better like this (I disagree):
sub discover { return [ { 'name' => $name, 'version' => $VERSION, } ]; }
It's indenting the hash keys twice, presumably because there are two opening tokens. I'm using -sot "stack opening tokens".
But surely a large benefit of stacking opening parentheses and brackets is that you don't have to indent twice?
It's saving vertical space but wasting horizontal space.

Does anyone know the setting to control this? I've looked through the docs but not found it:
http://perltidy.sourceforge.net/perltidy.html#code_indentation_control

Replies are listed 'Best First'.
Re: Perltidy indents too much when there are stacked opening tokens
by LanX (Saint) on Oct 21, 2014 at 01:07 UTC
    The current behavior is a good default, since stacked parens doesn't mean that all data is on the same depth (see discoverX ) and yes perltidy doesn't seem to have any finer control about data indentation.

    $ perltidy -st -sct -sot tsttdy.pl sub discoverX { return [ { 'name' => $name, 'version' => $VERSION, }, [ 1, 2, 3 ] ]; } sub discover1 { return { 'name' => $name, 'version' => $VERSION, }; } sub discover2 { return [ { 'name' => $name, 'version' => $VERSION, } ]; } sub discover3 { return [ [ { 'name' => $name, 'version' => $VERSION, } ] ]; }

    For what it's worth emacs has an option to calculate the indentation relative from the last statement:

    Maybe you want to propose this feature to the maintainer?

    I'm not too convinced. But YMMV ...

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-25 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found