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 MoreNine 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 code folding with Emacs for beginners
Code folding in Emacs provides a practical way to manage long Magik source files by hiding blocks of text behind a single descriptive line. For developers working on GE Smallworld platforms, this technique is particularly valuable because Magik procedures, method definitions and iterator blocks often run on for many screens. Folding transforms sprawling method bodies into a clean outline, letting you focus on the structure of a class rather than the implementation details.
If you are based in Sydney, Melbourne, Brisbane or Perth and work with utility networks managed through Smallworld, you have likely encountered the challenge of navigating legacy modules from colleagues at organisations such as Sydney Water, APA Group or Jemena. This guide walks you through the essentials of folding Magik code within Emacs, from the basic commands to advanced customisations that suit Australian work patterns and the way Magik sessions are typically run across distributed teams in the AEST time zone.
Understanding code folding fundamentals in Emacs
Folding in Emacs is handled by several minor modes that can collapse regions of code based on indentation, logical markers or explicit overlays. The most common starting point is hs-minor-mode, which stands for "hide-show". Once enabled, you can place the cursor inside a code block and call hs-toggle-hiding to collapse or expand the region. Because Magik relies heavily on indentation to indicate block structure, this mode works well out of the box for if statements, _block constructs and _for loops.
Emacs also offers outline-mode and outline-minor-mode, which use regular expressions to detect structural headings. In Magik source files, you can configure outline mode to recognise define method, _proc declarations and iter definitions as top-level entries. When combined with folding, outline mode turns a file into a navigable table of contents that you can jump between with simple key bindings. For many developers in Australian consultancies that service the water and gas sectors, this combination replaces the need for external documentation tools when reviewing unfamiliar code.
Another approach uses folding-mode, a package that marks folds with specially formatted comments such as {{{ and }}}. While this requires more setup because you must insert markers into your source, it gives precise control over what collapses. For Magik code that mixes procedural and object-oriented styles, folding mode can be helpful when you want to hide entire classes while keeping their method signatures visible for quick reference.
Setting up Magik mode for proper folding
Magik mode itself ships with Emacs distributions that target Smallworld, and it integrates with several folding mechanisms out of the box. When you open a .magik or .mag file, the mode defines syntax tables and font-lock rules that recognise Magik keywords. To enable folding, add (hs-minor-mode 1) to your Magik mode hook in your init.el file. This ensures every Magik buffer opens with hide-show active, saving you from remembering to enable it manually.
For outline-based folding, customise the outline-regexp variable inside a hook. A typical setting might look for _proc, _method, _block and iter declarations, treating each as a foldable heading. If you work on Smallworld databases managed by teams in Melbourne or on gas distribution networks in regional Victoria, this configuration helps you skim through long import scripts without losing your place.
Folding mode markers can also be automated through Magik's comment syntax. By adding {{{ before a _method definition and }}} after the corresponding _endmethod, you create explicit fold points. Some Australian teams adopt this as a coding convention, arguing that explicit folds survive refactoring better than indentation-based folding when a developer accidentally changes whitespace. A small wrapper function can insert these markers for you, reducing the friction of maintaining them across a large codebase.
Hiding and showing procedures, methods and iterators
The most common fold targets in a Magik file are top-level procedures and method definitions. A _proc declaration usually signals a logical unit of work, while _method blocks define object behaviour. Hiding these allows you to read a class definition as if it were an interface, seeing what operations exist without the implementation noise. Use hs-hide-block and hs-show-block to collapse or expand the region under the cursor, or hs-hide-all and hs-show-all to manage the entire buffer at once.
Iterators in Magik, particularly _for loops and _lock constructs, often contain deeply nested logic. Folding the outer loop lets you see the overall data flow, while expanding individual iterations helps with debugging. When working with collection analysis on a Smallworld database served from a remote office in Perth or Adelaide, this layered view is invaluable because you are usually more interested in the sequence of operations than in the conditional logic inside each loop.
Method navigation becomes significantly easier when folds are combined with imenu or speedbar. These tools list every procedure and method in a sidebar or popup, and when combined with folding you can jump to a definition, expand it temporarily to read the body, and then collapse it again to keep your screen tidy. Many Australian Magik programmers keep their window layouts consistent across projects, with the speedbar on the left, the source buffer in the middle and a REPL or Smallworld session buffer on the right.
Tailoring fold behaviour to your Magik sessions
Magik developers often spend long stretches inside a live Smallworld session connected to a database, evaluating expressions and modifying running objects. Folding works well in the REPL buffer too, particularly when you are composing multi-line method calls or assembling complex query objects. Adding hide-show to your Magik session buffer hook ensures that long expressions can be collapsed, making it easier to scroll back through earlier work and copy reusable snippets.
Customising fold visibility based on file type is straightforward. Inside magik-mode-hook, you might enable hs-minor-mode but disable folding mode, while in plain text buffers or email buffers you might want a different set of rules entirely. For teams that span Brisbane, Canberra and Darwin, keeping these customisations in a shared dotfiles repository means everyone sees consistent folding behaviour regardless of their local time zone.
Another useful tweak involves the hs-set-up-overlay function, which controls how folded text is displayed. By default, Emacs shows the first line of a hidden region followed by .... You can modify this to include a summary, such as the number of lines hidden or a marker like [folded procedure]. When you are reviewing code with a colleague over a screen-share during a meeting scheduled for 10 am AEST, the more descriptive marker helps your collaborator immediately understand what is hidden without having to expand the region themselves.
Building folding into a productive daily routine
The real benefit of code folding emerges when it becomes part of your habitual workflow. Start your morning by opening the modules you plan to work on, then fold everything down to the procedure or method level using hs-hide-all. As you dive into a specific function, expand just that region to read the implementation. When you finish debugging, collapse the method again to maintain the high-level view. This rhythm mirrors the way many Australian software teams practise focused work blocks followed by brief reviews.
Pair folding with your version control workflow to make code reviews more efficient. When reviewing a pull request, fold the unchanged regions so the diff stands out clearly. If your team uses a Git hosting platform hosted in the Asia-Pacific region, this visual reduction helps reviewers concentrate on what actually changed rather than scanning past familiar code. Combining folding with Magik's own debugging tools, such as :step or :next in the REPL, gives you a comfortable environment for tracing execution through a folded outline.
Finally, take time to document your folding shortcuts in a personal cheat sheet or team wiki. The key bindings are simple but easy to forget, and having them written down next to your other Magik references helps new team members in offices from Parramatta to Geelong get up to speed quickly. Once folding feels natural, you will find yourself reading Magik code the way you read a well-structured book: chapter headings first, details when you need them.
Visit the HydePark Consulting site to explore consulting services for Magik and Smallworld projects, and subscribe to the Magik Emacs newsletter for ongoing tutorials, screen-casts and configuration tips tailored to Australian Smallworld teams.
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
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.
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.
Screen-cast 7: Magik Debugger
Useful tools for application developers: Object Inspector and Magik Debugger with breakpoints and slot/variable monitoring.
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.