在Pharo中保存方法的自动格式化

时间:2011-08-17 08:57:31

标签: coding-style ide pharo

Pharo有一个内置的代码格式化程序。我希望每当我保存一个方法时,Pharo会忽略我的所有格式并自动格式化代码。可以这样做吗?

3 个答案:

答案 0 :(得分:3)

当然,如果您使用重构引擎和OmniBrowser,则会有一个设置:在“设置浏览器”中,导航到重构引擎>接受时自动格式。还有设置重构引擎>显示屏上的自动格式,在显示之前自动格式化代码。格式设置本身位于重构引擎>可配置格式化程序

答案 1 :(得分:2)

我想出了一种破解,处理自我形成方法的保存。它可能会派上用场。

NautilusUi -> compileSource: aText notifying: aController

在开头添加此行。

self refactor formatSourceCode.

这将创建保存功能的自动格式。我也承认,这不是正确的方法,但它对我有用。

 **compileSource: aText notifying: aController
        | source category method |
        self refactor formatSourceCode.
        source := aText asString.
        category := self selectedCategory.
        method := self selectedMethod.
        category ifNil: [ method ifNotNil: [ category := method protocol. ]. ].
        (category isNil and: [ method isNil. ])
            ifTrue: [

                source first isUppercase
                    ifTrue: [ ^ self compileAClassFrom: source notifying: aController. ].
                category := Categorizer default.
                ]
            ifFalse: [

                (category = self allLabel and: [ self selectedMethod notNil. ])
                    ifTrue: [ category := self selectedMethod protocol. ].
                ].
        self compileAMethodFromCategory: category withSource: source notifying: aController.**

答案 2 :(得分:0)

对于OmniBrowser,我添加了这个新方法:

OBTextMorphEditorWithShout>>accept
"
This method did not previously exist for this class.
It is a subclass hook to auto format code on accept.
"

(ORCmdFormat on: 'TargetIsNotUsed' for: self model) execute.
super accept
相关问题