SublimeText / PackageDev

Tools to ease the creation of snippets, syntax definitions, etc. for Sublime Text.
MIT License
436 stars 83 forks source link

Allow Tab to enumerate scopes in `syntax_test` files #383

Open nk9 opened 1 year ago

nk9 commented 1 year ago

This is a proposal to change Tab to enumerate the available scopes in syntax_test files. It would work like repeatedly pressing ^ does for meta scopes, but instead of selecting successively larger scopes, it would move the auto-generated assertion to the next available substring.

Consider this example, with the cursor at |:

a = myfunc("str", var) + "aa"
#         ^^^^^^^^^^^^ meta.function-call.arguments.python
#|                   @ % $$$$

With Tab working as it does today, pressing Tab in this circumstance would create a single-character assertion at %. The scopes are selected. If you press Tab again, the scopes are replaced with some number of spaces, which is useless. You'd never want spaces after the set of carets.

In this proposal, pressing Tab in this situation would move the assertion to $$$$. The carets would be moved and resized, and the scopes would be rewritten. Also, pressing Shift+Tab would move the assertion BACK to the close paren (@).

This behavior would only happen AFTER Tab was first used to auto-generate an assertion. That means that Shift+Tab would still be available to insert spaces on an empty line for manually aligning an assertion.