emacs is a text editor. an extensible one. it is mainly used for coding, but it can also do anything else. uml is a modeling language for creating diagrams of software design.
uml-mode.el is a minor mode for emacs that makes it easier to build ascii sequence diagrams in emacs. my goal is for it to do for sequence diagrams what orgtbl-mode does for tables.
ascii uml diagrams are quick and easy to make and can be emailed without attachment or embedded in code comments.
uml-mode.el can be used to make ascii uml sequence diagrams like this:
person1 person2 kitchen | | | | make me a sandwich | | |------------------------->| | | | | | no way | | |< - - - - - - - - - - - - | | | | | | sudo make me a sandwich | | |------------------------->| | | | | | | go | | |---------->| | | | | | | --. | | |<--' make it | | | | |< - - - - -| | | | | sandwich | | |< - - - - - - - - - - - - | | | | |
- only supports sequence diagrams
- provides key bindings for more easily moving around sequence diagrams, and aligning and redrawing them
- diagrams can be embedded in source code comments
- run M-x
package-install
RETuml-mode
- download uml-mode.el
- run M-x
package-install-file
RET - choose
uml-mode.el
if you move the point over a line with some names and hit C-c C-c to redraw it, the list of names will be spread out and centered over timelines.
put the following content in a buffer, enabled uml-mode
(M-x uml-mode
), and hit
C-c C-c while the point is on the
line.
timeline1 timeline2 timeline3
the above line will be replaced with:
timeline1 timeline2 timeline3 | | |
you can modify the diagram at any point and run redraw again and uml-mode will clean it up.
arrows can be added by putting a single dash next to a timeline (pipe character below a timeline name). this will draw an arrow to the nearest neighbor in that direction.
add a dash next to a timeline, as shown below, and run redraw to create an arrow to its neighbor.
timeline1 timeline2 timeline3 |- | |
becomes
timeline1 timeline2 timeline3 | | | |---------->| | | | |
an angle bracket near a timeline indicates the other end of the arrow. both the angle bracket and the dash are used to determine which timelines to connect. there can only be one arrow per line.
timeline1 timeline2 timeline3 |- | >|
becomes
timeline1 timeline2 timeline3 | | | |---------------------->| | | |
create arrows that go to the left by reversing the angle bracket and dash.
timeline1 timeline2 timeline3 |< | -|
becomes
timeline1 timeline2 timeline3 | | | |<----------------------| | | |
arrows will be dashed if there is a non-consecutive missing dash at any point in the line.
timeline1 timeline2 timeline3 |- - | >|
or
timeline1 timeline2 timeline3 |- ---------------------->|
becomes
timeline1 timeline2 timeline3 | | | | - - - - - - - - - - ->| | | |
labels can be entered on the line above or the same line as the arrow. there can only be one label per line.
timeline1 timeline2 timeline3 | call | | |- | |
or
timeline1 timeline2 timeline3 |- call | |
becomes
timeline1 timeline2 timeline3 | | | | call | | |---------->| | | | |
self arrows are made by keeping the angle bracket and any dashes under the same timeline.
timeline1 timeline2 timeline3 |< call | |
becomes
timeline1 timeline2 timeline3 | | | | --. | | |<--' call | | | | |
diagrams can be embedded in source code comments.
# # timeline1 timeline2 # |- ;; ;; timeline1 timeline2 ;; |- ;; // // timeline1 timeline2 // |- // /* * timeline1 timeline2 * |- */
becomes
# timeline1 timeline2 # | | # |---------->| # | | ;; timeline1 timeline2 ;; | | ;; |---------->| ;; | | ;; // timeline1 timeline2 // | | // |---------->| // | | // /* * timeline1 timeline2 * | | * |---------->| * | | */
key | action |
---|---|
C-c C-c | redraw the diagram at the point |
M-f | move forward to the next word or timeline |
M-b | move backward to the previous word or timeline |
M-left | shift a timeline to the left |
M-right | shift a timeline to the right |
M-S-left | delete the timeline at the point |
M-S-right | insert a timeline to the right |
timeline names can contain special characters but cannot contain spaces. timeline names can be multiple lines, but be sure to keep the names that are part of the same timeline lined up vertically.
labels must start with a letter or number but can contain any special characters except pipe (|), dash (-), or angle brackets (<>).
comment prefixes can be any length and can contain any special characters, but cannot contain letters or numbers. comment prefixes can contain leading spaces but cannot contain spaces in the middle or at the end.
- separators
- swap arrow up or down
- move cursor up or down by an arrow
- class diagrams