lukstafi / navi-parens

VS Code extension: navigate structured code with keybindings. Markmacs: WYSIWYG for LaTeX via the preview pane.
https://marketplace.visualstudio.com/items?itemName=lukstafi.navi-parens
Other
4 stars 0 forks source link
editor-plugin emacs latex vscode vscode-extension wysiwyg

navi-parens README

Navi Parens is a Visual Studio Code extension that provides structured code navigation similar to what's available in Emacs. It also provides additional key bindings for moving the cursor without "fingers leaving the home row".

The future plan for Navi Parens is to build out Markmacs Mode to emulate TeXmacs-like WYSIWYG editing capabilities within preview panes.

Keywords

VSCode, Structured Code Navigation, Emacs S-Expressions, Atom Block Travel, Jump, Selection, Keymaps, Key Shortcuts, Home Row Cursor Movement, LaTeX, WYSIWYG, TeXmacs

Navi Parens

Overview

Navi Parens provides commands for moving the cursor around smoothly from the innermost parentheses to the outermost code blocks and in between. It also offers keybindings centered around the J, K, L, I keys and the Alt modifier. E.g. moves of the cursor: Alt+J one character left, Ctrl+Alt+J one scope left, Alt+K one line up, Ctrl+Alt+K to outside the beginning of the scope around the cursor.

Overview

Features

Commands:

The meaning of "near the beginning/end of a scope" is mode-specific.

Extra key bindings:

I suggest mapping Caps Lock to alt (rather than ctrl) to facilitate using the above bindings.

Navi Parens combines two sources of structure information:

Each of the sources comes in two variants.

An indentation scope comprises a less-indented line followed by at least one more-indented line. The first, less-indented line is a big opening delimiter for the indentation scope: none of it is inside the scope, and only the first non-whitespace position and earlier are outside the scope. The closing delimiter is the whitespace from the end of the last indented line to before the first non-whitespace position of the less-indented following line. Currently, if there is an empty line at the end of an indentation scope, the Go Past Next Scope and Go To Down Scope commands put the cursor there.

The Raw mode for bracket scopes is useful as it enables navigating within comments or string literals, and does not cause "jitter" like the JumpToBracket mode does. However, it is less reliable since it will count brackets even if they were not intended as delimiters.

Some use cases

First Navi Parens-specific command activates the scope navigation modes indicator.

activation

Navigation with Semantic mode.

Semantic

Navigation with Indentation mode.

Indentation

Navigation with Jump To Bracket with block modes disabled.

Jump To Bracket bracket scope mode

Navigation with Raw bracket mode.

Raw bracket scope mode

Future plan -- the big goal for v2.0: MarkMacs Mode

Markmacs Mode will emulate TeXmacs-like WYSIWYG editing capabilities within preview panes. The LaTeX and Mermaid code will be postprocessed before being rendered, to add a cursor marker and a scope marker. Moreover, Markmacs Mode will add commands such as "cycle-through" which replaces a token to the left of the cursor with its alternatives.

Planned features

Note: there's a PanDoc filter for Mermaid.

You can sponsor the development of Navi Parens.

Requirements

Extension Settings

This extension contributes the following settings:

Technical Details

See integration tests Extension Test Suite for diverse behavior examples. In tests, the character @ stands for initial cursor position, and ^ for resulting cursor position. The test names starting with 'Tricky syntax navigation:' indicate cases where there is no unique best or most logical navigation behavior. For such cases, the behavior of Navi Parens should be one that fits well in general, but might get changed if further usability corner cases arise.

Navi Parens will not perform an action when it does not make logical sense, e.g. there is no outer scope to jump out of, or there is no next/previous scope within the current scope to go to the end of (even if there are more scopes outside of the current scope). This design is intentional, so that you can quickly repeat a command until you get stuck, where you can make a navigational decision (e.g. whether to leave the current scope).

One context where the current behavior might be a bit limiting is when the cursor is placed at the header line of an indentation scope, but not at the beginning of it. Jumping past next scope will find a scope nested inside the subsequent more-indented lines, rather than jumping to the end of the indentation scope. However, jumping down out of the scope will also not jump to the end of the indentation scope, instead it will jump to outside of an encompassing scope (if any). One way to conceptualize this is to think of the header line of an indentation scope as a multi-character block scope delimiter. A position inside a delimiter is neither fully inside, nor fully outside the delimited scope.

Currently, multiple cursors are not supported. It's unlikely that I'll add multiple cursors handling, unless other users ask for it.

Navi Parens ignores defined-symbols that are out-of-order with respect to the syntactic structure, e.g. Python class field definitions inside methods.

If Navi Parens logs assertion failure, maybe the language has delimiters other than those in the configuration.

Some Navi Parens commands will misbehave if they are executed before a document editor is fully initialized. Specifically, the Semantic and JumpToBrackets modes require the corresponding initializations, while the Indentation and Raw modes are good-to-go right away since they only look at the text of a document.

Whitespace-only lines are ignored in computing indentation scopes, which might lead to undesired behavior when you navigate out of a newly-opened line.

TODO: commandline to run tests.

Release Notes

See the changelog for a detailed list of features and changes!

The main/only feature that is still missing is multiple cursors support.

0.9

Initial release of Navi Parens.

0.9.9

1.0.0

1.0.1

1.1.0

1.2.0

1.2.1

1.2.3

1.3.0

1.3.1

Emergency release fixing a performance regression.