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 Method Navigation in Emacs
Large Magik applications can make method lookup feel slower than the actual coding. A method may be implemented in a class definition, inherited from a parent exemplar, reopened in another file, or generated as part of a framework convention. When a developer has to search manually through directories and image files, understanding existing behaviour becomes unnecessarily difficult.
Emacs provides several ways to turn method names into navigable links. With suitable Magik-aware configuration, you can move from a call site to its definition, inspect related methods, return to previous locations, and keep the source tree visible while debugging. The result is a faster workflow for Smallworld customisation, migration work, and day-to-day maintenance.
Why Method Navigation Matters In Magik
Magik systems often distribute related behaviour across many source files. A class may contain a public method in one file, helper methods in another, and inherited behaviour somewhere inside the Smallworld product libraries. A call such as object.perform_action() tells you what is being requested, but finding the implementation by filename alone can be tedious.
This becomes especially important in established Australian projects, where a small consultancy team may support a utility, transport, or government deployment for years. A developer in Melbourne might be fixing a production issue while another team member in Perth is working through a related customisation. Efficient navigation reduces the amount of tribal knowledge required to identify the right method.
Method jumping also supports safer changes. Before altering a call, you can inspect its definition, check callers, compare overloaded or similarly named methods, and follow the inheritance chain. That context is valuable in Magik because a seemingly local change can affect object protocols, database access, collection handling, or user interface behaviour elsewhere in the application.
The Core Emacs Navigation Workflow
The standard Emacs starting point is cross-reference navigation. When point is on a method name or symbol, M-. runs xref-find-definitions. If the active Magik package can identify the symbol and its source location, Emacs opens the definition and places the cursor at the relevant declaration. M-, runs xref-go-back, taking you to the call site.
The marker stack is particularly useful during investigation. You can jump from a caller into a definition, follow another method, inspect a superclass, and then step backwards through each location. C-x 4 . can display a definition in another window, allowing the original code and target method to remain visible together. These small choices prevent the familiar cycle of opening a file, losing your place, and searching for the original line again.
When direct cross-reference support is unavailable, Emacs still offers practical alternatives. M-x imenu presents an index of methods detected in the current buffer, while M-x occur can find every textual use of a method name. M-x find-grep-dired and project search commands are useful for locating definitions across a source tree. The quality of the result depends on how accurately the search pattern reflects Magik’s method syntax.
Making Magik Definitions Discoverable
For reliable jumping, Emacs needs a recognisable representation of Magik methods. A major part of configuration is ensuring that the Magik major mode fontifies method declarations and exposes them to imenu. A typical definition may begin with _method, include an exemplar and method name, and finish with _endmethod; exact forms vary between codebases and framework conventions.
If imenu lists methods correctly, it provides a useful fallback even before a full language server or tags database is available. Run M-x imenu, select a method, and Emacs moves directly to its declaration. You can also bind the command to a convenient key or use consult-imenu if that package is part of your setup. Fuzzy matching makes it much quicker to locate a method in a long buffer.
For project-wide navigation, generate tags with an Emacs-compatible tool that understands the Magik declaration pattern. A custom regular expression can often identify _method lines and record the method name as a tag. Once a TAGS file is available, M-. can use it as a definition source, while M-x tags-search searches matching symbols throughout the project. Keep the tags file near the repository and regenerate it after substantial source changes so that navigation does not lead to stale locations.
Searching Calls, Definitions, And Variants
Text search remains important because Magik method names may be qualified, dynamically constructed, or passed as symbols. A definition lookup can fail when the source uses a naming style that the indexer does not understand. In those cases, search for the method name without assuming that the caller and declaration use identical qualification.
Regular expressions help distinguish a declaration from an invocation. For example, a search pattern can look for _method followed by optional whitespace, an exemplar or object qualifier, and the target method name. A second search can find ordinary calls, symbol references, or strings containing the same name. Use whole-word or boundary matching where possible to avoid confusing update_record with update_record_status.
Emacs query replacement can support navigation-related cleanup as well as refactoring. Before changing a method name across a project, review the techniques in Magik regex refactoring, particularly where qualification and whitespace differ between files. A controlled replacement makes subsequent definition searches more consistent and reduces the chance of leaving old call forms behind.
Navigating Inheritance And Object Behaviour
Finding the first matching definition is only part of understanding Magik behaviour. If a method is inherited, the visible call may resolve through an exemplar hierarchy rather than a definition in the current file. After jumping to a method, inspect its receiver, parent exemplars, and any nearby method combinations or delegation patterns. The surrounding declarations often explain why a method behaves differently for related object types.
A useful Emacs arrangement places the caller in one window, the selected definition in another, and an outline or method index in a third. C-x 2 and C-x 3 create the basic layout, while C-x o moves between windows. Developers who prefer a single-buffer workflow can use M-x clone-indirect-buffer to inspect different parts of a large source file without repeatedly scrolling.
Object inspection closes the gap between static source and runtime behaviour. When a debugger stops at a method call, record the receiver’s exemplar and inspect the corresponding source definition. This is valuable in systems with generated objects, database-backed records, or application-specific subclasses. A team working on a rail asset system in Sydney, for example, may need to distinguish a generic record method from a project-specific override before changing validation logic.
Building A Practical Emacs Setup
Start with the smallest configuration that matches the project. Enable the correct Magik major mode, confirm that source files are recognised, and test M-x imenu on a representative file. If method entries are missing, fix syntax recognition before adding more packages. A clean method index is often more useful than a large collection of commands that produces unreliable matches.
Next, configure project navigation. project.el, projectile, or a repository-specific command can restrict searches to the active Magik codebase rather than scanning generated files, logs, and installed Smallworld libraries. Excluding build directories improves both speed and accuracy. For large repositories used by councils, utilities, and engineering firms, this distinction can turn a search from several seconds into an immediate result.
Key bindings should reflect the sequence you use repeatedly. A practical arrangement might assign one key to definition lookup, another to returning to the previous position, and a third to imenu. Keep familiar Emacs defaults where possible, so developers moving between a Brisbane office, a home workstation, and a client environment do not have to relearn the workflow.
For teams spread across Australian time zones, place the configuration in version control with the project’s development files. A shared setup helps a Sydney developer, an Adelaide analyst, and a Perth support engineer use the same method-index rules and search exclusions. Document any custom tag-generation command beside the repository rather than relying on one person’s .emacs file.
Troubleshooting Failed Definition Jumps
A failed jump usually has a predictable cause. The symbol may be inside a string, the method name may be qualified differently at the call site, the source may not be included in the project, or the index may be out of date. First test the same name with M-x occur or project search. If text search finds the declaration, the problem is indexing or pattern recognition rather than the source itself.
Check file encoding, major-mode activation, and the regular expression used by imenu or tags. Some Magik files contain unusual spacing, continuation lines, comments, or generated declarations. Test the pattern against several real files, including inherited methods and methods with qualified names. Avoid making the expression so broad that ordinary comments and calls appear as false definitions.
If a method has multiple definitions, treat the results as an investigation list rather than assuming the first match is correct. Compare the receiver type, module or product area, and load order. This is especially important for long-lived Smallworld installations, where local extensions can coexist with vendor code and site-specific patches.
Keep navigation data fresh after branch switches or major refactors. A stale TAGS file can be more misleading than no index because it appears authoritative. Regenerate it as part of a project command, and use version-control status to notice moved or renamed source files. With those habits in place, Emacs becomes a dependable map of the Magik codebase rather than a collection of disconnected search tools.
Configure the Magik mode, test a definition jump, and add a project-aware fallback search today. Once M-., M-,, imenu, and reliable source indexing work together, method investigation becomes a repeatable part of development instead of a manual hunt through folders and libraries.
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.