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 Formatting With Emacs
Consistent formatting makes Magik code easier to read, review and maintain, particularly in large Smallworld environments where methods can remain in service for many years. Pairing Emacs with a formatter gives developers a repeatable way to organise indentation, spacing, method layout and comments without relying on individual habits.
For Australian teams, this matters across long-distance projects involving utilities, transport agencies, councils and mining operations. A developer in Melbourne may review changes from Perth before the morning stand-up, while a consultant in Brisbane works with a client’s established repository conventions. A dependable formatting workflow reduces avoidable discussion and keeps attention on behaviour rather than whitespace.
Why Formatting Matters In Magik Projects
Magik code often communicates its structure through indentation, method boundaries and the visual arrangement of long expressions. When several programmers edit the same application, small differences quickly accumulate. One person may align arguments vertically, another may compress them, and a third may add blank lines inconsistently around _proc and _endproc.
The cost is greater than visual untidiness. In a method containing collection operations, database queries or nested conditionals, inconsistent layout can hide the relationship between a receiver, its arguments and the returned value. A formatter makes those relationships predictable, which helps when tracing object behaviour or reviewing a change that affects production data.
Formatting also improves version control. If a team agrees on line breaks and indentation before making functional changes, pull requests contain fewer cosmetic edits. This is useful for distributed Australian teams where review windows may be shaped by AEST, ACST and AWST working hours. A clean diff is easier to inspect between meetings, site visits and client support calls.
The formatter should be treated as a source-code policy rather than an aesthetic preference. It needs documented rules for indentation width, continuation lines, comment placement, method separators and the handling of legacy constructs. Magik developers can then apply the same policy through Emacs, batch jobs and continuous integration.
Building A Formatter Workflow In Emacs
Emacs is well suited to this task because it can combine a Magik major mode, buffer-local settings, commands and hooks. A practical workflow starts with a command that formats the current method or buffer, followed by a clear visual signal showing what changed. Developers should be able to run it manually while exploring code, or automatically before saving a controlled set of files.
A formatter does not need to rewrite every historical file on its first day. Large Smallworld repositories often contain decades of code and local conventions inherited from earlier teams. Applying formatting to an entire application can create noisy commits and make reviews harder. A safer rollout formats new or modified methods first, then expands as files are touched for legitimate maintenance.
An Emacs command might use the following pattern, with the actual formatter command adjusted to the project’s tooling:
(defun magik-format-buffer ()
"Format the current Magik buffer."
(interactive)
(save-restriction
(widen)
(shell-command-on-region
(point-min) (point-max)
"magik-format --stdin"
(current-buffer) t))
(set-buffer-modified-p nil))
(add-hook 'magik-mode-hook
(lambda ()
(local-set-key (kbd "C-c f") #'magik-format-buffer)))
In a production setup, it is often better to call an Emacs package or an external process asynchronously. That prevents a slow formatter from blocking the editor and allows the user to see diagnostics separately from formatted output. A project can also expose formatting through format-all, a custom Lisp function or an editor integration based on reformatter.el, provided the Magik syntax is handled accurately.
The command should preserve point position, narrowing and file encoding where possible. It should also report failures clearly. A syntax error should never cause Emacs to replace a working buffer with partial output. For teams supporting systems in regional offices or on mine sites with unreliable connections, local formatting is preferable to a service that depends on a remote endpoint.
Designing Rules That Respect Magik Syntax
A useful Magik formatter must understand the language rather than treating it as generic text. It should recognise method declarations, _proc and _endproc, compiler directives, symbols, strings, comments and statements that span several lines. It also needs to avoid changing the contents of strings or comments, where spaces may be meaningful to generated output or operational messages.
Indentation rules should be conservative. A continuation line can be indented beneath the opening parenthesis or aligned with the first argument, but the chosen style must remain stable. The same applies to chained sends, collection literals and conditional expressions. A formatter that repeatedly shifts code between two equally valid layouts will create formatting churn and undermine confidence in automated edits.
Long database queries and collection expressions deserve particular attention. Magik code that filters, maps or sorts a collection can become difficult to scan when every operation is placed on one line. A project rule might put each chained operation on a separate line, align the operators, and keep the final assignment visually distinct. This is especially helpful in Smallworld applications that analyse network records, land parcels or asset inventories.
Comments should be preserved with their nearest logical statement whenever possible. Header comments describing a method’s purpose can remain above the declaration, while inline notes should stay attached to the expression they explain. The formatter should avoid aggressively reflowing prose because operational terminology, field names and client-specific abbreviations may be deliberate.
Before enabling automatic formatting, create representative fixtures. Include short methods, nested procedures, empty collections, multiline strings, comments containing punctuation and deliberately awkward legacy examples. Compare the formatter’s output with expected files. A small regression suite is valuable here; teams that already maintain browser or integration checks can place formatting validation alongside their existing web test tooling, while keeping language-specific checks in the Magik repository.
Connecting Formatting With Navigation And Review
Formatting becomes more useful when it works with the rest of the Emacs development environment. After a buffer is formatted, developers should still be able to jump between method definitions, inspect an object, fold a long procedure and navigate references. The formatter should support these features by retaining valid syntax and predictable boundaries.
Code folding benefits particularly from consistent method layout. When every procedure begins and ends in a recognisable form, a developer can collapse implementation details while reviewing the public shape of an object. Method navigation also becomes less distracting because declarations appear in a regular visual pattern rather than being hidden among irregular blank lines.
A useful key binding might format the current method, while another formats the entire buffer. Formatting only the active method is safer during exploration and reduces accidental changes in a large file. Formatting the buffer is appropriate before committing a focused change, provided the repository’s rules have been tested against legacy syntax.
Review policy matters as much as editor configuration. Teams should decide whether formatting runs before a commit, in a pre-commit hook or in continuous integration. Many organisations choose a non-blocking warning at first, then make violations fail after developers have updated their local Emacs configuration. That staged approach is practical for consulting projects where environments differ between a client laptop, a managed virtual desktop and a developer’s own workstation.
A formatter should also be observable. Report which file or method was changed, return a useful exit status and preserve the original file when parsing fails. These details help support teams diagnose problems without opening an extended investigation into why a seemingly harmless save operation altered a generated or vendor-managed file.
Rolling Out A Shared Standard
Start with a short style document that explains the rules in examples rather than abstract preferences. Include indentation, blank lines, line length, comment handling, method spacing and the treatment of generated code. Store the formatter configuration beside the application so a new developer can clone the repository and obtain the same result.
The rollout can begin with a pilot package owned by a team that understands both Magik and the operational domain. For example, a Sydney utility project may choose a small group of network-management methods, while a Perth mining client tests collection-heavy asset code. These samples reveal whether the rules work across real code instead of only clean demonstration examples.
Training does not need to be elaborate. A short screen-cast showing a method before and after formatting, followed by a demonstration of Emacs navigation and folding, can establish the workflow quickly. Developers who use “arvo” support sessions or informal pairing can compare results without turning style discussions into a formal approval process. The important point is that the formatter remains predictable and easy to invoke.
Teams should distinguish source files they own from generated, vendor-supplied or externally maintained files. Automatic rewriting of those files may complicate upgrades and support agreements. Exclusion patterns, directory-level configuration and a clear ownership rule prevent the formatter from becoming a source of accidental maintenance work.
The following comparison helps position the main implementation choices:
| Approach | Strengths | Limitations | Suitable use |
|---|---|---|---|
| Manual Emacs indentation | Immediate and familiar | Depends on individual habits; inconsistent across teams | Early exploration or small scripts |
| Emacs command with a Magik formatter | Fast feedback and easy adoption | Requires reliable parser and configuration | Daily development |
| Save hook formatting | Consistent local output | Can surprise users or affect legacy files | Controlled repositories with tested rules |
| Pre-commit formatting | Keeps committed code uniform | Developers must install the hook correctly | Teams with shared Git practices |
| Continuous integration check | Enforces repository policy | Feedback arrives after the edit is complete | Mature projects and release branches |
| Full automatic rewrite | Rapidly standardises a codebase | Creates large diffs and exposes parser weaknesses | Carefully planned migration |
A sensible standard combines editor feedback with repository enforcement. Emacs should make the correct action convenient, while version control checks protect the shared codebase. The formatter’s version should be pinned, and configuration changes should be reviewed like any other development-tool change. That prevents two developers from producing different output because their local binaries were updated at different times.
For consultants working across Australian clients, portability is important. A configuration that works in Melbourne but assumes a particular shell, path layout or package manager may fail in a restricted corporate environment. Document the required Emacs packages, command-line dependencies and Windows or Linux differences, then test the setup in the same kind of managed environment used by the client.
A consistent Magik formatting workflow turns Emacs into more than a text editor: it becomes a dependable part of the development standard. Begin with a small, syntax-aware rule set, connect it to method navigation and review, and expand only after real project code has proved the approach. HydePark Consulting can help teams assess their Magik development workflow, improve Emacs tooling and establish maintainable practices for Smallworld applications.
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.