Skip to content

Fix delete-pair and list navigation for delimiters#29

Merged
bbatsov merged 1 commit intomainfrom
fix-delete-pair-navigation
Mar 14, 2026
Merged

Fix delete-pair and list navigation for delimiters#29
bbatsov merged 1 commit intomainfrom
fix-delete-pair-navigation

Conversation

@bbatsov
Copy link
Owner

@bbatsov bbatsov commented Mar 13, 2026

Fixes #28.

delete-pair was deleting the wrong closing delimiter because
forward-sexp used tree-sitter node navigation instead of
syntax-table paren matching when point was on a delimiter character.

Two changes here:

  • Added a list thing to treesit-thing-settings covering OCaml's
    container/delimited node types. On Emacs 31+ this gives us native
    forward-list, up-list, down-list and the hybrid
    treesit-forward-sexp-list for free.

  • For Emacs 29-30 (where the list thing isn't wired up by
    treesit-major-mode-setup), added neocaml--forward-sexp-hybrid
    that falls back to scan-sexps when point is on a delimiter.
    This follows the same approach Emacs 31 takes internally.

@bbatsov bbatsov force-pushed the fix-delete-pair-navigation branch 3 times, most recently from 632b828 to 9575314 Compare March 13, 2026 22:44
Add a `list' thing to `treesit-thing-settings' covering all OCaml
container/delimited node types.  On Emacs 31+ this enables native
support for `forward-list', `up-list', `down-list', and correct
`forward-sexp' behavior on delimiters via `treesit-forward-sexp-list'.

For Emacs 29-30, introduce `neocaml--forward-sexp-hybrid' which falls
back to syntax-table-based `scan-sexps' when point is on a delimiter
character, so that commands like `delete-pair' find the correct
matching paren instead of jumping to an unrelated tree-sitter node.
@bbatsov bbatsov force-pushed the fix-delete-pair-navigation branch from 9575314 to 7888359 Compare March 14, 2026 14:51
@bbatsov bbatsov merged commit b134d83 into main Mar 14, 2026
3 checks passed
@bbatsov bbatsov deleted the fix-delete-pair-navigation branch March 14, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Surprising delete-pair behavior

1 participant