Java 编码风格和Emacs cc 模式配置
我在 GNU/Linux Debian 机器上使用带有 cc 模式(c 版本 5.32.2)的 GNU/Emacs HEAD。
我正在尝试定义自定义样式来管理 Java 编程的 代码约定语言、Android 贡献者代码风格指南以及一些自定义规则。
作为一个 Lisp 初学者,从头开始似乎并不明智。因此,我使用了 google-c-style 作为起点,我设法获得了大多数缩进规则的预期行为,但嵌套条件除外(请参阅下面的代码片段)。
来自 帖子,我在自定义样式中定义了 (arglist-cont-nonempty . ++)
(完整代码:custom-java-style.el)。不幸的是,尽管大多数情况都按预期缩进:
if ((condition1 && condition2)
|| (condition3 && condition4)
||!(condition5 && condition6)) {
doSomethingAboutIt();
someMethod(longExpression1, longExpression2, longExpression3,
longExpression4, longExpression5);
}
嵌套条件错误缩进:
if (!(deviceRegistred.getAddress().equalsIgnoreCase(deviceAdress)
&& deviceRegistred.getName().equalsIgnoreCase(deviceName))) {
doSomethingAboutIt();
}
Ctrl-c Ctrl+s 报告 语法分析: ((arglist-cont-nonempty 2447 2450) (arglist-cont-nonempty 2447 2452))
在第二行,我显然有 16 个空格(2 次 ++
)缩进,而不是 8 次(++
)。
我想得到以下缩进:
if (!(deviceRegistred.getAddress().equalsIgnoreCase(deviceAdress)
&& deviceRegistred.getName().equalsIgnoreCase(deviceName))) {
doSomethingAboutIt();
}
我尝试定义一个 (,(when (fboundp …)))
条件,类似于用于 statement-cont
的条件,但没有成功(我缺乏 lisp 知识也无济于事)。
现在,问题是:我的方法是对还是错?我可以/应该如何实现预期的行为(即检测我何时处于嵌套条件以获得正确的缩进)?
(我不想使用 malabar-mode 或 JDEE,所以请不要告诉我使用它们。)
干杯,
Renaud
更新 2011/12/06(对评论做出反应)
我们不会不要在这里开始一场圣战。想用Emacs的人,因为自己的原因,可以坚持用Emacs,其他人就随心所欲……
话说回来,我在一个团队里,只有我一个人用Emacs,其他人都喜欢蚀。由于我负责编码规则,因此我与同事合作以获得正确的保存操作并帮助配置 Eclipse 的格式化程序。我只能说:Eclipse 保存操作和格式化程序根本不容易配置……主要区别是您有一个带有漂亮复选框的漂亮 GUI,但它对降低复杂性没有太大帮助。
我坚持使用 Emacs...
I'm using GNU/Emacs HEAD with the included cc-mode (c-version 5.32.2) on a GNU/Linux Debian machine.
I'm trying to define a custom style to manage the Code Conventions for the Java Programming Language, Android's Code Style Guidelines for Contributors and some custom rules.
As a lisp beginner, it does not seem wise to start from scratch. As a consequence, I used google-c-style as a starting point and I managed to get the intended behavior for the most indenting rules, with an exception on nested condition (see the code snippet below).
From that post, I have defined (arglist-cont-nonempty . ++)
in my custom style (full code: custom-java-style.el). Unfortunately, although most cases is indented as intended:
if ((condition1 && condition2)
|| (condition3 && condition4)
||!(condition5 && condition6)) {
doSomethingAboutIt();
someMethod(longExpression1, longExpression2, longExpression3,
longExpression4, longExpression5);
}
Nested condition are wrongly indented:
if (!(deviceRegistred.getAddress().equalsIgnoreCase(deviceAdress)
&& deviceRegistred.getName().equalsIgnoreCase(deviceName))) {
doSomethingAboutIt();
}
Ctrl-c Ctrl+s report Syntactic analysis: ((arglist-cont-nonempty 2447 2450) (arglist-cont-nonempty 2447 2452))
on the second line and I obviously have a 16 spaces (2 times ++
) indentation instead of 8 (++
).
I'd like to get the following indentation:
if (!(deviceRegistred.getAddress().equalsIgnoreCase(deviceAdress)
&& deviceRegistred.getName().equalsIgnoreCase(deviceName))) {
doSomethingAboutIt();
}
I tried to define a (,(when (fboundp …)))
condition like the one used for statement-cont
but without success (my lack of lisp knowledge don't help either).
Now, the question: Is my approach right or wrong? How could/should I implement the intended behavior (i.e. detect when i'm in a nested condition to get the right indentation)?
(I don't want to use malabar-mode or JDEE, so please don't tell me to use them.)
Cheers,
Renaud
Update 2011/12/06 (reacting to the comments)
We wouldn't begin a holy war here. Those who want to use Emacs, for their own reasons, can stick to Emacs, the others will do as they want…
Saying that, I work within a team in which I'm the only one to use Emacs, the others are fond of Eclipse. Since I'm in charge of the coding rules, I have worked with my colleagues to get the right save actions and help to configure the Eclipse's formatter. All I could say is that: the Eclipse save actions and formatter are not easy to configure at all… The main difference is that you have a nice GUI with nice checkboxes but it doesn't help much to reduce the complexity.
I stick with Emacs…
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说,Emacs 做的是正确的事。
考虑这种情况:
如果嵌套条件缩进 8 个字符,这将是一个令人困惑的变体:
I'd say, that Emacs does the right thing.
Consider this case:
If nested condition was indented 8 chars that would be a confusing variant: