Until Smallworld 5 was released, emacs was the standard editor with which to write Magik code. As such I’ve been using it for more than 25 years.
It was okay and got the job done.
But what I really wanted to use was a modern editor with features such as context-aware autocomplete, tree-like navigation, outline view, go to definition, hover-to-reveal and all the other modern features to which I had become accustomed using IDEs such as Visual Studio,
I even tried an Eclipse-based product called MDT for about a year. It wasn’t bad, but it was fairly expensive and slower than emacs. So I went back to emacs.
They were okay, but were slower than VS Code and a bit too heavy for my liking. I preferred VS Code’s ability to extend itself with just the functionality I wanted, through its myriad extensions, rather than having things I didn’t use prepackaged. So I started using VS Code for all my development work — except for two areas: Magik and VB.Net/C#.Net.
“But wouldn’t it be nice to get rid of emacs and use VS Code for everything?” I was constantly thinking. Then Smallworld 5 was released and some VS Code extensions appeared.
I tried two of them and settled on the one by Siamak Zolghadri. So far I’m quite happy with the results. I’m now using VS Code for practically all my development needs and it makes life so much easier.
However there are a couple areas still lacking.
First, there is no emacs-like functionality to recall previous commands based on a sub-string (e.g. typing, “t <<” and F2-P to bring back the, “t << v.collections[:hotel]” command).
Second, the Magik buffer doesn’t recognize keywords and automatically pre-pend the underscore. So rather than typing, “loop” and having it show up as, “_loop”, you have to remember to type, “_loop” in the buffer.
Otherwise VS Code does everything I’d hoped, and its myriad advantages far outweigh these two issue.
So if you’re interested in upgrading to a modern editor for Magik development, I highly recommend VS Code. You’ll find a step-by-step guide, below, for installing and configuring VS Code for use with Smallworld 5.
How to Install and Confgure VS Code for Smallworld 5
- Install Visual Studio Code and open the application.
- Select the extensions tab (in the left window pane) and search for, “Smallworld Magik for Visual Studio Code”. The author is, Siamak Zolghadri.
Select File->Preferences->Settings and search for, “Smallworld GIS”, under Extensions. You can edit the settings.json file according to your preferences. You can also edit the sessions and startup json. Startup allows you to set environment variables and run scripts before gis.exe runs. Search for, “smallworld.giscomm” to see the GIS command that will run to start a Smallworld session.
- Type F2-z and select, “>Click here to add a new GIS Command, or select one from the list”. If this is your first time, you won’t have any commands in the list.
- Enter a command in the following format:
-p <path to Smallworld Core product> -a <path to gis_aliases file with desired stanza>
For example, if your core product is installed in, “D:\Services\Smallworld521\core” and your local gis_aliases file is located at, “D:\Services\Smallworld521\cambridge_db\config” and the stanza you want is, “cambridge_db_open” you would enter the following:
“-p D:\Services\Smallworld521\core -a D:\Services\Smallworld521\cambridge_db\config\gis_aliases cambridge_db_open”
- Note you can also add the, -e flag to specify a specific environment.bat file. If you don’t specify this flag, the environment.bat file that resides in the folder with gis_aliases will be used.
- By default VS Code’s terminal uses Powershell. However the Smallworld GIS extension requires the CMD shell (or else it will not work). To change from Powershell to CMD, type Ctrl-Shift-P and at the “>” prompt enter, “shell”. Then select, “Choose Terminal: Select Default Shell” and finally choose, “CMD”.
- At this point you can type F2-z again and select the command you entered in step 4. This will start the Smallworld session in a Terminal window using the CMD shell.
- When the session starts, you can login and start a Smallworld Application in the usual manner.
- Select File->Open Folder and navigate to your local source code repository so you can view and edit files.
- The familiar Emacs commands (such as F2-B to compile a method and F2-F2 to open Class Browser) are available. For a full list of commands, select File->Preferences->Keyboard Shortcuts and search or scroll to the “SW” section.
This will list the available extension commands such as F2-<up arrow>, F2-<down arrow>, F2-J, Ctrl-F9 (compile all Magik in editor), F2-B (compile method), Shift-F9 or F2-L (compile Magik line), F2-S (compile Magik selection), F2-Z (Run GIS Command), F2-C (clear workspace cache) F2-D (dump workspace cache).
- Use Ctrl ` to switch between the editor and Magik buffer and Ctrl j to toggle between hiding and showing the terminal.
- Type Ctrl t and then type a method name (such as “geojson”). Select the item you’d like and you can jump to its source code. The format for searching is: “#Package:Class.Method” (e.g. “#sw:point.as_geojson”).
- Type F2-F2 to open Class Browser.
- There are a ton of other VS Code extensions, debuggers and tools you can install. VS Code also allows you to hover the cursor over class and method names, right click and bring up a menu with other useful options.
It also provides a nice breadcrumb feature so you know exactly where the current file is located as well as the class and method names.
If you’ve been using emacs because it was all that was available, like I had been, go ahead and give VS Code a try. I think you’ll be pleased. And if you find yourself doing non-Magik development, you can probably use VS Code for that too.
And of course it’s cross-platform so you can use it on your MacOS and Linux computers as well.