@@ -1200,6 +1200,14 @@ garbage."
12001200 start-pos
12011201 (point )))))
12021202
1203+ (defun pygn-mode--pgn-at-pos-or-stub (pos )
1204+ " Return a single-game PGN string inclusive of any move at POS.
1205+
1206+ Identical to `pygn-mode-pgn-at-pos' except that a stub value is returned
1207+ when POS is not inside a game."
1208+ (or (pygn-mode-pgn-at-pos pos)
1209+ " [Event \" ?\" ]\n\n *\n " ))
1210+
12031211(defun pygn-mode-pgn-at-pos-as-if-variation (pos )
12041212 " Return a single-game PGN string as if a variation had been played.
12051213
@@ -1779,7 +1787,7 @@ When called non-interactively, display the FEN corresponding to POS.
17791787With `prefix-arg' DO-COPY, copy the FEN to the kill ring, and to the system
17801788clipboard when running a GUI Emacs."
17811789 (interactive " d\n P" )
1782- (let ((fen (pygn-mode-pgn-to-fen (pygn-mode-pgn-at-pos pos))))
1790+ (let ((fen (pygn-mode-pgn-to-fen (pygn-mode-- pgn-at-pos-or-stub pos))))
17831791 (when do-copy
17841792 (kill-new fen)
17851793 (when (and (fboundp 'gui-set-selection )
@@ -1798,7 +1806,7 @@ clipboard when running a GUI Emacs."
17981806
17991807When called non-interactively, display the FEN corresponding to POS."
18001808 (interactive " d" )
1801- (let* ((fen (pygn-mode-pgn-to-fen (pygn-mode-pgn-at-pos pos)))
1809+ (let* ((fen (pygn-mode-pgn-to-fen (pygn-mode-- pgn-at-pos-or-stub pos)))
18021810 (buf (get-buffer-create pygn-mode-fen-buffer-name))
18031811 (win (get-buffer-window buf)))
18041812 (with-current-buffer buf
@@ -1829,7 +1837,7 @@ When called non-interactively, display the FEN corresponding to POS."
18291837 " Save the board image corresponding to POS to a file."
18301838 (let* ((pygn-mode-board-size (completing-read " Pixels per side: " nil nil nil nil nil pygn-mode-board-size))
18311839 (filename (read-file-name " SVG filename: " ))
1832- (svg-data (pygn-mode-pgn-to-board (pygn-mode-pgn-at-pos pos) 'svg )))
1840+ (svg-data (pygn-mode-pgn-to-board (pygn-mode-- pgn-at-pos-or-stub pos) 'svg )))
18331841 (with-temp-buffer
18341842 (insert svg-data)
18351843 (write-file filename))))
@@ -1839,7 +1847,7 @@ When called non-interactively, display the FEN corresponding to POS."
18391847
18401848When called non-interactively, display the board corresponding to POS."
18411849 (interactive " d" )
1842- (let* ((svg-data (pygn-mode-pgn-to-board (pygn-mode-pgn-at-pos pos) 'svg ))
1850+ (let* ((svg-data (pygn-mode-pgn-to-board (pygn-mode-- pgn-at-pos-or-stub pos) 'svg ))
18431851 (buf (pygn-mode--get-or-create-board-buffer))
18441852 (win (get-buffer-window buf)))
18451853 (with-current-buffer buf
@@ -1858,7 +1866,7 @@ When called non-interactively, display the board corresponding to POS."
18581866
18591867When called non-interactively, display the board corresponding to POS."
18601868 (interactive " d" )
1861- (let* ((text-data (pygn-mode-pgn-to-board (pygn-mode-pgn-at-pos pos) 'text ))
1869+ (let* ((text-data (pygn-mode-pgn-to-board (pygn-mode-- pgn-at-pos-or-stub pos) 'text ))
18621870 (buf (pygn-mode--get-or-create-board-buffer))
18631871 (win (get-buffer-window buf)))
18641872 (with-current-buffer buf
@@ -1931,7 +1939,7 @@ When called non-interactively, display the board corresponding to POS."
19311939
19321940When called non-interactively, display the line corresponding to POS."
19331941 (interactive " d" )
1934- (let* ((line (pygn-mode-pgn-to-line (pygn-mode-pgn-at-pos pos)))
1942+ (let* ((line (pygn-mode-pgn-to-line (pygn-mode-- pgn-at-pos-or-stub pos)))
19351943 (buf (get-buffer-create pygn-mode-line-buffer-name))
19361944 (win (get-buffer-window buf)))
19371945 (with-current-buffer buf
0 commit comments