Structural movement is the ability to move the cursor in terms of program structures instead of characters. For example, instead of moving the cursor to the next character in a file, one might move to the next function definition.
Harmonia-Mode has two different forms of structural movement: structure browsing, and structure jumping.
Harmonia-Mode implements a novel structure-aware cursor, similar to the one used in the Pan research project. This feature allows a programmer to navigate hierarchically throughout a program's source code.
When using this type structural movement, a highlighted region appears with the cursor, indicating the programming structure being browsed. The user can move this structure forward, backward, or make it bigger or smaller.
In this example Cool file, the cursor is the dark red rectangle, and the light-blue region around the "size_of_board" method indicates that it is the current structure being browsed.
Using the Structure Browser:
When structure-browsing, the programmer can navigate:
- larger in the hierarchy, selecting a larger enclosing structure
- smaller, selecting the first sub-structure of the current structure
- forward, selecting the next structure at the same level as the current structure
- or backward, selecting the previous structure at the same level.
The four commands just described are available in the "Structure Browse" sub-menu:
Using the menu is inconvenient, however, for any intensive structural navigation. It is recommended that you use it only as a reference to remember the structure browsing keyboard bindings: C-M-left, C-M-right, C-M-up, and C-M-down.
Structure Browsing sessions involve three steps:
- Enable: Executing any of the four structure browsing commands will automatically enable structure browsing and highlight the current structure.
- Browse: When structure browsing, the user can continue to use the structure browsing commands to navigate their program's hierarchy.
- Disable: Once done, pressing any other key will disable structure browsing and remove the highlight.
Structure Browsing Examples:
- Structure-browsing is a quick way to move amongst method definitions in a file. For example, pressing C-M-up will take a programmer from this place in the file...
...directly to the method definition above it:
The programmer can then start editing that method, and the highlight will be disabled.
- It's easy to move among larger structures as well, as we see in this Java file:
Pressing C-M-left C-M-left selects first the method definition encompassing the cursor, and then the class:
Now, pressing C-M-down C-M-down moves the programmer to the second class following the current one, leaving the programmer here:
As always, the programmer can now immediately continue normal editing. As soon as he or she moves the cursor or types a keystroke, the highlight will be disabled.
- Perhaps, though, the programmer now wants to edit the method "toString()" in this class.
Pressing C-M-right selects the first method in the class (the constructor "Rule()"), and then pressing C-M-down once brings the programmer directly to the desired method:
- Although we haven't shown any examples of it here, one can also browse the lower-level structures of their programs, such as method arguments, variable declarations, and the branches of "if" statements.
The "Jump to" Feature:
The "jump to" feature is a simpler alternative to the structure browser. With it, you can "jump" the cursor to the next or previous structure of certain types. Each language has a particular set of structure-types to which one can jump.
Using "jump to"
In the Harmonia menu, select "Jump to".
You will now see a list of program structures to which Harmonia knows how to jump. Selecting one of these items will move the cursor appropriately.
Note: Each item in the menu is listed with its corresponding keyboard shortcut, if available. Browsing these menus is a great way to learn Harmonia-Mode's key-bindings.