diff options
| -rw-r--r-- | TODO | 6 | ||||
| -rw-r--r-- | chess-autosave.el | 63 | ||||
| -rw-r--r-- | chess-display.el | 4 | ||||
| -rw-r--r-- | chess-engine.el | 4 | ||||
| -rw-r--r-- | chess-game.el | 8 | ||||
| -rw-r--r-- | chess.el | 19 |
6 files changed, 77 insertions, 27 deletions
@@ -9,6 +9,9 @@ analysis/highlight tools bughouse/crazyhouse +- if someone says Bx in the san input, use the x to constrain; but + using x is totally optional + - undoing a single move (my move) and moving again, causes chess-algebraic to get a little screwed up @@ -52,9 +55,6 @@ - Use server-side sockets in chess-network, if Emacs supports it -- Support auto-saving of games to PGN, and saving them at appropriate - points; this will require database interaction support - - Allow ASCII displays to use a separate frame - In edit mode, mouse-2 and mouse-3 should provide a drop-down list of diff --git a/chess-autosave.el b/chess-autosave.el new file mode 100644 index 0000000..8652070 --- /dev/null +++ b/chess-autosave.el @@ -0,0 +1,63 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; A special kind of display that merely autosaves the game +;; +;; $Revision$ + +(require 'chess-game) + +(defgroup chess-autosave nil + "A special display that autosaves after each move." + :group 'chess-display) + +(defcustom chess-autosave-file "~/.chess-save" + "Filename in which to autosave chess games." + :type '(choice file (const :tag "Do not auto-save" nil)) + :group 'chess-autosave) + +(chess-message-catalog 'english + '((chess-read-autosave . "There is a chess autosave file, read it? ") + (chess-delete-autosave . "Delete the autosave file? "))) + +(defun chess-autosave-handler (event &rest args) + (cond + ((eq event 'initialize) + (if (file-readable-p chess-autosave-file) + (if (y-or-n-p (chess-string 'chess-read-autosave)) + (prog1 + (chess-game-copy-game chess-display-game + (chess-read-game chess-autosave-file)) + (delete-file chess-autosave-file)) + (ignore + (if (y-or-n-p (chess-string 'chess-delete-autosave)) + (delete-file chess-autosave-file))))) + (kill-buffer (current-buffer)) + (set-buffer (find-file-noselect chess-autosave-file t)) + (current-buffer)) + + ((eq event 'post-move) + (chess-autosave-write chess-display-game chess-autosave-file)) + + ((eq event 'shutdown) + (delete-file chess-autosave-file)))) + +(defun chess-autosave-write (game file) + "Write a chess GAME to FILE as raw Lisp." + (let ((game-copy (copy-alist game))) + (chess-game-set-hooks game-copy nil) + (chess-game-set-data-alist game-copy nil) + (with-current-buffer (find-file-noselect file t) + (erase-buffer) + (prin1 game-copy (current-buffer)) + (basic-save-buffer) + (message nil)))) + +(defun chess-autosave-read (file) + "Read a chess game as raw Lisp from FILE." + (with-current-buffer (find-file-noselect file t) + (goto-char (point-min)) + (read (current-buffer)))) + +(provide 'chess-autosave) + +;;; chess-autosave.el ends here diff --git a/chess-display.el b/chess-display.el index 69a7e47..fedeb94 100644 --- a/chess-display.el +++ b/chess-display.el @@ -202,9 +202,7 @@ This is the function to call to cause a display to view a game. It will also update all of the listening engines and other displays to also view the same game." (chess-with-current-buffer display - (chess-game-set-tags chess-display-game (chess-game-tags game)) - ;; this call triggers `setup-game' for us - (chess-game-set-plies chess-display-game (chess-game-plies game)) + (chess-game-copy-game chess-display-set-game game) (chess-display-set-index nil (or index (chess-game-index game))))) (defun chess-display-detach-game (display) diff --git a/chess-engine.el b/chess-engine.el index 470e1a2..2eb887a 100644 --- a/chess-engine.el +++ b/chess-engine.el @@ -342,10 +342,8 @@ (defun chess-engine-set-game (engine game &optional no-setup) (chess-with-current-buffer engine - (chess-game-set-tags chess-engine-game (chess-game-tags game)) - ;; this call triggers `setup-game' for us (let ((chess-game-inhibit-events no-setup)) - (chess-game-set-plies chess-engine-game (chess-game-plies game))))) + (chess-game-copy-game chess-engine-game game)))) (defun chess-engine-set-game* (engine game &optional no-setup) (chess-with-current-buffer engine diff --git a/chess-game.el b/chess-game.el index 55b7588..1fcdb8b 100644 --- a/chess-game.el +++ b/chess-game.el @@ -196,6 +196,11 @@ matches." (chess-pgn-to-game pgn)) +(defsubst chess-game-copy-game (game new-game) + (chess-game-set-tags game (chess-game-tags new-game)) + (chess-game-set-plies game (chess-game-plies new-game))) + + (defun chess-game-create (&optional position tags) "Create a new chess game object. Optionally use the given starting POSITION. @@ -237,7 +242,8 @@ progress (nil), if it is drawn, resigned, mate, etc." (chess-game-run-hooks game 'move current-ply)))) (t - (chess-game-run-hooks game 'move current-ply))))) + (chess-game-run-hooks game 'move current-ply))) + (chess-game-run-hooks game 'post-move))) (defsubst chess-game-end (game keyword) "End the current game, by resignation, draw, etc." @@ -88,7 +88,8 @@ (defcustom chess-default-displays '((chess-images chess-ics1 chess-plain) - (chess-sound chess-announce)) + (chess-sound chess-announce) + chess-autosave) "Default displays to be used when starting a chess session. This is a list of display modules, all of which will be invoked. If any entry is itself a list, then it specifies a series of alternatives @@ -250,22 +251,6 @@ making it easy to go on to the next puzzle once you've solved one." (chess-game-set-data chess-display-game key (chess-game-data next-game key)))))) -(defun chess-write-game (game file) - "Write a chess GAME to FILE as raw Lisp." - (let ((game-copy (copy-alist game))) - (chess-game-set-hooks game-copy nil) - (chess-game-set-data-alist game-copy nil) - (with-current-buffer (find-file-noselect) - (erase-buffer) - (prin1 game) - (save-buffer)))) - -(defun chess-read-game (file) - "Read a chess game as raw Lisp from FILE." - (with-current-buffer (find-file-noselect) - (goto-char (point-min)) - (read))) - (provide 'chess) ;;; chess.el ends here |
