[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnugo-devel] Re: XPM's
From: |
Thien-Thi Nguyen |
Subject: |
[gnugo-devel] Re: XPM's |
Date: |
Thu, 09 Jan 2003 12:21:56 -0800 |
slightly improved:
(dolist (xpm-var (mapcar 'car (apropos "^gnugo-xpm-")))
(let ((xpm (eval xpm-var)))
(insert-image (find-image `((:type xpm :data ,xpm :ascent 100))))
(when (string-match "[i369]$" (symbol-name xpm-var))
(insert "\n"))))
anyway, below is a diff against gnugo.el 1.19 that revamps gnugo-command
handling again (the gnugo-command-output var of previous diff is gone).
of note is the :help command now jumps to the gtp reference info node.
to play, read "command properties" comments, add command properties as
you see fit, and if they work in a nice way, let me know and i'll
include them in gnugo.el. i have seeded the process w/ my best guess
for :clear_board and :fixed_handicap. there are many more commands to
consider, but since i'm just a lowly "hit SPC to make a move" user, i
invite those who actually use these commands to help define and improve
their proper handling (given the properties framework).
lastly, ";" is now also bound to gnugo-command.
thi
_____________________________________________
rcsdiff -c -w -b -r1.19 gnugo.el
===================================================================
RCS file: RCS/gnugo.el,v
retrieving revision 1.19
diff -c -w -b -r1.19 gnugo.el
*** gnugo.el 2002/12/28 03:15:50 1.19
--- gnugo.el 2003/01/09 20:00:44
***************
*** 1,6 ****
! ;;; ID: $Id: gnugo.el,v 1.19 2002/12/28 03:15:50 ttn Exp $
;;;
! ;;; Copyright (C) 1999, 2000, 2002 Thien-Thi Nguyen
;;; This file is part of ttn's personal elisp library, released under GNU
;;; GPL with ABSOLUTELY NO WARRANTY. See the file COPYING for details.
--- 1,6 ----
! ;;; ID: $Id: gnugo.el,v 1.23 2003/01/09 20:00:44 ttn Exp $
;;;
! ;;; Copyright (C) 1999, 2000, 2002, 2003 Thien-Thi Nguyen
;;; This file is part of ttn's personal elisp library, released under GNU
;;; GPL with ABSOLUTELY NO WARRANTY. See the file COPYING for details.
***************
*** 29,35 ****
(defvar gnugo-board-mode-map nil
"Keymap for GNUGO Board mode.")
! (defvar gnugo-option-history '()
"History of additional GNUGO command-line options.")
(defvar gnugo-animation-string
--- 29,35 ----
(defvar gnugo-board-mode-map nil
"Keymap for GNUGO Board mode.")
! (defvar gnugo-option-history nil
"History of additional GNUGO command-line options.")
(defvar gnugo-animation-string
***************
*** 403,408 ****
--- 403,477 ----
black black-captures white white-captures est)))
;;;---------------------------------------------------------------------------
+ ;;; Command properties and gnugo-command
+
+ ;; A direct gtp command can easily confuse gnugo.el, so we allow for
+ ;; interpretation of any command (and still become confused when the
+ ;; heuristics fail ;-). Both control and data paths are are influenced by
+ ;; these properties:
+ ;;
+ ;; gnugo-full -- completely interpret the command string; the value is a
+ ;; func that takes the list of words derived from splitting the
+ ;; command string (minus the command) and handles everything.
+ ;;
+ ;; gnugo-rinse -- function taking raw output string and returning a
+ ;; (possibly filtered) replacement, the only one able
+ ;; to set the `gnugo-post-function' property (below).
+ ;; value may also be a list of such functions.
+ ;;
+ ;; gnugo-output -- symbol specifying the preferred output method.
+ ;; message -- show output in minibuffer
+ ;; discard -- sometimes you just don't care
+ ;; default is to switch to buffer "*gnugo command output*"
+ ;; if the output has a newline, otherwise use `message'.
+ ;;
+ ;; gnugo-post-function -- function or list of functions to call after the
+ ;; command (also after all output processing); only
+ ;; settable by a `gnugo-rinse' function.
+
+ (defun gnugo-command (command)
+ "During a GNU Go game, send Go Text Protocol COMMAND to the subprocess."
+ (interactive "sCommand: ")
+ (if (string= "" command)
+ (message "(no command given)")
+ (let* ((split (split-string command))
+ (cmd (intern (car split)))
+ (full (get cmd 'gnugo-full))
+ (last-message nil))
+ (if full
+ (funcall full (cdr split))
+ (message "Doing %s ..." command)
+ (let* ((ans (cdr (gnugo-synchronous-send/return command)))
+ (rinse (get cmd 'gnugo-rinse))
+ (where (get cmd 'gnugo-output)))
+ (put cmd 'gnugo-post-function nil)
+ (when rinse
+ (cond ((functionp rinse) (setq ans (funcall rinse ans)))
+ ((listp rinse) (while rinse
+ (setq ans (funcall (car rinse) ans)
+ rinse (cdr rinse))))
+ (t (error "bad gnugo-rinse property: %s" rinse))))
+ (if (string-match "unknown.command" ans)
+ (message ans)
+ (cond ((eq 'discard where) (message ""))
+ ((or (eq 'message where)
+ (not (string-match "\n" ans)))
+ (message ans))
+ (t (switch-to-buffer "*gnugo command output*")
+ (erase-buffer)
+ (insert ans)
+ (message "Doing %s ... done." command)))
+ (let ((pf (get cmd 'gnugo-post-function)))
+ (when pf
+ (cond ((functionp pf) (funcall pf))
+ ((listp pf) (while pf
+ (progn (funcall (car pf))
+ (setq pf (cdr pf)))))
+ (t (error "bad gnugo-post-function property: %s"
+ pf)))
+ (put cmd 'gnugo-post-function nil)))))))))
+
+ ;;;---------------------------------------------------------------------------
;;; Major mode for interacting with a GNUGO subprocess
(defun gnugo-board-mode ()
***************
*** 435,460 ****
! Estimate score (at any time).
! : Extended command. Type in a string to be passed
! directly to the GNUGO subprocess. Output goes to the
! buffer \"*gnugo command output*\" which is displayed.
! Note that some commands might confuse gnugo.el."
(kill-all-local-variables)
(use-local-map gnugo-board-mode-map)
(setq major-mode 'gnugo-board-mode)
(setq mode-name "GNUGO Board"))
- (defun gnugo-command (command)
- "During a GNU Go game, send Go Text Protocol COMMAND to the subprocess.
- Display output to buffer *gnugo command output* and switch to there."
- (interactive "sCommand: ")
- (message "Doing %s ..." command)
- (let ((data (cdr (gnugo-synchronous-send/return command))))
- (switch-to-buffer "*gnugo command output*")
- (erase-buffer)
- (insert data))
- (message "Doing %s ... done." command))
-
;;;---------------------------------------------------------------------------
;;; Entry point
--- 504,519 ----
! Estimate score (at any time).
! : or ; Extended command. Type in a string to be passed (quite
! indirectly) to the GNUGO subprocess. Output and emacs
! behavior depend on which command is given. Try `help'
! to get a list of all commands. Note that some commands
! may confuse gnugo.el."
(kill-all-local-variables)
(use-local-map gnugo-board-mode-map)
(setq major-mode 'gnugo-board-mode)
(setq mode-name "GNUGO Board"))
;;;---------------------------------------------------------------------------
;;; Entry point
***************
*** 554,563 ****
("t" . gnugo-toggle-dead-group)
("!" . gnugo-estimate-score)
(":" . gnugo-command)
;; mouse
([(down-mouse-1)] . gnugo-mouse-move)
([(down-mouse-3)] . gnugo-mouse-pass))))
(provide 'gnugo)
! ;;; $RCSfile: gnugo.el,v $$Revision: 1.19 $ ends here
--- 613,646 ----
("t" . gnugo-toggle-dead-group)
("!" . gnugo-estimate-score)
(":" . gnugo-command)
+ (";" . gnugo-command)
;; mouse
([(down-mouse-1)] . gnugo-mouse-move)
([(down-mouse-3)] . gnugo-mouse-pass))))
+ (put 'help 'gnugo-full
+ '(lambda (sel)
+ (info "(gnugo)GTP command reference")
+ (if (not sel)
+ (message "(you can also try \"help COMMAND\" next time)")
+ (let ((topic (intern (car sel))))
+ (goto-char (point-min))
+ (when (search-forward (concat "* " (car sel) "\n") (point-max) t)
+ (let (buffer-read-only)
+ (when (get topic 'gnugo-full)
+ (insert "[NOTE: fully handled by gnugo.el]\n"))
+ (when (get topic 'gnugo-rinse)
+ (insert "[NOTE: output rinsed by gnugo.el]\n"))))))))
+
+ (mapc '(lambda (command)
+ (put command 'gnugo-output 'discard)
+ (put command 'gnugo-rinse
+ '(lambda (ans)
+ (put cmd 'gnugo-post-function 'gnugo-refresh)
+ ans)))
+ '(clear_board
+ fixed_handicap))
+
(provide 'gnugo)
! ;;; $RCSfile: gnugo.el,v $$Revision: 1.23 $ ends here