]> code.delx.au - gnu-emacs-elpa/commitdiff
*** no comment ***
authorJohn Wiegley <johnw@newartisans.com>
Tue, 9 Apr 2002 23:51:30 +0000 (23:51 +0000)
committerJohn Wiegley <johnw@newartisans.com>
Tue, 9 Apr 2002 23:51:30 +0000 (23:51 +0000)
TODO
chess-display.el
chess-engine.el
chess-gnuchess.el
chess-ics.el
chess-irc.el
chess-network.el
chess.el

diff --git a/TODO b/TODO
index b9064a34e08cd913de36dc3935b7fd04c2df4f71..0dfbb691cb765c7d5ec98560e001513234840e12 100644 (file)
--- a/TODO
+++ b/TODO
@@ -9,14 +9,9 @@
 
 - Rewrite ics.el
 
-- Add acknowledgement to the chess-network protocol
-
 - Make use of the my-color data in chess-game.el to ensure that I only
   do what I should be doing
 
-- After somebody sends me "name", I need a responding event to tell
-  them my name
-
 - Allow the user to request a move retraction (ala takeback)
 
 - In edit mode, mouse-2 and mouse-3 should provide a drop-down list of
index ed94ae5e6e8e4706f1d6e871f29d25cfcf995b43..45561ca4301b0de2a05723e9694a8da58e3081ac 100644 (file)
@@ -53,6 +53,7 @@
 (defvar chess-display-ply)
 (defvar chess-display-position)
 (defvar chess-display-perspective)
+(defvar chess-display-main-p nil)
 (defvar chess-display-event-handler nil)
 (defvar chess-display-no-popup nil)
 (defvar chess-display-edit-mode nil)
@@ -64,6 +65,7 @@
 (make-variable-buffer-local 'chess-display-ply)
 (make-variable-buffer-local 'chess-display-position)
 (make-variable-buffer-local 'chess-display-perspective)
+(make-variable-buffer-local 'chess-display-main-p)
 (make-variable-buffer-local 'chess-display-event-handler)
 (make-variable-buffer-local 'chess-display-no-popup)
 (make-variable-buffer-local 'chess-display-edit-mode)
       (funcall handler 'initialize)
       (setq chess-display-event-handler handler
            chess-display-perspective perspective)
-      (add-hook 'kill-buffer-hook 'chess-display-on-kill nil t)
+      (add-hook 'kill-buffer-hook 'chess-display-quit nil t)
       (current-buffer))))
 
-(defun chess-display-on-kill ()
-  "Function called when the buffer is killed."
-  (chess-display-detach-game nil))
-
 (defun chess-display-destroy (display)
   "Destroy a chess display object, killing all of its buffers."
   (let ((buf (or display (current-buffer))))
     (when (buffer-live-p buf)
       (funcall chess-display-event-handler 'destroy)
-      (chess-display-detach-game display)
       (kill-buffer buf))))
 
 (defsubst chess-display-perspective (display)
     (erase-buffer)                     ; force a complete redraw
     (chess-display-update nil)))
 
+(defsubst chess-display-main-p (display)
+  (chess-with-current-buffer display
+    chess-display-main-p))
+
+(defun chess-display-set-main (display)
+  (chess-with-current-buffer display
+    (setq chess-display-main-p t)))
+
+(defun chess-display-clear-main (display)
+  (chess-with-current-buffer display
+    (setq chess-display-main-p nil)))
+
 
 (defun chess-display-set-position (display position &optional search-func)
   "Set the display position.
@@ -304,8 +313,10 @@ See `chess-display-type' for the different kinds of displays."
   (with-current-buffer display
     (cond
      ((eq event 'shutdown)
-      (ignore-errors
-       (chess-display-destroy nil)))
+      (chess-display-destroy nil))
+
+     ((eq event 'destroy)
+      (chess-display-detach-game nil))
 
      ((eq event 'pass)
       (let ((my-color (if chess-display-game
@@ -496,7 +507,9 @@ Basically, it means we are playing, not editing or reviewing."
 (defun chess-display-quit ()
   "Quit the current game."
   (interactive)
-  (if chess-display-game
+  (remove-hook 'kill-buffer-hook 'chess-display-quit t)
+  (if (and chess-display-main-p
+          chess-display-game)
       (chess-game-run-hooks chess-display-game 'shutdown)
     (chess-display-destroy nil)))
 
index 07d7bd610bb5bd2ca177e80ec73310378949901a..77cca30baf17e5c52f124b9e093cdc617de9e9b5 100644 (file)
 
 (defun chess-engine-on-kill ()
   "Function called when the buffer is killed."
-  (chess-engine-detach-game nil))
+  (chess-engine-command (current-buffer) 'shutdown))
 
 (defun chess-engine-destroy (engine)
   (let ((buf (or engine (current-buffer))))
     (when (buffer-live-p buf)
       (chess-engine-command engine 'destroy)
+      (remove-hook 'kill-buffer-hook 'chess-engine-on-kill t)
       (kill-buffer buf))))
 
 (defun chess-engine-command (engine event &rest args)
   (chess-with-current-buffer engine
-    (apply chess-engine-event-handler event args)))
+    (apply 'chess-engine-event-handler
+          (chess-engine-game nil) engine event args)))
 
 ;; 'ponder
 ;; 'search-depth
       (if proc
          (if (memq (process-status proc) '(run open))
              (process-send-string proc string)
-           (error "The engine you were using is no longer running"))
+           (message "The engine you were using is no longer running")
+           (chess-engine-command nil 'destroy))
        (chess-engine-command nil 'send string)))))
 
 (defun chess-engine-submit (engine string)
   "Submit the given STRING, so ENGINE sees it in its input stream."
   (chess-with-current-buffer engine
     (let ((proc chess-engine-process))
-      (if (and (processp proc)
-              (not (memq (process-status proc) '(run open))))
-         (error "The engine you were using is no longer running"))
+      (when (and (processp proc)
+                (not (memq (process-status proc) '(run open))))
+       (message "The engine you were using is no longer running")
+       (chess-engine-command nil 'destroy))
       (chess-engine-filter nil string))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
          (apply chess-engine-event-handler event args)))
     (cond
      ((eq event 'shutdown)
-      (ignore-errors
-       (chess-engine-destroy engine))))))
+      (chess-engine-destroy engine))
+
+     ((eq event 'destroy)
+      (chess-engine-detach-game engine)))))
 
 (defun chess-engine-filter (proc string)
   "Filter for receiving text for an engine from an outside source."
index c619bb3c15dc6cb37627f285968e4f69b47492d2..c26bf45de4df60c46ba4c33f6c2f153bdca7721e 100644 (file)
@@ -57,8 +57,7 @@
     (chess-engine-send nil "quit\n")
     (dolist (file chess-gnuchess-temp-files)
       (if (file-exists-p file)
-         (ignore-errors
-           (delete-file file)))))
+         (delete-file file))))
 
    ((eq event 'setup)
     (if (equal (car args) chess-starting-position)
index cadc95521998f7a660102c5f0de4b73c0e19c13d..0d046ca6e84169e0e360245b62257c7ca4cc3fb3 100644 (file)
@@ -179,8 +179,7 @@ who is black."
       nil))
 
    ((eq event 'shutdown)
-    (ignore-errors
-      (chess-engine-send nil "quit\n")))
+    (chess-engine-send nil "quit\n"))
 
    ((eq event 'move)
     (unless chess-ics-ensure-ics12
index 6459cc209dda22afccd7638d90267b70ad6a0cc7..dbc9cdfa429031ea70f8620c735e37d5e59af34c 100644 (file)
     nil)
 
    ((eq event 'shutdown)
-    (ignore-errors
-      (chess-engine-send nil "quit"))
-    (ignore-errors
-      (process-send-string chess-irc-process "QUIT :Goodbye\n"))
-    (ignore-errors
-      (kill-buffer (process-buffer chess-irc-process))))
+    (chess-engine-send nil "quit")
+    (process-send-string chess-irc-process "QUIT :Goodbye\n")
+    (kill-buffer (process-buffer chess-irc-process)))
 
    ((eq event 'send)
     (process-send-string chess-irc-process
index 39d9d33944f28573e78c0c8bba777892b363b9d8..ebc3b8fb2eb95f51d38deecc417082f74fb2861f 100644 (file)
@@ -63,8 +63,7 @@
       proc))
 
    ((eq event 'shutdown)
-    (ignore-errors
-      (chess-engine-send nil "quit\n")))
+    (chess-engine-send nil "quit\n"))
 
    ((eq event 'setup)
     (chess-engine-send nil (format "fen %s\n"
index ed80fea749964f68045ecc28ebf74d51674f9ba0..2c17206115defcddab725d6f68811212fdca5715 100644 (file)
--- a/chess.el
+++ b/chess.el
@@ -117,8 +117,9 @@ minibuffer, which works well for Emacspeak users."
 
 
     (require chess-default-display)
-    (chess-display-set-game
-     (chess-display-create chess-default-display my-color) game)
+    (let ((display (chess-display-create chess-default-display my-color)))
+      (chess-display-set-game display game)
+      (chess-display-set-main display))
     (chess-display-set-main display)
     (let ((engine-module
           (if arg