只想看到Allman风格的代码,并保存K&R风格的代码 [英] Only want to ever see Allman style code and save K&R style code

查看:687
本文介绍了只想看到Allman风格的代码,并保存K&R风格的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的开发人员决定,他会向其他开发人员规定人们应该如何格式化源代码。

One of our developers decided he'd dictate to other developers how people should format their source code.

我自己,我坚信Allman风格的缩进比K& R更好。

Myself, I'm a firm believer that Allman style indentation is better than K&R.

格式化样式就像宗教,总是有些不同意。不管有多少证据表明一个人比另一个更好,人们不会接受。

Formatting styles is like religion, there are always those that disagree. No matter how much evidence is shown that one is better than the other, people will not accept it.

所以我想做的是每次打开一个文件在Eclipse中,我有格式化源代码,以便我可以看看漂亮的代码。
每次我保存,它应该格式化为办公室中的规定样式。

So what I want to do, is every time I open a file in Eclipse, I have it format the source code, so that I can look at pretty code. Every time I save, it should format to the dictated style in the office.

我认为我可以手动进行此操作,它的钥匙。
Ctrl-Alt-PgUp:我的方式
Ctrl-Alt-PgDown:高级方式

I think I'm ok with doing this manually and having two hot-keys for it. Ctrl-Alt-PgUp: my way Ctrl-Alt-PgDown: high way

热键选项可能很好,因为我得到验证一切都是好的,而不是在幕后不可见。

The hot key option is probably good because then I get to verify all is well instead of it happening invisibly behind the scenes.

Eclipse有一个格式的选项。我需要的是两种格式化样式,并将它们映射到快捷键。那么可能的话,如果是的话,怎么样?

Eclipse has a single format option. What I need is two formatting styles and map them each to a shortcut key. Is that possible, and if so, how?

推荐答案

好吧,这个古老的辩论似乎回来了。不幸的是,Eclipse JDT UI不支持应用不同的代码格式化程序。

Well, it seems like the age-old debate is back. Unfortunately, Eclipse JDT UI does not support applying different code formatters yet.

有一个 bug no 45423 ,这是为了解决这个问题。只要该错误仍然不固定,最好的解决方法是在提交钩子中应用格式化程序,因为每个项目都与它自己的格式化程序相关联;您甚至不能选择一个不同的格式化程序来应用于文件保存操作(首选项 - > Java - >编辑器 - >保存操作)。老实说,我不认为快捷键甚至可以工作。

There's bug no 45423, which is intended to resolve this. As long as that bug remains unfixed, the best workaround would be applying a formatter in a commit hook as each project is associated with it's own formatter; you cannot even choose a different formatter to apply on the file save action (Preferences -> Java -> Editor -> Save Actions). Honestly, I don't think shortcut keys would even work.

另外,可能值得研究使用 Questoid Code Formatter ,它似乎是最接近(或只有)插件来支持你的需要。我没有尝试使用它;我只读了Eclipse Marketplace的描述。

Also, it might be worth investigating the use of the Questoid Code Formatter, which appears to be the closest (or only) plugin to support your need. I haven't attempted using it; I've only read the description from Eclipse Marketplace.

这篇关于只想看到Allman风格的代码,并保存K&R风格的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆