3

I'm using GNU Emacs 22.2.1 and cperl 5.23.

I have perl code like this:

sub foo
{
    if($x)
    {
      print "x";
    }
    else
    {
      print "y";
    }
}

I'd like to reindent the code to a 2-space indent. But when I run cperl-indent-region on this code, I get:

sub foo
  {
    if ($x) {
      print "x";
    } else {
      print "y";
    }
  }
  1. How can I keep the outer brace at the left margin / column 0?
  2. How can I prevent the opening brace for the if and else from moving up to the previous line?
Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
bstpierre
  • 30,042
  • 15
  • 70
  • 103

1 Answers1

8

I believe the customization you're looking for is:

(setq cperl-extra-newline-before-brace t
      cperl-brace-offset              -2
      cperl-merge-trailing-else        nil)

You can customize cperl mode with M-x customize-group <ENTER> cperl <ENTER>. The indentation variables are in the Cperl Indentation Details subgroup.

cjm
  • 61,471
  • 9
  • 126
  • 175