在 Pharo 中保存方法时自动格式化
Pharo 有一个内置的代码格式化程序。我希望每当我保存方法时,Pharo 都会忽略我的所有格式并自动格式化代码。可以吗?
Pharo has a built-in code formatter. I want that whenever I save a method, Pharo ignores all my formatting and auto-formats the code instead. Can that be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当然,如果您使用重构引擎和 OmniBrowser,则有一个设置:在“设置浏览器”中导航至“重构引擎”>“重构引擎”。接受时自动格式化。还有设置重构引擎>显示时自动格式化,在显示之前自动格式化代码。格式化设置本身位于重构引擎>中可配置的格式化程序。
Sure, there is a setting if you use the Refactoring Engine and OmniBrowser: In the "Settings Browser" navigate to Refactoring Engine > Auto Format on Accept. There is also the setting Refactoring Engine > Auto Format on Display, which automatically formats the code before it is displayed. The formatting settings themselves are in Refactoring Engine > Configurable Formatter.
我想出了一种技巧,来处理自格式化方法保存。它可能会派上用场。
在 NautilusUi -> 中compileSource: aText notification: aController
在开头添加这一行。
也就是说,这将在保存功能上创建自动格式。我也承认,这不是正确的方法,但它对我有用。
I figured out a sort of hack , to deal with self formating method saves. It might come in handy.
In
NautilusUi -> compileSource: aText notifying: aController
add this line in the begining.
That is this will create the auto format on save functionality. Also i admit, that this is not the right way to do this, but it works for me.
对于 OmniBrowser,我添加了这个新方法:
For OmniBrowser, I added this new method:
不完全是OP所要求的,但我认为这是值得考虑的。在项目中工作时,当 Pull 请求仅显示功能性代码更改而不会出现与编码风格相关的误报时,规范化代码格式将有助于同行评审者的工作。
我正是为此发布了 PharoPackageFormatter 。
以下是如何使用它的示例:
Not exactly what OP is asking but I think this is worth considering. When working in a project, having code formatting normalized would facilitate the life of peer-reviewers when the Pull Requests show only functional code changes without the false positives related to coding style.
I've published PharoPackageFormatter precisely for this.
Here is an example of how you would use it: