summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO5
-rw-r--r--chess-display.el31
-rw-r--r--chess-engine.el22
-rw-r--r--chess-gnuchess.el3
-rw-r--r--chess-ics.el3
-rw-r--r--chess-irc.el9
-rw-r--r--chess-network.el3
-rw-r--r--chess.el5
8 files changed, 45 insertions, 36 deletions
diff --git a/TODO b/TODO
index b9064a3..0dfbb69 100644
--- 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
diff --git a/chess-display.el b/chess-display.el
index ed94ae5..45561ca 100644
--- a/chess-display.el
+++ b/chess-display.el
@@ -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)
@@ -87,19 +89,14 @@
(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)
@@ -112,6 +109,18 @@
(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)))
diff --git a/chess-engine.el b/chess-engine.el
index 07d7bd6..77cca30 100644
--- a/chess-engine.el
+++ b/chess-engine.el
@@ -139,17 +139,19 @@
(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
@@ -217,16 +219,18 @@
(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))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -243,8 +247,10 @@
(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."
diff --git a/chess-gnuchess.el b/chess-gnuchess.el
index c619bb3..c26bf45 100644
--- a/chess-gnuchess.el
+++ b/chess-gnuchess.el
@@ -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)
diff --git a/chess-ics.el b/chess-ics.el
index cadc955..0d046ca 100644
--- a/chess-ics.el
+++ b/chess-ics.el
@@ -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
diff --git a/chess-irc.el b/chess-irc.el
index 6459cc2..dbc9cdf 100644
--- a/chess-irc.el
+++ b/chess-irc.el
@@ -70,12 +70,9 @@
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
diff --git a/chess-network.el b/chess-network.el
index 39d9d33..ebc3b8f 100644
--- a/chess-network.el
+++ b/chess-network.el
@@ -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"
diff --git a/chess.el b/chess.el
index ed80fea..2c17206 100644
--- 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