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

Magik Class Hierarchy Graphs with Emacs' Graphviz

Large Magik codebases rarely keep every inheritance rule in one visible place. Method owners, inherited implementations and package-level conventions can make a hierarchy feel like folklore. A generated graph gives that structure a repeatable shape while exposing duplicate names and surprising inheritance edges. It becomes a map for developers, reviewers and maintainers of a long-lived Smallworld system.

Emacs is a natural home for the workflow because it already understands Magik buffers, source trees and project-specific commands. Add Graphviz as the drawing engine and the same hierarchy can move from runtime data or source analysis to a searchable SVG. The important design choice is not the picture alone, but the provenance of each edge.

Reading inheritance from Magik

Magik's hierarchy is not always expressed as a tidy class child extends parent declaration. The dependable inputs are the owner and parent information exposed by the relevant Smallworld release, or a source index that records the inheritance mechanism used by your packages. Keep class identity separate from method identity: a method attached to my:sales_order says who owns it, but it does not by itself establish the edge to its parent.

Normalise the extracted data into parent-child pairs before drawing anything. For example, a project with business, sales and service packages might yield records shaped like this:

("sw:object" . "my:business_object")
("my:business_object" . "my:sales_order")
("my:business_object" . "my:service_order")

These records deliberately contain no method names. Overridden methods, helper methods and identically named routines in different packages can otherwise create a misleading method web. Preserve the fully qualified owner name in the underlying data, then shorten labels only in the rendered graph.

Do not infer inheritance from a super call, a similar name or the location of a method in a file. A method can invoke another object's implementation without making its owner a subclass. Where runtime metadata and source disagree, record the runtime relationship as authoritative for the deployed build and keep the source discrepancy visible to the team. Accessor names vary across Smallworld releases, so the extraction script should target the catalogue available in your own environment.

Modelling the hierarchy for Graphviz

Graphviz works best when the DOT model answers one clear question. For a class hierarchy, make each node a class and each directed edge an inheritance relationship from parent to child. This orientation works naturally with rankdir=TB: a root sits near the top and increasingly specialised classes descend beneath it. A node such as my:sales_order should normally have one incoming inheritance edge, even when many methods implement or override behaviour along that chain.

Use styling to carry information that a reader can scan. Rounded boxes can represent concrete classes, dashed boxes can mark abstract or extensible classes, and clusters can group packages such as GIS, network assets or customer records. Only apply an abstract style when your catalogue confirms it. Otherwise, a polished diagram can communicate a category that the runtime never declared.

A small DOT file establishes the pattern:

digraph magik_hierarchy {
  graph [rankdir=TB, label="Magik class hierarchy", fontsize=20];
  node [shape=box, style=rounded];
  edge [color="#666666"];

  "sw:object" -> "my:business_object";
  "my:business_object" -> "my:sales_order";
  "my:business_object" -> "my:service_order";
}

Large estates need more restraint than this. Filter to application packages before adding vendor internals, use concentrate=true for parallel edges, and split unrelated package hierarchies into separate graphs. A graph of several hundred readable classes is useful; a hairball of every framework method is not. For Australian teams using Australian English in their documentation, clear package labels and consistent modelled terminology matter more than decorative colour.

Generating DOT inside Emacs

Keep extraction, normalisation and rendering inside the editor so the graph can be regenerated without rebuilding a separate toolchain. The Magik Emacs resources provide a practical starting point for editor configuration and related Magik tooling. If the host already has Graphviz installed, dot -V should report its version; this check is worthwhile on a locked-down Windows workstation in Perth as well as a macOS laptop used in Melbourne.

A deliberately small Emacs Lisp function can turn parent-child records into DOT. The function below expects each cons cell to hold parent first and child second:

(defun magik-dot-name (name)
  (replace-regexp-in-string "\"" "\\\"" name))

(defun magik-write-hierarchy (edges file)
  (with-temp-file file
    (insert "digraph magik_hierarchy {\n")
    (insert "  graph [rankdir=TB, label=\"Magik class hierarchy\", fontsize=20];\n")
    (insert "  node [shape=box, style=rounded];\n")
    (insert "  edge [color=\"#666666\"];\n\n")
    (dolist (edge edges)
      (insert (format "  \"%s\" -> \"%s\";\n"
                      (magik-dot-name (car edge))
                      (magik-dot-name (cdr edge)))))
    (insert "}\n")))

(magik-write-hierarchy
 '(("sw:object" . "my:business_object")
   ("my:business_object" . "my:sales_order")
   ("my:business_object" . "my:service_order"))
 "magik-hierarchy.dot")

Replace the literal list with records from your scanner or runtime export, then open the resulting .dot file. Emacs releases differ in their Graphviz commands, so use M-x graphviz-dot where available or the equivalent DOT-mode command supplied by your configuration. Otherwise, M-x compile can run dot -Tsvg magik-hierarchy.dot -o magik-hierarchy.svg, after which the generated SVG can be opened in a browser. Keeping both files gives reviewers a readable source as well as a portable artefact.

Reviewing the hierarchy in practice

Treat the first rendering as evidence to check, not as a finished architecture document. Compare a few branches with source definitions and runtime ownership, looking for missing roots, duplicated nodes and edges that point in the wrong direction. Emacs navigation is particularly useful here: jump from a DOT node label back to the class declaration, then inspect nearby Magik methods without losing the graph in another window.

The distinction between a hierarchy graph and a call graph is essential. An inheritance edge says that a class receives or specialises another class's behaviour; it does not prove that either class calls the other. Method overrides, delegated services and dynamically resolved objects can all create runtime paths absent from the diagram. Describe the artefact precisely so a new developer does not mistake it for a complete execution trace.

Time zones and working patterns deserve explicit consideration in distributed reviews. A Sydney team and a Perth team often share the same AEST or AEDT business day, while Melbourne can be on a different daylight-saving date during the changeover. Store the DOT source and generated SVG together, identify the Smallworld build used for extraction, and hold the final visual review at an agreed arvo checkpoint rather than relying on whichever teammate happens to be online. That habit keeps the Australian delivery rhythm practical without turning a class map into a meeting exercise.

Sharing and maintaining the map

Put the generator and its input rules in the same repository as the Magik source, then automate the DOT and SVG outputs during the normal build. Graphviz is deterministic for a fixed input and tool version, so version-controlled output gives reviewers a stable diff. Record the Graphviz version and source-build identifier in a comment; relative paths and a standard font such as Helvetica reduce differences between developer machines.

The value grows in Australian Smallworld programmes across utilities, transport and mining, where business packages often sit beside GIS and network models. Package clusters let a Sydney water team focus on customer and asset classes while a Melbourne transport team can isolate corridor and schedule logic from the same wider hierarchy. A filtered graph can be published in the engineering wiki, whereas the complete runtime graph can remain in the controlled development environment.

Maintenance needs an owner and a refresh trigger. Regenerate after a package-level inheritance change, a Smallworld release or an alteration to filtering rules. Magik Emacs is operated by HydePark Consulting, so its documentation site also identifies where teams can obtain focused help when extraction rules become release-specific. Keep that contact point separate from the generated artefact so ownership of the diagram remains with the internal engineering team.

The practical choices differ by source and maintenance burden:

Approach Best suited to Main advantage Main constraint
Hand-written DOT Small, stable class sets Exact layout with minimal tooling Manual updates quickly become stale
Source index Offline and repository-wide analysis Repeatable without a running Smallworld system Must reproduce release-specific inheritance rules
Runtime catalogue Deployed-build verification Reflects the build actually in use Requires controlled access and careful handling of internal names
Emacs Graphviz workflow Day-to-day development and review Fast feedback in one editor Depends on Graphviz and disciplined filtering

Choose one bounded package and turn its inheritance records into DOT today. Open the file in Emacs, compile it with Graphviz, and place the reviewed SVG beside the source it describes. That single repeatable loop will reveal ownership gaps before they become expensive redesigns.

Begin with the package your team changes most often, add one extraction rule at a time, and make the first graph review part of the next Australian sprint. Once the pipeline is working, extend it to adjacent packages and publish each approved map where developers can reach it.

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