Is there a way to automatically format a method during the compilation phase or immediately after?
I followed the advice from this question on stackoverflow 14234003 and from there created this simple method to add instance variables and the basic accessors in one go. addVarsAndTheirAccessors: aCollection on: aClass aCollection do: [ :each | aClass addInstVarNamed: each; compile: each, ' ^ ', each classified: 'accessing'; compile: each,': aByteString ',each, ' := aByteString' classified:'accessing' ] Currently I have to click on the created methods and format them in the browser. Is there an option to format the method during the compile phase or an method that can be passed a collection of methods to format automatically? -- Frank Church ======================= http://devblog.brahmancreations.com
Frank Church wrote:
I followed the advice from this question on stackoverflow 14234003 and from there created this simple method to add instance variables and the basic accessors in one go.
addVarsAndTheirAccessors: aCollection on: aClass aCollection do: [ :each | aClass addInstVarNamed: each; compile: each, ' ^ ', each classified: 'accessing'; compile: each,': aByteString ',each, ' := aByteString' classified:'accessing' ]
Currently I have to click on the created methods and format them in the browser.
Is there an option to format the method during the compile phase or an method that can be passed a collection of methods to format automatically?
I don't know the answer but here is how I might find out.... Note I am actually only doing this for the first time, so I'll lay it out in detail in case I can learn from someone else poking holes in it. 1. Bring up the context menu in the browser so that it shows the <Format> menu item 2. Use Alt-Shift-Click (on Windows) to bring up halos on the <Format> menu item, so that you see it is aToggleMenuItemMorph 3. Click the green Duplicate action then put the menu item down on the background. Check that clicking that copied button will format the code in the browser 4. Bring up halos on that duplicated menu item, so that it shows as aMenuMorph (I don't know why it changed from aToggleMenuItemMorph) 5. Click the grey spanner to Debug > Inspect Morph 6. Notice that instance variable 'submorphs' is aToggleMenuItemMorph. Inspect 'submorphs' and then inspect item 1 of the Array to get an inspector on aToggleMenuItemMorph. 7. This inspector shows the following instance variables... target: anORCmdFormat selector: #perform:orSendTo: In the pane at the bottom of the inspector, execute... self selector: #xxx:yyy: and observe the instance variable change 8. Click the duplicated menuitem still sitting on the background. A debugger opens with a MNU #xxx:yyy: Observe that the following message is selected... perform: selector withArguments: arguments since in [12.] you will Step Into this point. 9. Select the second line from the top of the call stack, which is #invokeWithEvent: Observe the instance variable 'selector' shows #xxx:yyy: 10. In the bottom pane second from the left, execute... self selector: #perform:orSendTo: and observe the instance variable change 12. Click <Restart> from the debugger Step Over until you can Step Into the message you observed in [8.] After twice stepping-into, you should be in ORCmdFormat>>execute which looks like it has a few things that will be useful to you. I'll leave it there for you to continue tracing. cheers -ben
Which version of Pharo? in 1.1-1.4 open the world menu, click system, click settings, type format, click the top 5 checkboxes. Probably the same in Pharo 2 too. On 01/12/2013 08:29 AM, Ben Coman wrote:
Frank Church wrote:
I followed the advice from this question on stackoverflow 14234003 and from there created this simple method to add instance variables and the basic accessors in one go.
addVarsAndTheirAccessors: aCollection on: aClass aCollection do: [ :each | aClass addInstVarNamed: each; compile: each, ' ^ ', each classified: 'accessing'; compile: each,': aByteString ',each, ' := aByteString' classified:'accessing' ]
Currently I have to click on the created methods and format them in the browser.
Is there an option to format the method during the compile phase or an method that can be passed a collection of methods to format automatically?
I don't know the answer but here is how I might find out.... Note I am actually only doing this for the first time, so I'll lay it out in detail in case I can learn from someone else poking holes in it.
1. Bring up the context menu in the browser so that it shows the <Format> menu item
2. Use Alt-Shift-Click (on Windows) to bring up halos on the <Format> menu item, so that you see it is aToggleMenuItemMorph
3. Click the green Duplicate action then put the menu item down on the background. Check that clicking that copied button will format the code in the browser
4. Bring up halos on that duplicated menu item, so that it shows as aMenuMorph (I don't know why it changed from aToggleMenuItemMorph)
5. Click the grey spanner to Debug > Inspect Morph
6. Notice that instance variable 'submorphs' is aToggleMenuItemMorph. Inspect 'submorphs' and then inspect item 1 of the Array to get an inspector on aToggleMenuItemMorph.
7. This inspector shows the following instance variables... target: anORCmdFormat selector: #perform:orSendTo: In the pane at the bottom of the inspector, execute... self selector: #xxx:yyy: and observe the instance variable change
8. Click the duplicated menuitem still sitting on the background. A debugger opens with a MNU #xxx:yyy: Observe that the following message is selected... perform: selector withArguments: arguments since in [12.] you will Step Into this point.
9. Select the second line from the top of the call stack, which is #invokeWithEvent: Observe the instance variable 'selector' shows #xxx:yyy:
10. In the bottom pane second from the left, execute... self selector: #perform:orSendTo: and observe the instance variable change
12. Click <Restart> from the debugger Step Over until you can Step Into the message you observed in [8.] After twice stepping-into, you should be in ORCmdFormat>>execute which looks like it has a few things that will be useful to you.
I'll leave it there for you to continue tracing.
cheers -ben
participants (3)
-
Ben Coman -
Frank Church -
Paul DeBruicker