如何设置两种不同的格式样式并将它们映射到 Eclipse 中的不同快捷方式
每次在 Eclipse 中打开文件时,我都想将源代码格式化为 Allman 风格的缩进。每次保存时,它都应该格式化为办公室中指定的样式。
我可以手动执行此操作并有两个热键:
- Ctrl-Alt-PgUp:我的方式
- Ctrl-Alt-PgDown:高方式
热键选项很好,因为这样我就可以验证一切都很好,而不是它在幕后无形地发生。
然而,Eclipse 只有一个格式选项。我需要的是两种格式样式并将它们分别映射到一个快捷键。这可能吗?如果可能的话,如何实现?
Every time I open a file in Eclipse, I want to format the source code to Allman-style indentation. Every time I save, it should format to the dictated style in the office.
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 good because then I get to verify all is well instead of it happening invisibly behind the scenes.
However, Eclipse only 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,Eclipse JDT UI 尚不支持应用不同的代码格式化程序。
错误号 45423 旨在解决此问题。只要该错误仍未修复,最好的解决方法就是在提交挂钩中应用格式化程序,因为每个项目都与其自己的格式化程序相关联;您甚至无法选择不同的格式化程序来应用于文件保存操作(首选项 -> Java -> 编辑器 -> 保存操作)。老实说,我认为快捷键根本不起作用。
另外,可能值得研究 Questoid Code Formatter 的使用,它似乎是最接近(或唯一)支持您的需求的插件。我还没有尝试过使用它;我只阅读了 Eclipse Marketplace 的描述。
Unfortunately, Eclipse JDT UI does not support applying different code formatters yet.
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.
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.