- 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
(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)
(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.
(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
(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)))
(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."
(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)
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
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
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"
(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