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