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

Handling Large Magik Buffers with Emacs Global-Font-Lock

Working on a hefty Magik module in Emacs can feel like waiting for a kettle that never quite whistles — the buffer looks ready, but the highlighting crawls. This article walks through configuring Global-Font-Lock so that even multi-megabyte Magik source files render their keywords, method names, and slot references without freezing the editor. The discussion stays grounded in the regex, mode, and buffer-tuning tricks that keep fontification responsive while preserving the readable, colourful display Magik developers expect.

In several Australian utilities and asset-management shops — Sydney Water, Yarra Valley Water, Jemena, CitiPower, and Powercor — the Smallworld environment behind Magik powers the network models that keep gas, water, and electricity flowing. Engineers in those Melbourne and Sydney offices often open the same session object across thousands of lines and need an editor that does not stall on the first keystroke. A well-tuned font-lock setup is the difference between a sluggish diagnostic session and a snappy navigation experience.

The steps that follow cover Magik-specific font-lock definitions, the global mode that turns them on for every buffer, performance tuning via jit-lock, and the supporting tooling that makes sense of highlighted buffer text. By the end, large Magik files should open, jump, and refold almost as quickly as the small ones.

Why Syntax Highlighting Stalls on Very Large Magik Buffers

Font-lock is fundamentally a regex-driven highlighter. Every time a buffer changes, Emacs runs the configured keyword patterns against the modified region and applies faces based on the matches. For a 5,000-line Magik module full of _method, _proc, _pragma, define_slot, and literal type tags, this work scales quickly. The lag is rarely the regex itself; it is the cumulative cost of running dozens of patterns over a buffer that has grown past a few hundred kilobytes.

Magik code has a particular shape that makes naive highlighting expensive. Method definitions stretch across many lines, slot accesses use self.<slot_name> and super.<slot_name>, and conditionals mix >>, <<, and >> block markers with ._endblock() closures. Each token deserves a face, and well-stocked keyword lists do their job thoroughly. The trade-off is that thoroughness becomes throughput when the buffer is large.

A second source of slowdown is communication with a running Magik session. Many installations wire imenu or speedbar into an external Smallworld process running over a TCP socket. A font-lock update that triggers any of those side effects pauses until the round trip completes. Disabling those hooks while fontifying large regions is one of the easiest wins available, particularly for engineers triaging faults from a Melbourne control room or an Adelaide depot.

Building a Sensible font-lock-keywords List

A lean Magik keyword list begins with the obvious tokens: _method, _proc, _function, _block, _endblock, _loop, _endloop, _if, _elif, _else, _endif, _try, _when, _endtry, _for, _over, _endfor, and _return. Anchored matches with word boundaries keep the engine from re-running against subwords, and grouping them with regexp-opt produces a single combined alternation that runs noticeably faster than listing each keyword separately.

Beyond keywords, Magik's pragma and slot vocabulary deserves its own patterns. Highlights for define_slot(, define_shared_constant(, def_mixin, and def_slotted_exemplar give a Magik module a clear visual rhythm. A pattern such as '":\\(\\(string\\|integer\\|float\\|object\\|symbol\\)\\)\\b" adds a face to literal type tags found in slot definitions and message catalogues, which otherwise blur into the surrounding text.

Naming conventions also help readability. A leading underscore marks private globals, lowercase_with_underscores marks locals, and ALL_CAPS marks session constants. A light font-lock rule that colours these conventions turns a wall of identifiers into a readable map. Keep such rules at the bottom of the keyword list so they only run after the core keywords have done their work.

Switching On Global-Font-Lock Without the Bloat

The simplest way to get reliable highlighting across every Magik buffer is (global-font-lock-mode t). For most languages this is all that is needed. For Magik, the global mode benefits from a small handful of additional toggles that suppress the patterns Emacs enables by default yet contribute nothing useful to Magik code.

Two faces stand out as candidates for trimming. font-lock-builtin-face and font-lock-constant-face rarely fire on real Magik tokens, and keeping them enabled simply adds work to every update. Disabling them through font-lock-maximum-decoration or by calling font-lock-set-defaults with a trimmed alist keeps the highlighter focused on the patterns that actually matter to a Magik session.

Another useful toggle is font-lock-global-modes. Listing magik-mode and any derived buffer modes used by Smallworld sessions ensures that buffers opened through indirect tooling inherit the same rules. For developers who keep remote Magik sessions attached for hours at a time — a common pattern in Brisbane offices that maintain long-running maintenance windows overnight — this consistency removes the surprise of one buffer highlighting and the next one remaining monochrome.

Tuning JIT Lock for Responsive Editing

For buffers above a few thousand lines, jit-lock-mode is essential. It defers fontification of off-screen regions until they scroll into view, which means opening a one-megabyte Magik file takes roughly the same time as opening a fifty-kilobyte one. Combined with (setq jit-lock-chunk-size 1000) and a modest jit-lock-defer-time, the highlighter stays ahead of the cursor instead of chasing it.

The trade-off is that the very top of the buffer remains unfontified until something scrolls past it. In Magik, where the top of a module often holds the header comment and pragma declarations, a single keystroke or scroll is enough to force the update. Most Melbourne developers we have worked with prefer this compromise over the long wait that full-fontification demands.

A small adjustment that pays off in mixed-language sessions is (setq jit-lock-stealth-time 16). Stealth time lets Emacs fontify idle regions using spare CPU cycles, so a buffer that sits untouched for a moment gradually becomes fully coloured. For Australian developers running Emacs over NBN or corporate VPN links to datacentres in Sydney and Perth, stealth fontification happens during natural pauses in typing and feels effortless in practice.

Pairing Font-Lock with Code Folding and Outline Tools

Once highlighting stabilises, code folding becomes far more usable. hs-minor-mode in Magik buffers hides _method ... _endmethod blocks behind a single line, and the colour differences between the keyword and the body make those hidden regions easy to spot. Combined with outline-minor-mode and a Magik-flavoured outline-regexp, the folded tree mirrors the structure of _define( exemplars and their nested method groupings.

Imenu benefits from these patterns even more directly. A Magik imenu update scans the buffer for method, procedure, and exemplar names; if those names are already highlighted by font-lock, the index builds without needing a second pass. Setting imenu-auto-rescan t keeps the navigation pane in sync with the buffer at almost no extra cost.

Engineers at energy and water distributors around Canberra and Hobart frequently use these features while reviewing datasets captured in collection rosters. A _for i _over my_roster.fast_elements() block is far easier to expand and inspect when the underscore methods and the keyword-driven loop boundaries are clearly coloured and easily folded away during the daily handover at 6am AEST.

Navigating Methods and Inspecting Objects in Highlighted Buffers

Highlighting is only useful if it leads somewhere. Magik-mode integrates tightly with the Smallworld session through plugins built on top of magik-session-bridge, which call into the running process to resolve method locations and slot definitions. Each of those calls costs latency that compounds on every keystroke, so the recommendation is conservative: keep fontification purely local, and rely on dedicated shortcuts — not on font-lock updates — to invoke inspection.

Tools like magik-edit-method and magik-find-symbol remain the workhorses for jumping into a method or jumping to the exemplar that owns a slot. With font-lock showing where each method begins and ends, the navigation pane becomes a visual map, and the inspector responds in a single keystroke rather than after a multi-second fontification pass.

A useful habit, especially across the AEST/AEDT boundary that catches Australian offices twice a year, is to keep a second buffer open for transient outputs. Long error traces and stack dumps can easily be five or six megabytes on their own. Opening them in a read-only Magik-derived mode with a deliberately stripped font-lock list prevents the highlight cycle from ever firing in the first place.

Fixing the Common Slowdowns

When fontification still feels heavy, three checks resolve the majority of issues. First, verify that only one copy of the Magik font-lock definitions is loaded — duplicate add-hook calls in init.el are surprisingly common and double the work on every redraw. Second, confirm that font-lock-multiline is enabled only where it is genuinely needed; multiline patterns are useful for block comments but expensive when applied to every expression. Third, watch the buffer's font-lock-extra-line-warn-increment value: when it complains about missed updates, the keyword list usually has a hole that retries a section repeatedly.

Memory plays a role too. A heavily highlighted two-megabyte Magik buffer consumes more RAM than the same buffer in fundamental mode, because each match stores a marker and a face. On older laptops still standard at some regional utilities and local councils, switching to a hand-tuned font-lock list rather than relying on the broad defaults makes a measurable difference in tab-switching latency across long shifts of incident response.

HydePark Consulting helps Magik and Smallworld teams across Australia tune Emacs for these exact workloads. The team provides hands-on configuration, performance reviews, and training for developers in Sydney, Melbourne, Brisbane, Adelaide, Perth, Hobart, and regional centres. If your team is wrestling with sluggish buffers, inconsistent highlighting, or tooling that does not match your Magik conventions, reach out to HydePark Consulting to scope a short engagement and get editors that keep up with the work.

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