我怎样才能让emacs cperl-mode 将所有语句延续仅缩进一级?
在 emacs 的 cperl 模式中,从前一行继续语句的行缩进一级:
my $var
= (1+1)
* (2+2)
/ (3+3);
但是,如果语句由于位于块内而不以零缩进开始,那么如果将语句中断到第三行,你会得到另一个级别的缩进,等等:
sub break_my_indentation {
my $var
= (1+1)
* (2+2)
/ (3+3);
return "Indentation is broken.";
}
有没有办法解决这个问题,以便语句在块内部的缩进方式与块外部的缩进方式相同?我希望第二个例子看起来像这样:
sub fix_my_indentation {
my $var
= (1+1)
* (2+2)
/ (3+3);
return "Indentation is fixed.";
}
In emacs' cperl-mode, lines that continute a statement from a previous line are indented by one level:
my $var
= (1+1)
* (2+2)
/ (3+3);
However, if the statement does not begin at zero indentation because it is inside a block, then if you break your statement onto a third line, you get another level of indentation, and so on:
sub break_my_indentation {
my $var
= (1+1)
* (2+2)
/ (3+3);
return "Indentation is broken.";
}
Is there any way to fix this so that statements are indented the same way inside blocks as they are outside? I would like the second example to look like this:
sub fix_my_indentation {
my $var
= (1+1)
* (2+2)
/ (3+3);
return "Indentation is fixed.";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我确认您所描述的行为存在,但是,从阅读源代码并在调试器下运行来看,并不明显有一个自定义可以让您获得您(和我)想要的行为。
因此我认为这是 cperl-mode 中的一个错误。
修复方法是:
请测试此补丁;如果您对此感到满意,我将添加自定义来启用它。
I confirm that the behavior you describe is present, but, from reading the sources and running under the debugger, it is not obvious that there is a customization which gets you the behavior you (and I) want.
Therefore I think this is a bug in
cperl-mode
.The fix is:
Please test this patch; if you are happy with it, I will add a customization to enable it.
cperl-mode
默认情况下没有这个问题。默认情况下,它的缩进如下:您进行了自定义,以防止 cperl-mode 正确缩进。请参阅 cperl-indent-rules-alist 变量以了解缩进的配置。
cperl-mode
don't have this problem by default. By default, it indents like this :You have a customization that prevents
cperl-mode
to indent correctly. Seecperl-indent-rules-alist
variable for configuration of the indent.正如 @jerome-radix 所建议的,默认情况下
cperl-mode
不会出现您遇到的问题。这个问题当然可能出现在cperl-indent-rules-alist
中,但是还有很多其他地方需要查找。您使用的是哪个版本的模式? Ch v cperl-version RET
在调试此类问题时,您需要从一些基本的事情开始,看看是否可以重现错误。首先让大家知道您正在运行什么 Mx emacs-version。然后,通过运行
emacs -q
来消除您自己的自定义设置,以避免在启动时加载您的初始化文件:如果您在关闭自己的初始化文件的情况下仍然可以重现问题,那么请更进一步,使用 emacs -Q 在系统级别将其关闭:
As @jerome-radix suggests, the problem you're experiencing doesn't happen with
cperl-mode
by default. The problem could certainly by incperl-indent-rules-alist
, but there are a number of other places to look.What version of the mode are you using? C-h v cperl-version RET
When debugging this kind of question you need to start with a couple of basic things to see if you can reproduce the error. First let everyone know what M-x emacs-version you are running. Then eliminate your own customizations from the equation by running
emacs -q
to avoid loading your init file at startup:If you can still reproduce the problem with your own init file turned off, then go a step further and turn it off at the system level with
emacs -Q
: