Emacs cperl - 缩进恒定块 [英] Emacs cperl - indentation in constant block
问题描述
使用常量{
ONE => 1,
TWO => 2,
THREE => 3,
};
我想要的是: -
使用常量{
ONE => 1,
TWO => 2,
THREE => 3,
};
问题似乎是添加了cperl-continue-statement-offset,因为我们在里面一个块,在上一行的末尾没有分号。
有没有办法告诉cperl使用parens规则缩进常量块?我尝试调整cperl-indent-parens-as-block,但这没有帮助。我不是很惊讶,我想我应该找一个名为cperl-indent-constant-block-as-parens的变量: - )
在代码中挖掘一点,这表明这是一个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 @@
(和(memq(char-syntax(prior-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'
(或(和(look-at[a-zA-Z0-9 _:] + [ \\ t \\\
\f] * [{#]);方法调用语法
- (不(查找\\(bless\\ | return\\ | q [wqrx]?\\ | tr\\ | [smy] \\)\\>)))
+(not(looking-\\ bless\\ | constant\\ | return\\ | q [wqrx] \\ | tr\\ | [SMY] \\)\\>?) ))
;; sub bless :: foo {}
(progn
(cperl-backward-to-noncomment(point-min))
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 :-)
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))
这篇关于Emacs cperl - 缩进恒定块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!