Previous: , Up: Emacs  

4.2 Smalltalk interactor mode

An interesting feature of Emacs Smalltalk is the Smalltalk interactor, which basically allows you run in GNU Emacs with Smalltalk files in one window, and Smalltalk in the other. You can, with a single command, edit and change method definitions in the live Smalltalk system, evaluate expressions, make image snapshots of the system so you can pick up where you left off, file in an entire Smalltalk file, etc. It makes a tremendous difference in the productivity and enjoyment that you’ll have when using GNU Smalltalk.

To start up the Smalltalk interactor, you must be running GNU Emacs and in a buffer that’s in Smalltalk mode. Then, if you type C-c m. A second window will appear with GNU Smalltalk running in it.

This window is in most respects like a Shell mode window. You can type Smalltalk expressions to it directly and re-execute previous things in the window by moving the cursor back to the line that contains the expression that you wish to re-execute and typing return.

Notice the status in the mode line (e.g. ‘starting-up’, ‘idle’, etc). This status will change when you issue various commands from Smalltalk mode.

When you first fire up the Smalltalk interactor, it puts you in the window in which Smalltalk is running. You’ll want to switch back to the window with your file in it to explore the rest of the interactor mode, so do it now.

To execute a range of code, mark the region around and type C-c e. The expression in the region is sent to Smalltalk and evaluated. The status will change to indicate that the expression is executing. This will work for any region that you create. If the region does not end with an exclamation point (which is syntactically required by Smalltalk), one will be added for you.

There is also a shortcut, C-c d (also invokeable as M-x smalltalk-doit), which uses a simple heuristic to figure out the start and end of the expression: it searches forward for a line that begins with an exclamation point, and backward for a line that does not begin with space, tab, or the comment character, and sends all the text in between to Smalltalk. If you provide a prefix argument (by typing C-u C-c d for instance), it will bypass the heuristic and use the region instead (just like C-c e does).

C-c c will compile a method; it uses a similar heuristic to determine the bounds of the method definition. Typically, you’ll change a method definition, type C-c c and move on to whatever’s next. If you want to compile a whole bunch of method definitions, you’ll have to mark the entire set of method definitions (from the methodsFor: line to the ! !) as the region and use C-c e.

After you’ve compiled and executed some expressions, you may want to take a snapshot of your work so that you don’t have to re-do things next time you fire up Smalltalk. To do this, you use the C-c s command, which invokes ObjectMemory snapshot. If you invoke this command with a prefix argument, you can specify a different name for the image file, and you can have that image file loaded instead of the default one by using the -I flag on the command line when invoking Smalltalk.

You can also evaluate an expression and have the result of the evaluation printed by using the C-c p command. Mark the region and use the command.

To file in an entire file (perhaps the one that you currently have in the buffer that you are working on), type C-c f. You can type the name of a file to load at the prompt, or just type return and the file associated with the current buffer will be loaded into Smalltalk.

When you’re ready to quit using GNU Smalltalk, you can quit cleanly by using the C-c q command. If you want to fire up Smalltalk again, or if (heaven forbid) Smalltalk dies on you, you can use the C-c m command, and Smalltalk will be reincarnated. Even if it’s running, but the Smalltalk window is not visible, C-c m will cause it to be displayed right away.

You might notice that as you use this mode, the Smalltalk window will scroll to keep the bottom of the buffer in focus, even when the Smalltalk window is not the current window. This was a design choice that I made to see how it would work. On the whole, I guess I’m pretty happy with it, but I am interested in hearing your opinions on the subject.

Previous: , Up: Emacs