]> code.delx.au - gnu-emacs-elpa/blobdiff - chess-module.el
Work on the manual.
[gnu-emacs-elpa] / chess-module.el
index 47b5ff04ac2a075b4e2f4eac6169b0bf1b267534..c58184401ef48e4fa7625cf5eeb9318321edea48 100644 (file)
@@ -1,8 +1,28 @@
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;
-;; Basic module support code underlying all chess.el modules
-;;
-;; $Revision$
+;;; chess-module.el --- Basic module support code underlying all chess.el modules
+
+;; Copyright (C) 2002, 2004, 2008, 2014  Free Software Foundation, Inc.
+
+;; Author: John Wiegley <johnw@gnu.org>
+;; Keywords: games
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(eval-when-compile (require 'cl-lib))
+
+(require 'chess-game)
 
 (defvar chess-module-game nil)
 (defvar chess-module-event-handler nil)
           ,@body)
        ,@body)))
 
+(put 'chess-with-current-buffer 'lisp-indent-function 1)
+
 (defun chess-module-create (derived game &optional buffer-name
                                    &rest ctor-args)
   (let* ((name (symbol-name derived))
-        (handler (intern-soft (concat name "-handler")))
-        buffer)
-    (unless handler
+        handler)
+    (unless (and (require derived nil t)
+                (setq handler (intern-soft (concat name "-handler"))))
       (chess-error 'no-such-module name))
     (with-current-buffer (generate-new-buffer (or buffer-name
                                                  (format " *%s*" name)))
     (if chess-module-leader
        (chess-game-run-hooks chess-module-game 'destroy))))
 
-(defun chess-engine-set-game (module game &optional no-setup)
+(defun chess-module-set-game (module game &optional no-setup)
   (chess-with-current-buffer module
     (let ((chess-game-inhibit-events no-setup))
       (chess-game-copy-game chess-module-game game))))
 
 (defun chess-module-set-game* (module game)
   (chess-with-current-buffer module
-    (assert game)
+    (cl-assert game)
     (if chess-module-game
        (chess-module-detach-game nil))
     (setq chess-module-game game)
   (chess-with-current-buffer module
     (setq chess-module-leader nil)))
 
-(defun chess-module-destroy (module)
+(defun chess-module-destroy (&optional module)
   (let ((buf (or module (current-buffer))))
     (when (buffer-live-p buf)
       (with-current-buffer buf
-       (remove-hook 'kill-buffer-hook 'chess-module-destroy t))
-      (chess-module-detach-game nil)
+       (remove-hook 'kill-buffer-hook 'chess-module-destroy t)
+       (chess-module-detach-game nil))
       (kill-buffer buf))))
 
 (defun chess-module-event-handler (game object event &rest args)