dwcoates / pygn-mode

An Emacs major-mode for chess PGN files, powered by Python
BSD 2-Clause "Simplified" License
10 stars 3 forks source link

Port pygn-mode-next-move to tree-sitter #163

Closed rolandwalker closed 3 years ago

rolandwalker commented 3 years ago

~This PR is branched off of #154 and will look like a mess until rebased.~ rebased!

~The code is definitely WIP. It works, and works better than what we had, and requires less code.~

~Still, I'd like to recast it in terms of pygn-mode--true-containing-node and tsc-get-next-sibling. Looking for the face with text-property-search-forward is a cheat.~

cc @qnix with tree-sitter's full parse, we will no longer require those glitchy regular expressions for navigation.

~Edit: I turned off testing against Emacs 26.3 just to make tests pass for the moment. Turns out text-property-search-forward was not available.~

Edit: This function is now implemented the "right way" in terms of pygn-mode--true-containing-node and tsc-get-next-sibling, and does not use text-property-search-forward. It also now should be straightforward to adapt this logic to pygn-mode-previous-move using the same principles.

One subtlety was that tree-sitter-node-at-point was sometimes needed instead of pygn-mode--true-containing-node, which is explained in a comment.

There may be ways to make the function slightly less verbose in a later refactor.