(read_minibuf): Clean up the binding stack if
[bpt/emacs.git] / lisp / play / solitaire.el
index f761134..5b00718 100644 (file)
@@ -1,4 +1,4 @@
-;; solitaire.el --- game of solitaire in emacs lisp
+;;; solitaire.el --- game of solitaire in Emacs Lisp
 
 ;; Copyright (C) 1994 Free Software Foundation, Inc.
 
@@ -19,8 +19,9 @@
 ;; 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, write to the Free Software
-;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
 
 ;;; Code:
 
+(defgroup solitaire nil
+  "Game of solitaire."
+  :prefix "solitaire-"
+  :group 'games)
+
 (defvar solitaire-mode-map nil
   "Keymap for playing solitaire.")
 
+(defcustom solitaire-mode-hook nil
+  "Hook to run upon entry to solitaire."
+  :type 'hook
+  :group 'solitaire)
+
 (if solitaire-mode-map
     ()
   (setq solitaire-mode-map (make-sparse-keymap))
@@ -47,7 +58,7 @@
   (substitute-key-definition 'undo 'solitaire-undo
                             solitaire-mode-map global-map)
   (define-key solitaire-mode-map " " 'solitaire-do-check)
-  (define-key solitaire-mode-map "q" 'solitaire-quit)
+  (define-key solitaire-mode-map "q" 'quit-window)
 
   (define-key solitaire-mode-map [right] 'solitaire-right)
   (define-key solitaire-mode-map [left] 'solitaire-left)
@@ -115,10 +126,12 @@ The usual mnemonic keys move the cursor around the board; in addition,
 (defvar solitaire-end-x nil)
 (defvar solitaire-end-y nil)
 
-(defvar solitaire-auto-eval t
+(defcustom solitaire-auto-eval t
   "*Non-nil means check for possible moves after each major change.
 This takes a while, so switch this on if you like to be informed when
-the game is over, or off, if you are working on a slow machine.")
+the game is over, or off, if you are working on a slow machine."
+  :type 'boolean
+  :group 'solitaire)
 
 (defconst solitaire-valid-directions
   '(solitaire-left solitaire-right solitaire-up solitaire-down))
@@ -133,13 +146,13 @@ Move around the board using the cursor keys.
 Move stones using \\[solitaire-move] followed by a direction key.
 Undo moves using \\[solitaire-undo].
 Check for possible moves using \\[solitaire-do-check].
-(The variable solitaire-auto-eval controls whether to automatically
+\(The variable `solitaire-auto-eval' controls whether to automatically
 check after each move or undo)
 
 What is Solitaire?
 
 I don't know who invented this game, but it seems to be rather old and
-it's origin seems be northern Africa.  Here's how to play:
+its origin seems to be northern Africa.  Here's how to play:
 Initially, the board will look similar to this:
 
        Le Solitaire             
@@ -320,20 +333,18 @@ list containing three numbers: starting field, skipped field (from
 which a stone will be taken away) and target."
 
   (save-excursion
-    (let (move)
-      (fset 'move movesymbol)
-      (if (memq movesymbol solitaire-valid-directions)
-         (let ((start (point))
-               (skip (progn (move) (point)))
-               (target (progn (move) (point))))
-           (if (= skip target)
-               "Off Board!"
-             (if (or (/= ?o (char-after start))
-                     (/= ?o (char-after skip))
-                     (/= ?. (char-after target)))
-                 "Wrong move!"
-               (list start skip target))))
-       "Not a valid direction"))))
+    (if (memq movesymbol solitaire-valid-directions)
+       (let ((start (point))
+             (skip (progn (funcall movesymbol) (point)))
+             (target (progn (funcall movesymbol) (point))))
+         (if (= skip target)
+             "Off Board!"
+           (if (or (/= ?o (char-after start))
+                   (/= ?o (char-after skip))
+                   (/= ?. (char-after target)))
+               "Wrong move!"
+             (list start skip target))))
+      "Not a valid direction")))
 
 (defun solitaire-move (dir)
   "Pseudo-prefix command to move a stone in Solitaire."
@@ -415,11 +426,6 @@ Seen in info on text lines."
      (if (= (current-column) 0) 1 0)
      -1))
 
-(defun solitaire-quit ()
-  "Quit playing Solitaire."
-  (interactive)
-  (kill-buffer "*Solitaire*"))
-
 ;; And here's the spoiler:)
 (defun solitaire-solve ()
   "Spoil solitaire by solving the game for you - nearly ...