Major mode for editing SysML v2 (Systems Modeling Language) files with syntax highlighting and validation integration.
- Syntax Highlighting: Optimized with compile-time regex compilation for keywords, types, operators, comments, and documentation blocks
- Automatic Indentation: Smart indentation based on block structure
- Electric Pairs: Automatic insertion of matching delimiters
(
{},[],(),"",<>) - Comments: Support for
//single-line and/* */multi-line comments
- Imenu Support: Navigate to any definition via menu (
M-x imenu) - Which-Function Mode: Shows current definition in mode line
- Code Folding: Hide/show blocks with hideshow mode
C-c @ C-h- Hide blockC-c @ C-s- Show blockC-c @ C-c- Toggle hiding
- ElDoc Support: Inline documentation in minibuffer when cursor is on keywords or operators
- Prettify Symbols: Display operators with Unicode characters
:>→⊃(specialization):>>→⊇(redefinition)::→∷(qualified names)and→∧,or→∨,not→¬[*]→∞(unbounded multiplicity)
- Quick Reference:
C-c C-hdisplays a syntax guide with examples - Validation: Integration with
validate-sysml.shfor on-save validation (C-c C-v) - Spell Checking: Smart spell checking for comments and strings only
(
C-c C-s)
The mode automatically associates with .sysml files. To manually
enable:
M-x sysml-mode
- Download
sysml-mode.elto your Emacs configuration directory - Add to your init.el or .emacs:
;; Add the directory containing sysml-mode.el to load-path
(add-to-list 'load-path "~/.emacs.d/lisp/")
;; Load the mode
(require 'sysml-mode)(use-package sysml-mode
:load-path "~/.emacs.d/lisp/"
:mode ("\\.sysml\\'" "\\.sysmli\\'")
:custom
(sysml-validate-on-save t)
(sysml-enable-prettify-symbols t)
:config
;; Optional: Enable which-function-mode for current definition display
(add-hook 'sysml-mode-hook 'which-function-mode))(setq sysml-validate-on-save t)By default, the mode auto-detects validate-sysml.sh in the project
directory tree. To set explicitly:
(setq sysml-validator-script "/path/to/validate-sysml.sh");; Load SysML mode
(load-file "sysml-mode.el")
;; Enable validation on save
(setq sysml-validate-on-save t)
;; Optional: Enable which-function-mode globally to see current definition
(which-function-mode 1)
;; Optional: Enable hideshow mode by default for code folding
(add-hook 'sysml-mode-hook 'hs-minor-mode)
;; Optional: Customize prettify symbols (or disable them)
(setq sysml-enable-prettify-symbols t) ; Set to nil to disable
;; Optional: Customize prettify symbols mapping
(setq sysml-prettify-symbols-alist
'((":>" . ?⊃)
(":>>" . ?⊇)
("and" . ?∧)
("or" . ?∨)))
;; Optional: Set custom tab width
(add-hook 'sysml-mode-hook
(lambda ()
(setq tab-width 4)
(setq indent-tabs-mode t)))| Key | Command | Description |
|---|---|---|
C-c C-v |
sysml-validate-buffer |
Validate current file |
C-c C-h |
sysml-quick-reference |
Show quick reference guide |
C-c C-s |
sysml-spell-check-buffer |
Spell check comments/strings |
| Key | Command | Description |
|---|---|---|
C-c @ C-h |
Hide | Hide current block |
C-c @ C-s |
Show | Show hidden block |
C-c @ C-c |
Toggle | Toggle block hiding |
C-c @ C-l |
Hide All | Hide all blocks |
C-c @ C-a |
Show All | Show all blocks |
SysML v2 Mode follows Emacs conventions for declarative languages (like HTML, CSS, XML). The highlighting distinguishes between language keywords, definitions, usages, and references.
The mode uses standard Emacs faces to highlight different syntactic elements:
| Face | Color (typical) | What It Represents | Examples |
|---|---|---|---|
| font-lock-keyword-face | Purple/Magenta | Language keywords and operators | package, part, def, attribute, state, transition, :>, :>>, ::, ~ |
| font-lock-function-name-face | Blue | Type definitions and packages | part def Vehicle → Vehiclepackage SimpleVehicleModel → SimpleVehicleModel |
| font-lock-variable-name-face | Yellow/Orange | Property/instance declarations | attribute mass → massstate normal → normaltransition off_To_on → off_To_on |
| font-lock-type-face | Green | Type references | : Real, : Boolean, : Time::DateTime |
| font-lock-builtin-face | Cyan | Direction keywords, logical operators | in, out, inout, and, or, not |
| font-lock-constant-face | Blue/Cyan | Literals, multiplicity | 500, true, false, [*], [0..1] |
| font-lock-string-face | Red | String literals | "text value" |
| font-lock-comment-face | Gray/Dim | Comments | // comment, /* comment */ |
| font-lock-doc-face | Gray/Dim | Documentation blocks | doc /* documentation */ |
| font-lock-preprocessor-face | Purple | Metadata annotations | @MetadataName, #logical, #physical |
| Default face | White/Black | References to existing names | first normal, do senseTemperature |
Following declarative language conventions:
- Definitions (creating new types) are colored like HTML element names
- Usages (declaring properties) are colored like HTML attributes
- Type references (type annotations) are colored
- References (using existing names) are NOT colored, like HTML text content
package SimpleVehicleModel { // package=keyword, SimpleVehicleModel=function-name
part def Vehicle { // part,def=keyword, Vehicle=function-name
attribute mass : Real; // attribute=keyword, mass=variable-name, Real=type
port ignitionPort : IgnitionCmdPort; // port=keyword, ignitionPort=variable-name
exhibit state vehicleStates { // exhibit,state=keyword, vehicleStates=variable-name
state off; // state=keyword, off=variable-name
state on { // state=keyword, on=variable-name
constraint {electricalPower <= 500[W]} // constraint=keyword, 500=constant
}
transition off_To_on // transition=keyword, off_To_on=variable-name
first off // first=keyword, off=default (reference, not colored)
then on; // then=keyword, on=default (reference, not colored)
}
}
requirement def MassRequirement { // requirement,def=keyword, MassRequirement=function-name
doc /* Vehicle mass constraint */ // doc=keyword, comment=doc-face
attribute massActual :> ISQ::mass; // :>=operator, ISQ::mass=qualified type
}
}
Colored (structure and declarations):
- ✓ Language keywords (
part,state,first,then) - ✓ Operators (
:>,::) - ✓ Type definitions (
part def Vehicle→Vehicle) - ✓ Property declarations (
attribute mass→mass) - ✓ State/transition names (
state normal→normal) - ✓ Type references (
: Real) - ✓ Literals (
500,"text",true)
Not Colored (references and content):
- ✗ References to existing elements (
first off→offnot colored) - ✗ Action/method calls (
do senseTemperature→senseTemperaturenot colored) - ✗ State references in transitions (
then on→onnot colored)
This creates a visual distinction between declarations (colored) and usage (not colored), following standard declarative language patterns.
The mode provides color highlighting for:
- Package:
package,import,private,public,standard,library - Definitions:
def,part,attribute,ref,item,port,action,state,requirement,constraint - Behavioral:
exhibit,perform,then,first,accept,send,entry,exit,do - Relationships:
specializes,subsets,redefines,bind,connect,satisfy,verify
:>(specialization):>>(redefinition)::(qualified names)
- Built-in types:
String,Boolean,Integer,Real,Natural,DataValue - User-defined types in type position
- Qualified names:
Package::SubPackage::Type
- Strings:
"text" - Numbers:
123,3.14 - Booleans:
true,false - Multiplicity:
[0..1],[0..*],[1]
- Single-line:
// comment - Multi-line:
/* comment */ - Documentation:
doc /* documentation */
ElDoc is enabled by default. Move your cursor over any keyword or operator to see a brief description in the minibuffer (echo area).
Examples:
- Cursor on
:>shows: "specialization operator - inherit from supertype" - Cursor on
part defshows: "defines a structural component type (specializes Parts::Part)" - Cursor on
:>>shows: "redefinition operator - redefine inherited feature"
Press C-c C-h to open a comprehensive quick reference buffer showing:
- Operator syntax and examples
- Common code patterns
- Multiplicity notation
- Key bindings
- Links to authoritative documentation sources
The quick reference is designed as a cheat sheet for quick lookups without leaving Emacs.
The mode links to these official documentation sources:
- OMG SysML v2 Specification: https://www.omg.org/spec/SysML/2.0/
- SysML v2 Release Repository: https://github.com/Systems-Modeling/SysML-v2-Release
Use the SysML textual notation file for the example Simple Vehicle Model published by OMG: https://www.omg.org/cgi-bin/doc?ptc/25-04-31.sysml
The mode provides intelligent spell checking that only checks strings and comments, not code identifiers or keywords.
Simply use the standard ispell-buffer command:
M-x ispell-buffer
The mode automatically remaps this to ispell-comments-and-strings,
which checks only:
- String literals:
"text to check" - Single-line comments:
// comment text - Multi-line comments:
/* comment text */ - Documentation blocks:
doc /* documentation */
For real-time spell checking as you type:
(add-hook 'sysml-mode-hook 'flyspell-prog-mode)The flyspell-prog-mode function is the standard Emacs way to enable
spell checking in programming modes - it only checks comments and
strings.
When sysml-validate-on-save is enabled, the mode runs
validate-sysml.sh after saving. Validation errors appear in the
*compilation* buffer with GNU format:
filename:line:column: error: message
Click on errors to jump to the corresponding location.
Run validation at any time with C-c C-v or:
M-x sysml-validate-buffer
- Based on OMG SysML v2 specification (https://www.omg.org/spec/SysML/2.0/)
- Check that
validate-sysml.shis in your project directory - Verify the script is executable:
chmod +x validate-sysml.sh - Set
sysml-validator-scriptexplicitly if auto-detection fails - Check the
*Messages*buffer for error messages
If the mode is slow to load:
- Disable prettify-symbols:
(setq sysml-enable-prettify-symbols nil) - Disable hideshow mode: Remove
hs-minor-modefrom hooks - Check for conflicting modes or packages
- Validation Script Required: Syntax validation requires external
validate-sysml.shscript (not included).