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

I like to indent my closing braces like so:
if( $location eq 'cliche' ) { $inn->bard('omg my ears'); my $drink = $inn->dwarven_ale(); $drink->watered_down( 0.75 ); }
Okay, so using -icb normally works okay for this. However, in the below situation it doesn't achieve the desired results:
if ( !-e "new_entry_exists" ) { chown( $newentryexists_owner, $newentryexists_group, "new_entry_exists" ); }
As suggested above, I would like it to look like the follwing. Does anyone know if there is a way to do this (besides setting -l=0)?
if ( !-e "new_entry_exists" ) { chown( $newentryexists_owner, $newentryexists_group, "new_entry_exists" ); }
My .perltidyrc looks like:
# PBP .perltidyrc file -l=78 # Max line width is 78 cols -i=4 # Indent level is 4 cols -ci=4 # Continuation indent is 4 cols -st # Output to STDOUT -se # Errors to STDERR -vt=2 # Maximal vertical tightness -pt=1 # Medium parenthesis tightness -bt=1 # Medium brace tightness -sbt=1 # Medium square bracket tightness -bbt=1 # Medium block brace tightness -nsfs # No space before semicolons -nolq # Don't outdent long quoted strings -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= && += -= /= |= >>= ||= .= %= ^= x=" # Break before all operators # ArgelWasHere -lp # Table formatting -cti=2 # Extra indentation for closing brackets -icb # Indent to previous line for BLOCK closing brace -iob

Replies are listed 'Best First'.
Re: perltidy: trying to indent closing brace one level more than the starting indentation
by Herkum (Parson) on Apr 02, 2006 at 13:13 UTC

    Taking at look at the perltidy sytle key this is the section that you need to refer to, (from web page http://perltidy.sourceforge.net/stylekey.html#braces%20right).

    Indentation Style for Other Containers You have a choice of two indentation schemes for non-block containers. + The default is to use a fixed number of spaces per indentation level + (the same number of spaces used for code blocks). Here is an example + of the default: $dbh = DBI->connect( undef, undef, undef, { PrintError => 0, RaiseError => 1 } ); The alternate is to let the location of the opening paren (or square b +racket, or curly brace) define the indentation, like this: $dbh = DBI->connect( undef, undef, undef, { PrintError => 0, RaiseError => 1 } );

    If you don't want that extra identation remove the -lp switch.

    If you go down the Style key web page it will tell you how to set up all the switches for Perltidy. It presents the options in a if-elsif-else manor making it easy to understand and you go from top to bottom. So you go through the whole page, though you don't implment every switch along the way.

      Thanks for the link! I went through perldoc perltidy before posting and I just went through the very nice page you linked to. However. looks like -l=0 is the only way to get the closing brace to line up with the block indentation. Thanks for the help though!!
Re: perltidy: trying to indent closing brace one level more than the starting indentation
by EvanCarroll (Chaplain) on Apr 02, 2006 at 02:57 UTC
    And if you had to embed another if you would do:
    if ( 1 ) { if ( 1 ) { print "foo" } }
    Seems,,, obtuse.


    Evan Carroll
    www.EvanCarroll.com
      I'm not sure what your point is. For one liners like you show it isn't perfect but then who the heck writes one liners like that? For longer blocks of code I find it much easier to follow if the closing bracket has the same indentation as the contents of the block. Why? It's simple layout and design. When the bracket lines up with the contents of the code block it's a striaght line all the way back up to the opening statement. However, when the opening and closing indentation match then your eye will be drawn to the right a bit by the indented code in the block as you follow it up. Very loosely: '|' vs. ')'.