Emacs cperl - indentation in constant block

独自空忆成欢 提交于 2019-12-07 01:45:16

问题


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 :-)


回答1:


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))


来源:https://stackoverflow.com/questions/24494901/emacs-cperl-indentation-in-constant-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!