Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs cperl - indentation in constant block

I'm running Aquamacs 3.0a based on GNU Emacs 24.3.50.2. cperl-version is 6.2. When I edit a Perl constant block I get extra indentation that I don't want:-

use constant {
    ONE => 1,
        TWO => 2,
        THREE => 3,
    };

What I want is this:-

use constant {
    ONE => 1,
    TWO => 2,
    THREE => 3,
};

The problem seems to be that cperl-continued-statement-offset is being added because we're inside a block and there's no semicolon at the end of the previous line.

Is there a way to tell cperl to indent constant blocks using "parens" rules? I did try tweaking cperl-indent-parens-as-block, but that didn't help. I'm not surprised, I guess I should be looking for a variable called cperl-indent-constant-block-as-parens :-)

like image 782
kbro Avatar asked Jun 30 '14 16:06

kbro


1 Answers

A bit of digging in the code suggests this is a bug in cperl-mode - it should be treating a constant block like an anonymous hashref - after all, that's basically what it is! Here's a patch to cperl-block-p that makes it so. Would anyone care to approve or reject this? My elisp is a bit rusty :-)

$ diff -u cperl-mode.el.orig cperl-mode.el
--- cperl-mode.el.orig  2013-09-27 13:43:56.000000000 +0100
+++ cperl-mode.el   2014-06-30 18:02:30.000000000 +0100
@@ -4828,9 +4828,9 @@
       (and (memq (char-syntax (preceding-char)) '(?w ?_))
       (progn
         (backward-sexp)
-        ;; sub {BLK}, print {BLK} $data, but NOT `bless', `return', `tr'
+        ;; sub {BLK}, print {BLK} $data, but NOT `bless', `constant', `return', `tr'
         (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax
-             (not (looking-at "\\(bless\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
+             (not (looking-at "\\(bless\\|constant\\|return\\|q[wqrx]?\\|tr\\|[smy]\\)\\>")))
         ;; sub bless::foo {}
         (progn
           (cperl-backward-to-noncomment (point-min))
like image 58
kbro Avatar answered Oct 23 '22 05:10

kbro