【问题标题】:Emacs cperl - indentation in constant blockEmacs cperl - 常量块中的缩进
【发布时间】:2014-06-30 16:36:37
【问题描述】:

我正在运行基于 GNU Emacs 24.3.50.2 的 Aquamacs 3.0a。 cperl 版本是 6.2。当我编辑一个 Perl 常量块时,我得到了我不想要的额外缩进:-

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

我想要的是这个:-

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

问题似乎是 cperl-continued-statement-offset 正在被添加,因为我们在一个块内并且上一行的末尾没有分号。

有没有办法告诉 cperl 使用“parens”规则缩进常量块?我确实尝试过调整 cperl-indent-parens-as-block,但这并没有帮助。我并不感到惊讶,我想我应该寻找一个名为 cperl-indent-constant-block-as-parens 的变量 :-)

【问题讨论】:

    标签: perl emacs cperl-mode


    【解决方案1】:

    在代码中的一些挖掘表明这是 cperl 模式中的一个错误 - 它应该像对待匿名 hashref 一样对待一个常量块 - 毕竟,它基本上就是这样!这是 cperl-block-p 的一个补丁,可以做到这一点。有人愿意批准或拒绝吗?我的 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))
    

    【讨论】:

    • 对我来说看起来很合理(尽管我对 Perl 语法知之甚少)。您可以通过M-x report-emacs-bug 向维护人员发送错误报告以及此补丁。
    • 感谢您的建议 - 我已经直接给 cperl-mode 维护者发了电子邮件。
    • 我可能应该提到,在这个补丁中我仍然需要将 cperl-indent-parens-as-block 设置为 t 以获得所需的缩进,但这正是它应该的方式。跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-16
    • 2011-05-24
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    相关资源
    最近更新 更多