feat(pairs): context-aware auto-pairing and nested Markdown fences #7

Merged
rootiest merged 1 commits from feat/context-aware-pairs into main 2026-10-01 05:48:22 +00:00
Owner

Summary

mini.pairs decides whether to auto-close from one character on each side of the cursor, so going back to wrap existing text (e.g. adding backticks around some-name mid-sentence) always inserted a stray closer. This adds lua/smart_pairs.lua, which gates the opener keys with full-line context. Closers, <BS> and <CR> stay with mini.pairs.

Pairing rules (( [ { " ' `)

  • A closer is only added when the rest of the line is empty/whitespace, or starts with ) ] } (nesting inside an existing pair).
  • Quotes don't pair after a word character (don't) or after the same quote (""" stays 3); nothing pairs after \.
  • Stepping over a matching closer and <BS> on an empty pair work as before.

Markdown fences (` and ~)

  • The 3rd character on a blank line opens a fence pair — only outside an existing block, and only with a blank line, EOF, or the enclosing block's closer below.
  • Further characters lengthen both fences (````, `````); <BS> shrinks them, and the closer goes away once the opener drops below 3.
  • A length-aware fence stack replaces the old parity count, so ``` lines inside a ```` (or ~~~) block no longer confuse it.
  • Nested examples inside a longer block get their own closers; a nested pair that grows long enough to close the enclosing block collapses into that closer.

The inline Markdown backtick block in lua/plugins.lua is replaced by require("smart_pairs").setup(), and the README's Mini.pairs entry is updated.

Testing

  • Headless keystroke suite (61 cases) driving the real mappings: wrapping words, EOL/whitespace/nested pairing, quotes, backslash, BS, fence open/close/lengthen/shrink, ~~~, nested ````/`````/~~~ blocks, collapse-into-closer, and typing a full nested Markdown example from scratch. All pass.
  • Full config loads headlessly with the mappings active and no errors.
## Summary mini.pairs decides whether to auto-close from one character on each side of the cursor, so going back to wrap existing text (e.g. adding backticks around `some-name` mid-sentence) always inserted a stray closer. This adds `lua/smart_pairs.lua`, which gates the opener keys with full-line context. Closers, `<BS>` and `<CR>` stay with mini.pairs. ### Pairing rules (`(` `[` `{` `"` `'` `` ` ``) - A closer is only added when the rest of the line is empty/whitespace, or starts with `)` `]` `}` (nesting inside an existing pair). - Quotes don't pair after a word character (`don't`) or after the same quote (`"""` stays 3); nothing pairs after `\`. - Stepping over a matching closer and `<BS>` on an empty pair work as before. ### Markdown fences (`` ` `` and `~`) - The 3rd character on a blank line opens a fence pair — only outside an existing block, and only with a blank line, EOF, or the enclosing block's closer below. - Further characters lengthen both fences (` ```` `, ` ````` `); `<BS>` shrinks them, and the closer goes away once the opener drops below 3. - A length-aware fence stack replaces the old parity count, so ` ``` ` lines inside a ` ```` ` (or `~~~`) block no longer confuse it. - Nested examples inside a longer block get their own closers; a nested pair that grows long enough to close the enclosing block collapses into that closer. The inline Markdown backtick block in `lua/plugins.lua` is replaced by `require("smart_pairs").setup()`, and the README's Mini.pairs entry is updated. ## Testing - Headless keystroke suite (61 cases) driving the real mappings: wrapping words, EOL/whitespace/nested pairing, quotes, backslash, BS, fence open/close/lengthen/shrink, `~~~`, nested ` ```` `/` ````` `/`~~~` blocks, collapse-into-closer, and typing a full nested Markdown example from scratch. All pass. - Full config loads headlessly with the mappings active and no errors.
rootiest added 1 commit 2026-10-01 05:43:23 +00:00
mini.pairs decides from one character on each side of the cursor, so going
back to wrap existing text (e.g. backticks around a word) always inserted a
stray closer. A new lua/smart_pairs.lua gates the opener keys: a pair is only
inserted when the rest of the line is whitespace or starts with a closing
bracket; quotes also don't pair after a word character or the same quote.
Closers, <BS> and <CR> stay with mini.pairs.

Markdown fences move into the same module and get smarter:
- the 3rd ` or ~ on a blank line opens a fence pair only outside an existing
  block and with a blank line, EOF or the enclosing block's closer below
- further characters lengthen both fences (````, `````); <BS> shrinks them
- a length-aware fence stack replaces parity counting, so ``` inside a ````
  block (or ~~~) no longer confuses it; nested examples pair, and a pair that
  grows long enough to close the enclosing block collapses into its closer
rootiest merged commit 322d54d4d1 into main 2026-10-01 05:48:22 +00:00
rootiest deleted branch feat/context-aware-pairs 2026-10-01 05:48:23 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rootiest/neovim-config#7