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

Forgiving variant of pygn-mode-pgn-at-pos defun #186

Closed rolandwalker closed 3 years ago

rolandwalker commented 3 years ago

Here is one way to paper over the issues in #184 , and this might be good for a quick fix.

We make pygn-mode-pgn-at-pos return nil instead of ever throwing an exception. This makes good sense — at least, the exception made no sense.

We introduce pygn-mode--pgn-at-pos-or-stub, a forgiving variant of the defun, which returns a stub value instead of nil (when the point is outside of a game).

Then the various interactive commands are made to use the forgiving pygn-mode--pgn-at-pos-or-stub, so that they don't throw exceptions depending on where the point is. For example, if you try to echo FEN at point, and you are in between games, you will get the FEN for the default starting position.

Criticism: if every customer of the interface ends up using pygn-mode--pgn-at-pos-or-stub, then maybe the interface is not good.

Alternative: when the point is outside a game, return the preceding game. I think this was the pre-tree-sitter behavior. Not sure what is best when the point is before any game.

Edit: for the alternative case, we already have pygn-mode-game-start-position-forgive-trailing-pos.