Tree Editors
Programs are trees, not strings.
Code should be edited using a “tree editor” that respects the
syntactic structure of programs, rather than a “text editor” that
doesn’t. This is made difficult by the fact that there is a huge
amount of infrastructure already in place around text
files. Nevertheless, we’ll get there eventually.
Here are some quick thoughts on a grouping of tree editing commands.
The cursor will either be around a node in the tree, in which case it
refers to the node and all of its children, or it will be ‘editing’ a
particular node, in which case you’re manipulating the contents of
just that node itself. The “Navigation” directions are relative to the
code tree: “up” means “your parent”, and right means “your next
sibling”.
Navigation
- up (up arrow, ‘k’)
- down (down arrow, ‘j’)
- left (left arrow, ‘h’)
- right (right arrow, ‘l’)
- (Add ‘shift’ to go all the way up, right, etc.)
Commands
- insert node (‘i’, followed by a Nav direction)
- delete node (‘d’, followed by a Nav direction)
- swap nodes (‘s’, followed by a Nav direction)
- cut, copy, paste node; undo, redo; find (standard)
Editing
- edit node contents (‘enter’)
- done editing node contents (‘enter’)
- done editing node contents, and go right (‘tab’)
Kenny & John’s Tree Editor
Here are the commands from a tree editor project at Brown.
They are vim-like, and have two modes: normal mode and insert mode.
Navigation
- up (up arrow, ‘i’)
- down (down arrow, ‘k’)
- left sibling (left arrow, ‘j’)
- right sibling (right arrow, ‘l’)
- left inorder (‘u’)
- right inorder (‘o’)
Commands
- insert group (‘tab’ = ‘nk’)
- exit group (‘space’ = ‘if’)
- wrap (‘w’)
- unwrap (‘e’)
- swap (‘s’)
- delete (‘d’)
- select all (‘a’)
- select none (‘f’)
- reverse selection (‘r’)
- goto first (‘g’)
- cut, copy, paste node; undo, redo (standard)
- find (none yet)
Editing
- normal mode (‘enter’)
- insert mode (‘h’)