Some hack you just found and want to tell to others

Code Sniplets and Abbreviations

Postby fmadrid » 4. Dec 2008, 15:43

Code Sniplets and Abbreviations

In a Workspace you can remember a piece of code as a so called "Code Sniplet" and later insert it whenever it's needed. These sniplets are shared among multiple workspaces (they are not lost, when a workspace window is closed). However, they are only persistent inside the image, which means that there is not external file persistency. If you forget to save a snapshot image, or you start st/x anew, these sniplets are lost (in future versions, we will include the possibility to save and load Sniplets).

To add a Code Sniplet, you should select a piece of code, then go to the menu option "Edit>>Copy as Sniplet..." and define a sniplet name. Later you can paste them as many times you like, going to the menu option "Edit>>Paste Sniplet..." and select the desired sniplet by it's name.

Sniplets can also be used as abbreviations, in every Workspace or Code pane (also inside the SystemBrowser), typing the Sniplet name and then press ALT+SPACE. The Sniplet name will be automatically replaced by it's corresponding piece of code.

Some useful abbreviations included by default in Smalltalk/X are:

ps >> printString
sh >> self halt.
itf >> ifTrue: [!] ifFalse: []
trs >> Transcript showCR:
OCn >> OrderedCollection new.
Aww >> Array with:! with:

Note: after replacing the abbreviation the cursor will appear in the position marked with "!".

To see all the available abbreviations, you should go to the Workspace menu option: "Edit>>Manage Sniplets...".
To add new abbreviations, simply add a new code Sniplet as explained above.

Edit by cg:
You can change the default abbreviations by editing
Workspace class >> initializeDefaultAbbreviations
fmadrid
 
Posts: 10
Joined: 19. Nov 2008, 18:49

Return to Tips and Tricks

Users browsing this forum: No registered users and 2 guests

Design by GB