Emacs Extensions for
GE Smallworld Magik Development

Screen-casts, tutorials, and productivity tools for Magik programmers who use Emacs. From tab-mode and code folding to the Magik Debugger and object inspector — explore features built by a developer, for developers.

Learn More
HydePark Consulting Screen-casts on YouTube RSS via FeedBurner

Nine screen-casts published between November 2010 and January 2011 — covering everything from ECB mode to the Tree Item GUI control. Read the story behind the project →

Get in Touch

Connecting Magik Database Tools With Emacs SQL Mode For Smoother GIS Workflows

Magik developers working on GE Smallworld projects spend a great deal of their day moving between code, object inspectors, and live database sessions. The Magik language talks natively to Smallworld's object-oriented datastore, while Emacs offers a battle-tested SQL mode that can highlight, format, and send queries against a wide range of backends. Bringing the two together reduces context switching, especially for teams scattered between Sydney, Melbourne, and Perth who often share the same Smallworld instances across state boundaries. The result is a tighter feedback loop when inspecting collections, validating product models, or prototyping new spatial queries.

Many Australian utility and mining organisations still keep their Smallworld data in on-premise databases, governed by the Privacy Act 1988 and the Australian Privacy Principles when personal or landholder information is involved. That makes careful, auditable querying essential, and a well-configured Emacs session becomes more than a convenience. It becomes a way to keep query history, schema documentation, and inspection buffers aligned with the legal and operational obligations that come with managing critical infrastructure data in a country that spans several time zones from Perth to the east coast capitals.

Understanding Magik's Database Interaction Layer

Magik communicates with the Smallworld datastore through a small, well-defined set of classes that wrap object collections, products, and property accessors. When a developer types sw_database.open() or runs a db_select() call, the request is dispatched through the Smallworld session's internal connection, which in turn serialises operations against the underlying tables. From the developer's seat in Adelaide or Brisbane, that mechanism feels almost transparent, but the round-trips are real, and so are the queries generated behind the scenes.

For most practitioners, the practical question is not how to bypass that layer but how to surface its activity. Magik's built-in trace facilities, along with extensions like magik-trace and the db_collection inspectors, can dump equivalent SQL-like statements that the engine produces. Once those statements are visible, the door opens to feeding them directly into an Emacs buffer. Developers in Australian consultancies such as HydePark Consulting routinely use this approach when preparing material for client workshops in Parramatta or St Kilda, where attendees want to see exactly what the database is doing on their behalf.

Setting Up Emacs SQL Mode For Smallworld Sessions

Emacs ships with sql-mode, but the Smallworld community has settled on a few small customisations. Most teams start by defining a product in their .emacs or init.el that points sql-product at postgres or oracle, depending on which datastore the Smallworld installation is fronted by. After that, the standard sql-connect command opens a dedicated SQLi buffer that survives across file edits, which is useful for developers who split their day between coding in Magik and validating changes against the staging cluster.

The second step is teaching sql-mode about the dialect that Magik's object-relational mapping emits. A few keyword entries and an indentation style borrowed from sql-indent go a long way. From a Sydney office window looking over the harbour, a developer can fire up M-x sql-magik, watch the prompt appear, and then run a SELECT generated from the same Magik code they are editing one buffer over. The two views stay in sync because Emacs treats the SQL buffer as a long-lived process, much like a Magik REPL.

Bridging Magik Object Collections With SQL Buffers

The real productivity gain comes when a Magik collection can be queried without leaving Emacs. A common pattern is to add a hook to magik-mode that watches for sw_collection! operations and pipes their equivalent SQL into the connected *SQL* buffer. From there, sql-send-line and sql-send-paragraph push the query to the database, while sql-mode keeps the syntax highlighting and history intact.

This is where research into object-oriented distributed systems becomes surprisingly relevant. Papers presented at venues like the ISORC distributed computing symposium explored how object proxies could be exposed as queryable services, an idea that maps neatly onto how Magik treats smallworld objects as persistent handles. By borrowing that mental model, an Emacs user can think of every collection as a window onto a queryable view, rather than as a sealed black box that has to be opened through a separate GUI tool. For teams in Hobart or Darwin working on remote installations, that mental shift removes a lot of friction.

Querying Collection Data Through Product And Object Inspection

Smallworld's product model is its strength, but it can also feel opaque. A gas_main is not a row; it is a tree of joined objects with geometry, ownership history, and network relationships attached. SQL mode handles the relational side, while Magik's inspectors handle the object side, and a good integration makes the two perspectives feel like a single tool.

A practical workflow looks like this: open the Magik object inspector for a record, copy the generated SQL representation into the SQL buffer, then refine the query with WHERE clauses that match the current selection. In a Brisbane water utility, this technique has been used to validate that a newly modelled pressure zone matches the operational territory in the GIS, all without leaving Emacs. Australian engineers often appreciate that the work happens in plain text, which means peer review over a flat white in Carlton or a coffee in Surry Hills becomes a real possibility rather than a screen-sharing exercise.

Customising Buffers For Australian GIS Projects

Local conditions shape how these buffers end up configured. Australian projects frequently deal with large cadastral datasets, indigenous land-use overlays, and state-level fire history layers, all of which generate long-running queries. A few small tweaks make the experience bearable: raising sql-query-batch-lines so that a thousand-row result does not freeze the UI, attaching comint-output-filter-functions to strip the ANSI codes that some PostgreSQL frontends emit, and binding a key to dump the current query to a .sql file for inclusion in change tickets.

Time zones also matter. When a team in Perth hands a query log to a colleague in Sydney, the timestamps have to be normalised to Australian Eastern Standard Time, or the conversation goes nowhere. A small before-save-hook that reformats now() output in the SQL buffer keeps the trail consistent. For projects that touch the My Health Records framework or the federal data sharing schemes overseen by the Office of the Australian Information Commissioner, that consistency is not cosmetic; it is part of the audit story.

Debugging And Logging Database Calls From Emacs

When something goes wrong, the instinct is to reach for the Smallworld GUI, but Emacs can do most of the work. edebug in Magik mode can step through a method while a companion SQL buffer watches the dispatched queries. Pairing the two requires only a small advice function that listens for magik-method-exit and pushes the corresponding statement into the SQL history. Developers in mining consultancies around Kalgoorlie have used this combination to track down a slow db_select that only fired on Thursdays, when the corporate refresh job from Melbourne collided with the local reporting cycle.

Logging deserves the same care. A dedicated *Magik SQL Trace* buffer, fed by a thin wrapper around the database access methods, gives a chronological view that survives across restarts. Because the buffer is plain text, it can be grepped, diffed, or attached to a ticket. For Australian operators under the Security of Critical Infrastructure Act 2018, that kind of reproducible trail is more than a debugging nicety; it is one of the artefacts that regulators expect to see during an audit.

If your team is wrestling with similar integration challenges, the engineers at HydePark Consulting have spent years tuning Emacs and Magik for Australian Smallworld deployments, from water authorities on the NSW Central Coast to mining tenants in the Pilbara. The consulting arm offers hands-on workshops, custom extension development, and remote debugging support that picks up directly from the workflows described above. Reach out through the contact form on the site to book a discovery call and see how a tighter Magik-Emacs integration can shorten your feedback cycles, sharpen your audit trail, and give your developers a single, keyboard-driven home for everything between code and database.

Core Features

Tab Mode & ECB

Quick tab switching and Emacs Code Browsing mode for navigating Magik codebases efficiently.

Magik Smeller

Code analysis tool that helps identify potential issues in Magik source files.

Code Folding

Hide/Show mode for collapsing and expanding Magik code blocks to focus on what matters.

Visual Bookmarks

Quick visual bookmarks for jumping between key locations in your Smallworld session buffers.

Object Inspector

Inspect Magik objects and display them in an Emacs Deep Print buffer for detailed examination.

Magik Debugger

Set breakpoints and monitor slots and variables directly from within Emacs.

Development Tools

Direct links between Emacs and the Smallworld Development Tools application, including Click Monitor.

Screen-casts & Tutorials

Dark code editor window with syntax-highlighted Magik source code in muted blues and greys, conveying a focused development environment

Screen-cast 1: Tab Mode, ECB & More

Covers tab-mode, ECB, Magik Smeller, code folding, visual bookmarks, pragma toggling, moving code, external editor, and MS Explorer.

November 7, 2010
Split-pane Emacs interface with multiple buffers open, warm amber and navy tones against a dark background

Screen-cast 5: Object Inspection & Deep Print

Inspect a Magik object, prompt for an expression evaluated within a Smallworld session, and display results in a Deep Print buffer.

January 16, 2011
Debugging interface with breakpoint markers and variable watch panels in subdued teal and charcoal tones

Screen-cast 7: Magik Debugger

Useful tools for application developers: Object Inspector and Magik Debugger with breakpoints and slot/variable monitoring.

January 2011
Tree control GUI element with expandable branches rendered in clean greys and muted blues on a light background

Screen-cast 9: Tree Item GUI Control

Tree Item is a GUI control providing extensive facilities for displaying lists with rows, columns, trees, and in-place editing.

January 20, 2011