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

Emacs’ Imenu for Magik: Indexing Methods and Swamps

Large Magik codebases can become difficult to navigate long before they become difficult to run. A single source file may contain dozens of method definitions, related implementations, utility procedures and inherited behaviour. When that file is a swamp—a practical Magik source container holding many method definitions—scrolling from one declaration to another quickly becomes a poor substitute for a code index.

Emacs’ Imenu provides a lightweight answer. With a Magik-aware pattern, it can collect method declarations into a navigable menu, letting developers jump directly to a method from the menu bar or with imenu. The result is especially useful alongside Magik indentation, code folding, method lookup and object inspection tools.

Why Imenu matters in Magik development

Imenu scans the current buffer and builds an index from declarations that match configured expressions. In a conventional language, that might mean functions, classes and variables. For Magik, the most valuable entries are usually methods beginning with _method, along with procedures introduced by _proc where those are used in project code.

This matters because Magik method names often carry the information needed to understand a system. A declaration such as rope_network.calculate_route tells a developer which object owns the method and what operation it performs. An index based on the complete name is far more useful than a list of generic entries such as init, new, or display.

A swamp can make this benefit even clearer. The file may be arranged by subsystem, but its methods are not necessarily short or alphabetically ordered. Imenu turns the flat buffer into a searchable outline. A developer investigating a database collection in Melbourne, or checking a mapping workflow in Perth, can move between related methods without repeatedly searching for _method.

The feature is local to the buffer, so it does not require a language server, a separate indexing daemon or a complete project compilation. That makes it practical for older Smallworld environments, remote development sessions and consulting teams maintaining established Magik applications.

Building a useful Magik index

A basic configuration can use imenu-generic-expression to recognise method declarations. The following example is intentionally conservative: it looks for _method at the beginning of a line, allows indentation, and captures the declaration text before the argument list.

(defun magik-imenu-setup ()
  (setq-local imenu-generic-expression
              '(("Methods"
                 "^\\s-*_method\\s-+\\([^(\n]+\\)" 1)
                ("Procedures"
                 "^\\s-*_proc\\s-+\\([^(\n]+\\)" 1)))
  (imenu-add-menubar-index))

(add-hook 'magik-mode-hook #'magik-imenu-setup)

The exact regular expression may need adjustment for the Magik mode used by a site. Some teams place comments or pragmas before declarations, while others format method qualifiers differently. Testing the expression against real swamp files is important; a pattern that works on a tidy example may omit declarations with unusual spacing or naming.

The captured group should contain a readable method identity. If the expression captures only the final selector, methods owned by different objects may appear identical. Capturing object.method preserves useful context and reduces the risk of jumping to the wrong implementation.

Projects can also add separate categories for methods, procedures and special declarations. For example, a team might give _method entries one menu heading and _proc entries another. This keeps the menu compact while still exposing procedural utilities. If a project uses generated methods or non-standard declaration forms, those should be added only after confirming that they produce stable, meaningful index entries.

Making swamp files easier to navigate

Imenu works best when the source has consistent structure. A swamp does not need to be split into many small files to become manageable, but its declarations should follow a predictable layout. Keeping _method and _endmethod aligned, using consistent spacing and retaining the full receiver name in declarations all help both people and Emacs.

A practical arrangement is to group related methods by object or responsibility, with a short comment separating major areas. Comments are useful for human scanning, while Imenu provides the precise jump points. Folding can then hide the method bodies, leaving a compact list of method declarations visible in the buffer.

Method naming deserves particular attention. Names such as collect, load and print may be idiomatic within an object, yet they offer little help when presented in isolation. A receiver-qualified index, combined with descriptive selectors, gives a better outline of the swamp. In a mature application, this can reveal duplicate responsibilities and methods that have drifted far from the objects they support.

Developers should also decide how to handle private or generated methods. Hiding them may make the menu easier to read, but it can remove precisely the implementation detail needed during debugging. A useful compromise is to retain every declaration in the index and use prefixes, categories or a secondary command to narrow the list.

For teams working across Sydney and Brisbane, consistent formatting also reduces friction when source files move between consultants, clients and repositories. It gives code reviews a shared visual language and makes a swamp less dependent on the habits of its original author.

Combining Imenu with Emacs navigation

Imenu is most effective when treated as one part of a navigation workflow. M-x imenu opens a completion interface in many Emacs configurations, allowing a developer to type part of an object or method name. The menu-bar index is convenient for occasional browsing, while completion is faster when the target is known.

The index also complements ordinary search. Search is excellent for finding a string inside a method body, but it does not always distinguish declarations from calls, comments or documentation. Imenu starts with declarations and takes the developer to the method boundary. From there, narrowing, folding and incremental search can handle the details.

A useful workflow for a swamp is to refresh the index after editing declarations, jump to a method with imenu, fold its body, and then use method navigation to inspect related implementations. When debugging a collection query or a database-backed object, this sequence avoids losing the larger structure of the source file.

Imenu can be paired with which-function-mode, which displays the current method in the mode line as the cursor moves. That small piece of context is valuable in long methods and during stepping sessions. It also helps when an Emacs frame is split between source code, a listener and an object inspector.

For a distributed Australian team, this reduces dependence on shared screen sessions across time zones. A developer in Adelaide can identify the exact method being discussed with a colleague in Sydney, while a consultant working from home on an NBN connection can navigate locally without repeatedly requesting a full application walkthrough.

Keeping indexing reliable in real projects

The main failure mode is an index that appears to work but silently misses declarations. This can happen when a project uses tabs, unusual indentation, line breaks in method signatures or generated source. It is worth testing the expression against representative files from each major subsystem rather than relying on a single sample swamp.

A simple validation routine is to compare the number of visible _method declarations with the number of Imenu entries. Missing methods should be investigated before the configuration becomes part of a team-wide Emacs setup. Regexps should be specific enough to avoid indexing comments and examples, but flexible enough to recognise ordinary project variation.

Performance is another consideration. Imenu usually feels immediate on individual source files, though very large swamps or expensive dynamic index functions can cause delays. A generic regular expression is often sufficient. If a project needs hierarchical indexes, such as grouping methods under receiver names, a custom index function can provide that structure at the cost of additional maintenance.

Configuration should live with the Magik editing setup rather than in an individual developer’s private init file. A version-controlled Emacs library can document the expected declaration style, test representative samples and make onboarding easier. Teams organising maintenance work may also record indexing tasks alongside broader delivery work in project tracking software, particularly when a swamp cleanup spans several repositories.

Australian organisations should also consider where source and diagnostic data are stored. If a consultancy handles customer records, transport networks or mapping information, the Privacy Act 1988 and contractual data-handling obligations may affect cloud repositories, remote access and log collection. Imenu itself does not transmit source code, which is useful in restricted environments, but the surrounding development workflow still needs appropriate controls.

Extending the index without losing simplicity

Once basic method indexing is dependable, a project can add selective structure. A custom Imenu function might group methods by receiver, recognise _proc declarations, or create a separate section for hooks and callbacks. It could also use nearby comments as headings, provided those comments follow a stable convention.

The safest extensions are those that improve discovery without trying to become a full parser. Imenu is a navigation aid, not a replacement for Magik compilation, inheritance analysis or runtime inspection. A complicated regexp that attempts to understand every language feature can be harder to maintain than a modest index that handles the dominant coding style.

Generated code deserves a clear policy. If generated swamp files are routinely overwritten, local edits to their indexing conventions will not survive. In that situation, configure Imenu around generated declaration patterns and keep custom documentation in the source templates or build process. For hand-maintained files, a small formatting standard is usually enough.

It is also sensible to keep an escape route for exceptions. Developers should still be able to use ordinary search when a declaration is malformed, partially generated or hidden behind unusual syntax. Good tooling accelerates common work without making uncommon work impossible.

A well-tuned Imenu index gives Magik developers a reliable map of a swamp: method ownership remains visible, procedures are easy to locate and large files become less intimidating. Add it to the local Magik mode, test it against genuine project files and use the resulting index as a daily navigation tool rather than a decorative menu. For teams maintaining Smallworld systems, that small Emacs improvement can shorten investigations, clarify code reviews and make inherited code substantially easier to work with.

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