]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/gnugo/gnugo.el
[gnugo] Don't show underscore in group-animation message.
[gnu-emacs-elpa] / packages / gnugo / gnugo.el
index e2dbd21aaf1a16b31d541be08dbaaf0f01bcf988..15143ba65b82096e6844ec8f876c70860d4ca2a0 100644 (file)
@@ -170,12 +170,8 @@ For ~t, the value is a snapshot, use `gnugo-refresh' to update it.")
 ;;;---------------------------------------------------------------------------
 ;;; Support functions
 
-(put  'gnugo-put 'lisp-indent-function 1)
-(defun gnugo-put (key value) (puthash key value gnugo-state))
-(defun gnugo-get (key)       (gethash key gnugo-state))
-
-(let ((docs "Put or get move/game/board-specific properties.
-\(This docstring is shared by `gnugo-put' and `gnugo-get'.\)
+(defun gnugo-put (key value)
+  "Associate move/game/board-specific property KEY with VALUE.
 
 There are many properties, each named by a keyword, that record and control
 how gnugo.el manages each game.  Each GNUGO Board buffer has its own set
@@ -233,9 +229,14 @@ you may never really understand to any degree of personal satisfaction\".
 
  :last-user-bpos -- board position; keep the hapless human happy
 
-As things stabilize probably more info will be added to this docstring."))
-  (put 'gnugo-put 'function-documentation docs)
-  (put 'gnugo-get 'function-documentation docs))
+As things stabilize probably more info will be added to this docstring."
+  (declare (indent 1))
+  (puthash key value gnugo-state))
+
+(defun gnugo-get (key)
+  "Return the move/game/board-specific value for KEY.
+See `gnugo-put'."
+  (gethash key gnugo-state))
 
 (defun gnugo-describe-internal-properties ()
   "Pretty-print `gnugo-state' properties in another buffer.
@@ -533,7 +534,23 @@ a format string applied to the rest of the args."
 (defun gnugo-merge-showboard-results ()
   (let ((aft (substring (cdr (gnugo-synchronous-send/return "showboard")) 3))
         (adj 1)                         ; string to buffer position adjustment
-        (sync "[0-9]+ stones$")
+
+        (sync "[0-9]* stones$")
+        ;; Note: `sync' used to start w/ "[0-9]+", but that is too
+        ;; restrictive a condition that fails in the case of:
+        ;;
+        ;; (before)
+        ;;   ... WHITE has captured 1 stones
+        ;;                           ^
+        ;; (after)
+        ;;   ... WHITE has captured 14 stones
+        ;;                           ^
+        ;;
+        ;; where the after count has more digits than the before count,
+        ;; but shares the same leading digits.  In this case, the result
+        ;; of `compare-strings' points to the SPC following the before
+        ;; count (indicated by caret in this example).
+
         (bef (buffer-substring-no-properties (point-min) (point-max)))
         (bef-start 0) (bef-idx 0)
         (aft-start 0) (aft-idx 0)
@@ -1057,14 +1074,16 @@ To start a game try M-x gnugo."
     (gnugo-push-move t "resign")
     (gnugo-refresh)))
 
-(defun gnugo-animate-group (command)
-  (message "Computing %s ..." command)
+(defun gnugo-animate-group (w/d)
+  ;; W/D is a symbol, either ‘worm’ or ‘dragon’.
   (let* ((pos (gnugo-position))
          (orig-b-m-p (buffer-modified-p))
-         (stones (if (memq (char-after) '(?X ?O))
-                     (gnugo-lsquery "%s %s" command pos)
-                   (user-error "No stone at %s" pos))))
-    (message "Computing %s ... %s in group." command (length stones))
+         blurb stones)
+    (unless (memq (char-after) '(?X ?O))
+      (user-error "No stone at %s" pos))
+    (setq blurb (message "Computing %s stones ..." w/d)
+          stones (gnugo-lsquery "%s_stones %s" w/d pos))
+    (message "%s %s in group." blurb (length stones))
     (setplist (gnugo-f 'anim) nil)
     (let* ((spec (let ((spec (split-string gnugo-animation-string "" t)))
                    (cond ((gnugo-get :display-using-images)
@@ -1112,7 +1131,7 @@ Signal error if done out-of-turn or if game-over.
 See variable `gnugo-animation-string' for customization."
   (interactive)
   (gnugo-gate)
-  (gnugo-animate-group "worm_stones"))
+  (gnugo-animate-group 'worm))
 
 (defun gnugo-worm-data ()
   "Display in another buffer data from \"worm\" at current position.
@@ -1127,7 +1146,7 @@ Signal error if done out-of-turn or if game-over.
 See variable `gnugo-animation-string' for customization."
   (interactive)
   (gnugo-gate)
-  (gnugo-animate-group "dragon_stones"))
+  (gnugo-animate-group 'dragon))
 
 (defun gnugo-dragon-data ()
   "Display in another buffer data from \"dragon\" at current position.
@@ -1572,8 +1591,7 @@ NOTE: At this time, GTP command handling specification is still
     (let* ((split (split-string command))
            (cmd (intern (car split)))
            (spec (get cmd :gnugo-gtp-command-spec))
-           (full (plist-get spec :full))
-           (last-message nil))
+           (full (plist-get spec :full)))
       (if full
           (funcall full (cdr split))
         (message "Doing %s ..." command)
@@ -1693,22 +1711,20 @@ In this mode, keys do not self insert.  Default keybindings:
                            'gnugo-option-history))
         (rules "Japanese")
         board-size user-color handicap komi minus-l infile)
-    (mapc (lambda (x)
-            (apply (lambda (var default opt &optional rx)
-                     (set var
-                          (or (when (string-match opt args)
-                                (let ((start (match-end 0)) s)
-                                  (string-match (or rx "[0-9.]+") args start)
-                                  (setq s (match-string 0 args))
-                                  (if rx s (string-to-number s))))
-                              default)))
-                   x))
-          '((board-size      19 "--boardsize")
-            (user-color "black" "--color" "\\(black\\|white\\)")
-            (handicap         0 "--handicap")
-            (komi           0.0 "--komi")
-            (minus-l        nil "\\([^-]\\|^\\)-l[ ]*" "[^ ]+")
-            (infile         nil "--infile" "[ ]*[^ ]+")))
+    (dolist (x '((board-size      19 "--boardsize")
+                 (user-color "black" "--color" "\\(black\\|white\\)")
+                 (handicap         0 "--handicap")
+                 (komi           0.0 "--komi")
+                 (minus-l        nil "\\([^-]\\|^\\)-l[ ]*" "[^ ]+")
+                 (infile         nil "--infile" "[ ]*[^ ]+")))
+      (destructuring-bind (var default opt &optional rx) x
+        (set var
+             (or (when (string-match opt args)
+                   (let ((start (match-end 0)) s)
+                     (string-match (or rx "[0-9.]+") args start)
+                     (setq s (match-string 0 args))
+                     (if rx s (string-to-number s))))
+                 default))))
     (gnugo-put :user-color user-color)
     (when (string-match "--chinese-rules" args)
       (setq rules "Chinese"))
@@ -1718,9 +1734,7 @@ In this mode, keys do not self insert.  Default keybindings:
                               "--mode" "gtp" "--quiet"
                               proc-args)))
     ;; Emacs is too protective sometimes, blech.
-    (remove-hook (make-local-variable 'kill-buffer-query-functions)
-                 'process-kill-buffer-query-function
-                 t)
+    (set-process-query-on-exit-flag (gnugo-get :proc) nil)
     (when (or minus-l infile)
       (mapc (lambda (x)
               (apply (lambda (prop q)