Reputation: 42080
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.";
}
Upvotes: 8
Views: 731
Reputation: 60054
I confirm that the behavior you describe is present, but, from reading the sources and running under the debugger, it is not obvious that there is a customization which gets you the behavior you (and I) want.
Therefore I think this is a bug in cperl-mode
.
The fix is:
=== modified file 'lisp/progmodes/cperl-mode.el'
--- lisp/progmodes/cperl-mode.el 2012-12-01 05:09:12 +0000
+++ lisp/progmodes/cperl-mode.el 2012-12-26 16:29:19 +0000
@@ -3120,7 +3121,9 @@ and closing parentheses and brackets."
((eq 'continuation (elt i 0))
;; [continuation statement-start char-after is-block is-brace]
(goto-char (elt i 1)) ; statement-start
- (+ (if (memq (elt i 2) (append "}])" nil)) ; char-after
+ (+ (if (or (memq (elt i 2) (append "}])" nil)) ; char-after
+ (eq 'continuation ; do not repeat cperl-close-paren-offset
+ (elt (cperl-sniff-for-indent parse-data) 0)))
0 ; Closing parenth
cperl-continued-statement-offset)
(if (or (elt i 3) ; is-block
Please test this patch; if you are happy with it, I will add a customization to enable it.
Upvotes: 6
Reputation: 14855
As @jerome-radix suggests, the problem you're experiencing doesn't happen with cperl-mode
by default. The problem could certainly by in cperl-indent-rules-alist
, but there are a number of other places to look.
What version of the mode are you using? C-h v cperl-version RET
When debugging this kind of question you need to start with a couple of basic things to see if you can reproduce the error. First let everyone know what M-x emacs-version you are running. Then eliminate your own customizations from the equation by running emacs -q
to avoid loading your init file at startup:
--no-init-file, -q load neither ~/.emacs nor default.el
If you can still reproduce the problem with your own init file turned off, then go a step further and turn it off at the system level with emacs -Q
:
--quick, -Q equivalent to:
-q --no-site-file --no-site-lisp --no-splash
Upvotes: 0
Reputation: 10533
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.
Upvotes: 1