Ad blocker interference detected!
Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers
Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.
Status: integrated into 2.0b!
This document gives an overview of smalltalk-mode and gst-mode for GNU Emacs 20 and 21. Since this is a wiki, proof reading is left as an exercise for the reader ;).
Smalltalk-mode provides two major features: font-locking (highlighting) and auto indenting. There is also support for evaluating expressions in a gst-mode buffer, and some rudimentary support for templates.
Font-locking information comes from two sources: the syntax-table (stored in smalltalk-mode-syntax-table) and the font-locking `keywords' (stored in smalltalk-font-lock-keywords). The syntax table is used to highlight comments and strings, something that cannot be handled with regular expressions (at least, not as easily). Previous versions used the hilit19 package which could only highlight strings (and thus comments where treated like strings).
In order to add new font-locking features, one should modify smalltalk-font-lock-keywords (located near the top of smalltalk-mode.el) by adding regexs to identify new patterns. There are three different -keywords variables for each level of font-locking provided by Emacs. The highest group (-keywords-3) should contain the most expensive computationally to find, while the base -keywords should have simple (but important) keywords. See the Elisp documentation for more information.
The syntax table not only provides information for font-lock, but also allows certain functions to parse Smalltalk code. These functions might, for example, be used to find out if the point is in a comment or a string, or be used to pass over the next `n' comments.
Now, Smalltalk comments are particularly troublesome because the same character (a single `"') is used to both start and end a comment. It is therefor impossible to tell whether you are in a comment or not without parsing the entire file from the beginning. Vim has trouble with this, as you can see by moving around a smalltalk file. Code will be erroneously highlighted as a comment. This is not a problem for strings since they rarely span more then a couple of lines.
Emacs seems to be more intelligent and can parse many-line strings correctly (or well enough), but in Emacs 19 the designers did not consider generic comment delimiters. So the original smalltalk-mode parsed comments as strings.
So what is the point of all this? Well, when I updated the mode to Emacs 20, I fixed the syntax table to parse comments correctly. All the auto-indenting functions expected Emacs to parse comments as strings, and thus had hacks around this. I think I fixed all the functions, but if there are any odd bugs crawling around, this is most likely to blame. I did not do any extensive testing...
OK, so now the other major smalltalk-mode feature is auto-indenting. The general drill is that when TAB is pressed smalltalk-indent-line is called, which tries to identify it's context and indent the line appropriately. It uses narrow-to-region a lot to cut out surrounding noise and focus in on relevant code. This is where the syntax table bugs come up, because it uses it heavily to parse code.
An easy way of tracking down these bugs is to uses Emacs' elisp debugger. Just type `M-x debug-on-entry' and point it at smalltalk-indent-line. The next time you press TAB the debugger will start up and you can step through code. It is usually helpful to have smalltalk-mode.el opened up someplace else so you can follow the code. When done debugging use `cancel-debug-on-entry' to clear the break.
GNU Smalltalk also comes with gst-mode.el. Smalltalk-mode is fairly separate and can probably be used with other Smalltalks (at least, maybe, with a little tweaking) but gst-mode is GNU Smalltalk specific. It's basically a lot like starting `gst' from an eshell, but it saves your command history and you have smalltalk-mode file code directly into it. For example, if you type `C-c C-f' you can pick a file to file into the running interpreter just as if you had typed `FileStream fileIn: 'file.st'!'.
To start a session just type in `M-x gst'. To stop it, just kill the buffer with `C-x k'. If you stop the interpreter with `ObjectMemory quit!' the buffer will remain, and if GST is ever restarted it will reuse that buffer.
I did not spend a lot of time going over gst-mode.el, but basically it uses the comint (command interpreter) package and is pretty straight forward.
Originally there was an Emacs class browser package as well, but it was removed since no one wanted to maintain it. It was not very feature rich anyways, and most people just use the texinfo documentation or the Blox interface. If you really just want to explore Smalltalk, then I suggest checking out Squeak. It provides a much more traditional Smalltalk environment, excellent for exploring, while GNU Smalltalk is a little more down to business. YMMV, however, so try them both ;).