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
Rectangle mark mode for Magik column edits
Large Smallworld queries often arrive as text that resembles a spreadsheet rather than Magik source: one record per line, fields in fixed positions, and a collection or database export printed beside a method. Editing those rows one at a time is slow, especially when a developer in Melbourne or Sydney must prepare a test extract before a client review. Rectangle mark mode, built into Emacs, lets a rectangular block be selected and changed as one unit.
The technique suits column-shaped Magik data because it preserves surrounding rows while applying the same operation across a field. A normal Emacs region follows a linear path from point to mark; a rectangle follows two-dimensional screen coordinates. That difference makes short, repeated edits faster without replacing the structured Magik logic used to build or query the underlying collection.
| Editing need | Ordinary mark mode | Rectangle mark mode |
|---|---|---|
| Selection shape | Linear from point to mark | Rows by screen columns |
| Best suited to | Prose and contiguous code | Aligned, columnar text |
| Repeated values | Search-and-replace or repeated cursor edits | One action across selected cells |
| Main limitation | Requires a continuous region | Does not understand record fields or delimiters |
Why column edits matter in Smallworld
A Smallworld collection is a vector of records, but printed output can flatten records into aligned columns. Consider a diagnostic extract with the shape asset_id | region | state: three asset rows might contain A-100 | north | active, A-101 | south | active, and A-102 | east | active. If every row must move from active to review, selecting the status characters avoids three separate searches or edits.
Rectangle editing is equally useful in hand-written Magik fixtures, including vectors of records, temporary result files, and captured debugger output. It can change repeated literals, insert a fixed-width block, or remove a column without disturbing the row prefixes. This is valuable when investigating collection-analysis code and the sample data used to reproduce a defect.
The boundary is important: Emacs sees glyph positions, not Smallworld objects. A rectangle does not know that state is a record slot or that a pipe separates fields. Consequently, use it for text artefacts and source representations; use a Magik method that maps over records when the live collection itself must change.
Preparing an aligned Magik buffer
Start in a buffer whose columns are predictable. Open the export or Magik source with Magik Emacs so that comments, strings, and method bodies receive the appropriate editing support. Emacs displays tabs according to their screen width, so a logical tab can conceal several spaces. Run M-x untabify-list when that ambiguity would make a selection unsafe.
If separators are spaces but uneven, M-x align-regexp can align groups around a chosen regular expression. Alignment is a buffer-wide formatting operation, so review the diff and keep a backup. For generated output, regenerating it with a known format is often cleaner than hand-aligning dozens of rows.
Place point at the upper-left corner and invoke C-x r SPC, the standard binding for rectangle-mark-mode. Move point to the lower-right corner with a motion command. Emacs now treats the marked area as rows by columns. Using M-x rectangle-mark-mode is an equivalent fallback if the key binding has been changed.
Selecting and changing a rectangle
With the status column marked, C-x r k kills only that rectangle. The repeated word disappears while the surrounding text and rows stay in position. C-x r y yanks a rectangular kill, and C-x r c clears a marked block without moving it. These commands work in display columns, so values should remain within known widths.
C-x r w is often the best choice for a uniform replacement. Mark the six-character active cells, run C-x r w, and enter review. Because both words have the same width, adjacent region data does not shift. A shorter replacement normally leaves padding; a longer one can overwrite the next field, which is why a Magik-aware alignment step belongs before the edit.
For insertion, C-x r o opens a rectangular area, useful for adding a blank field or spacing between columns. C-x r = numbers lines within a rectangle when a sequential identifier is required. A recorded Emacs keyboard macro can repeat the sequence, but C-x u remains the quickest way to recover from a misplaced rectangle.
Handling common column transformations
Repeated values are the clearest case, but rectangles also solve uneven manual transformations. A narrow selection can remove a constant prefix from several identifiers; another can target a trailing note occupying the same positions on every line. Killing a column and yanking it beside another swaps the visible order, while open-rectangle creates room for a fixed-width value.
The same operation can cross rows without changing their count. For example, select only the north, south, and east region cells and use C-x r w to replace them with remote. Select the numeric suffix of each asset identifier and use C-x r = only when the result should be a sequence. Always inspect tabs, truncated columns, and wrapped lines before marking.
Do not use visual replacement as a substitute for domain logic when values have different widths or validation rules. active, pending, and closed may occupy different positions; selecting the longest common width can accidentally hit punctuation or neighbouring text. In that situation, write or call a Magik transformation that updates each record deliberately, then use the rectangular technique on the resulting text.
Combining rectangles with Emacs workflows
Rectangle mark mode composes well with the rest of an Emacs-based Magik workflow. Code folding can hide unrelated methods while a fixture is being adjusted, and method navigation such as M-. moves from a call site to its definition. After the edit, use Magik Emacs search, object inspection, and debugging views to check the live result rather than inferring success from the buffer alone.
Keep presentation and semantics separate. A clean approach is to align the exported rows, apply one rectangular transformation, save a fixture under version control, and then run the Magik code against that fixture. Emacs registers and the kill ring are useful for staging text, but named versions of the fixture make the change reviewable by another Magik programmer.
Keyboard macros can standardise large corrections, especially for an operations team that receives similar extracts every week. Record the alignment, rectangle selection, and replacement as one macro, assign it a descriptive name, and bind it only in the relevant Magik mode. A macro should accelerate a proven operation, not conceal assumptions about column widths.
Testing the edit in Australian teams
Reliable rollout matters in the Australian Smallworld market, where Melbourne and Sydney are major centres for enterprise support and long-lived installations often depend on small teams of specialists. A practical change should survive different business habits: stand-ups usually sit inside standard AEST or ACST working hours, daylight-saving transitions can shift a shared maintenance window, and teams in Brisbane or Perth may be online before or after eastern colleagues. A recorded procedure and timestamped fixture make hand-offs less dependent on who happens to be at a keyboard.
Test data also needs an Australian legal check. If a fixture contains customer names, email addresses, or employee records, the workflow may be governed by the Privacy Act 1988 (Cth) and the Australian Privacy Principles. Use synthetic identifiers where possible, restrict access to realistic extracts, and avoid copying production data into a developer buffer merely to make a rectangular edit convenient.
When Magik output feeds an adjacent operational application, browser-based test checks can confirm that identifiers and statuses still appear correctly beyond Emacs. They complement collection-level and method-level tests by covering the hand-off into the wider system. The final control is a small, repeatable drill: align the extract, mark only the intended field, replace or clear it, undo once to confirm recovery, then rerun the relevant Magik and browser tests.
Open your next Magik data extract in Emacs, enable rectangle mark mode, and perform one guarded status replacement on a copy before using the technique on a client-facing fixture. Pin the verified macro and sample command sequence in the team’s Magik Emacs notes so the next Australian support team can apply the same controlled edit without rediscovering the column boundaries.
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.