简体   繁体   English

Emacs cperl - 常量块中的缩进

[英]Emacs cperl - indentation in constant block

I'm running Aquamacs 3.0a based on GNU Emacs 24.3.50.2. 我正在运行基于GNU Emacs 24.3.50.2的Aquamacs 3.0a。 cperl-version is 6.2. cperl-version是6.2。 When I edit a Perl constant block I get extra indentation that I don't want:- 当我编辑一个Perl常量块时,我得到了我不想要的额外缩进: -

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. 问题似乎是添加了cperl-continue-statement-offset,因为我们在一个块内,并且在前一行的末尾没有分号。

Is there a way to tell cperl to indent constant blocks using "parens" rules? 有没有办法告诉cperl使用“parens”规则缩进常量块? I did try tweaking cperl-indent-parens-as-block, but that didn't help. 我确实尝试过调整cperl-indent-parens-as-block,但这没有帮助。 I'm not surprised, I guess I should be looking for a variable called cperl-indent-constant-block-as-parens :-) 我并不感到惊讶,我想我应该寻找一个名为cperl-indent-constant-block-as-parens的变量:-)

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! 在代码中进行一些挖掘表明这是cperl模式中的一个错误 - 它应该像匿名hashref一样处理一个常量块 - 毕竟,这基本上就是它! Here's a patch to cperl-block-p that makes it so. 这是cperl-block-p的一个补丁,它就是这样的。 Would anyone care to approve or reject this? 有人会关心批准还是拒绝这个? My elisp is a bit rusty :-) 我的elisp有点生疏:-)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM