views:

49

answers:

1

In emacs' cperl-mode, lines that continute a statement from a previous line are indented by one level:

my $var
  = (1+1)
  * (2+2)
  / (3+3);

However, if the statement does not begin at zero indentation because it is inside a block, then if you break your statement onto a third line, you get another level of indentation, and so on:

sub break_my_indentation {
  my $var
    = (1+1)
      * (2+2)
        / (3+3);
  return "Indentation is broken.";
}

Is there any way to fix this so that statements are indented the same way inside blocks as they are outside? I would like the second example to look like this:

sub fix_my_indentation {
  my $var
    = (1+1)
    * (2+2)
    / (3+3);
  return "Indentation is fixed.";
}
+1  A: 

cperl-mode don't have this problem by default. By default, it indents like this :

my $var
  = (1+1)
  * (2+2)
  / (3+3);

You have a customization that prevents cperl-mode to indent correctly. See cperl-indent-rules-alist variable for configuration of the indent.

Jérôme Radix
Hmm. If the statement begins at indentation level zero, it works like you say. However, if the statement begins within a block or something, then it does what I say. I'll update the question.
Ryan Thompson