[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gnugo ee09531 192/357: [gnugo] New command: ‘S’ (gnugo
From: |
Stefan Monnier |
Subject: |
[elpa] externals/gnugo ee09531 192/357: [gnugo] New command: ‘S’ (gnugo-request-suggestion) |
Date: |
Sun, 29 Nov 2020 14:51:19 -0500 (EST) |
branch: externals/gnugo
commit ee0953112db1f9fcc1b433b3e8d2f234b2e0fd13
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>
[gnugo] New command: ‘S’ (gnugo-request-suggestion)
* packages/gnugo/gnugo.el (gnugo-gate):
If waiting for a suggestion, say "Still thinking"
instead of "Not your turn yet" in error message.
(gnugo--q): If waiting for a suggestion, say
"receive a suggestion" instead of "play" in error message.
(gnugo--rename-buffer-portion): New func.
(gnugo-get-move-insertion-filter): On received suggestion,
rename buffer w/ "to play", warp the cursor unless nonsensical
or inhibited, and display the suggestion in the echo area.
(gnugo-get-move): Take optional arg SUGGESTION;
save it as well as color in :waiting.
(gnugo-request-suggestion): New command.
(gnugo-board-mode-map): Add binding for ‘S’.
---
NEWS | 1 +
gnugo.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++------------
2 files changed, 51 insertions(+), 12 deletions(-)
diff --git a/NEWS b/NEWS
index a6be4b8..0c17337 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ NB: "RCS: X..Y " means that the particular release includes
- ‘C-u F’ adds the (abbreviated) blurb as a comment to the last node
- new keybinding for ‘gnugo-undo-one-move’: M-u
- ‘gnugo-undo-one-move’ can optionally arrange for you to play next
+ - new command: ‘S’ (gnugo-request-suggestion)
- new command: ‘C’ (gnugo-comment)
- new command: ‘o’ (gnugo-oops)
- new command: ‘O’ (gnugo-okay)
diff --git a/gnugo.el b/gnugo.el
index b15e0bb..37d5a5b 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -334,9 +334,13 @@ Handle the big, slow-to-render, and/or uninteresting ones
specially."
(user-error "Wrong buffer -- try M-x gnugo"))
(unless (gnugo-get :proc)
(user-error "No \"gnugo\" process!"))
- (when (gnugo-get :waiting)
- (user-error "Not your turn yet -- please wait for \"\(%s to play\)\""
- (gnugo-get :user-color)))
+ (let ((slow (gnugo-get :waiting)))
+ (when slow
+ (user-error "%s -- please wait for \"\(%s to play\)\""
+ (if (cdr slow)
+ "Still thinking"
+ "Not your turn yet")
+ (gnugo-get :user-color))))
(when (and in-progress-p (gnugo-get :game-over))
(user-error "Sorry, game over")))
@@ -368,7 +372,10 @@ status of the command. See also `gnugo-query'."
(let ((slow (gnugo-get :waiting))
(proc (gnugo-get :proc)))
(when slow
- (user-error "Sorry, still waiting for %s to play" slow))
+ (user-error "Sorry, still waiting for %s to %s"
+ (car slow) (if (cdr slow)
+ "receive a suggestion"
+ "play")))
(process-put proc :incomplete t)
(process-put proc :srs "") ; synchronous return stash
(gnugo--begin-exchange
@@ -1554,21 +1561,38 @@ its move."
;;;---------------------------------------------------------------------------
;;; Game play actions
+(defun gnugo--rename-buffer-portion (old new)
+ (let ((name (buffer-name)))
+ (when (string-match old name)
+ (rename-buffer (replace-match new t t name)))))
+
(defun gnugo-get-move-insertion-filter (proc string)
(with-current-buffer (process-buffer proc)
(let* ((so-far (gnugo-get :get-move-string))
(full (gnugo-put :get-move-string (concat so-far string))))
(when (string-match "^= \\(.+\\)\n\n" full)
- (let ((pos-or-pass (match-string 1 full))
- (color (gnugo-get :waiting)))
+ (destructuring-bind (pos-or-pass color . suggestion)
+ (cons (match-string 1 full)
+ (gnugo-get :waiting))
(gnugo-put :get-move-string nil)
(gnugo-put :waiting nil)
- (gnugo-push-move (string= color (gnugo-get :user-color))
- pos-or-pass)
- (gnugo--finish-move (current-buffer)))))))
-
-(defun gnugo-get-move (color)
- (gnugo-put :waiting color)
+ (if suggestion
+ (progn
+ (gnugo--rename-buffer-portion "waiting for suggestion"
+ "to play")
+ (unless (or (gnugo--passp full)
+ (eq 'nowarp suggestion))
+ (gnugo-goto-pos pos-or-pass))
+ (message "%sSuggestion: %s"
+ (gnugo-get :diamond)
+ pos-or-pass))
+ (gnugo-push-move (string= (gnugo-get :user-color)
+ color)
+ pos-or-pass)
+ (gnugo--finish-move (current-buffer))))))))
+
+(defun gnugo-get-move (color &optional suggestion)
+ (gnugo-put :waiting (cons color suggestion))
(gnugo--begin-exchange
(gnugo-get :proc) 'gnugo-get-move-insertion-filter
;; We used to use ‘genmove’ here, but that forced asymmetry in
@@ -1600,6 +1624,19 @@ its move."
(or (get-text-property (point) 'gnugo-position)
(user-error "Not a proper position point")))
+(defun gnugo-request-suggestion (&optional nowarp)
+ "Request a move suggestion from GNU Go.
+After some time (during which you can do other stuff),
+Emacs displays the suggestion in the echo area and warps the
+cursor to the suggested position. Prefix arg inhibits warp."
+ (interactive "P")
+ (gnugo-gate t)
+ (gnugo--rename-buffer-portion "to play" "waiting for suggestion")
+ (gnugo-get-move (gnugo-get :user-color)
+ (if nowarp
+ 'nowarp
+ t)))
+
(defun gnugo-move ()
"Make a move on the GNUGO Board buffer.
The position is computed from current point.
@@ -2470,6 +2507,7 @@ starting a new one. See `gnugo-board-mode' documentation
for more info."
(mapc (lambda (pair)
(define-key gnugo-board-mode-map (car pair) (cdr pair)))
'(("?" . describe-mode)
+ ("S" . gnugo-request-suggestion)
("\C-m" . gnugo-move)
(" " . gnugo-move)
("P" . gnugo-pass)
- [elpa] externals/gnugo 566623c 121/357: [gnugo int] Invert ‘if’ CONDITION and THEN/ELSE clauses., (continued)
- [elpa] externals/gnugo 566623c 121/357: [gnugo int] Invert ‘if’ CONDITION and THEN/ELSE clauses., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 19309c3 139/357: [gnugo frolic] Handle invalid branch more consistently., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo d214e7e 137/357: [gnugo frolic] Add command to set the main line., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo dd42857 148/357: [gnugo frolic] Set ‘truncate-lines’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 1a544a5 154/357: [gnugo int] Whitespace munging; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 89d10e4 159/357: [gnugo int] Reorder gametree IR: ENDS, MNUM, ROOT, KIDS., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo bba08d3 158/357: [gnugo sgf int] Internalize ‘gnugo/sgf-hang-from-root’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 2f09438 145/357: [gnugo int] Fix syntax error., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 0eede2a 175/357: [gnugo int] Add abstraction: gnugo--count-query, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 8a064c5 184/357: [gnugo int] Incorporate *-play-stone into ‘gnugo-push-move’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo ee09531 192/357: [gnugo] New command: ‘S’ (gnugo-request-suggestion),
Stefan Monnier <=
- [elpa] externals/gnugo bc92d6d 202/357: [gnugo frolic] Type ‘Q’ to quit., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo a3baa99 200/357: [gnugo int] Use ‘following-char’ more., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo e644695 203/357: [gnugo] Increase S/N for ‘C-u F’ comment., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 7b29f73 219/357: [gnugo int] Decruft: Don't stash :proc-args., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 12d3d80 216/357: [gnugo] Keep GNUGO Board buffer read-only., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 4b6e204 221/357: [gnugo int] Move some prop jamming to ‘gnugo-board-mode’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo d52bbc7 222/357: [gnugo int] Add abstraction: gnugo--nquery, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo e837853 226/357: [gnugo int] Declare ‘lexical-binding: t’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo bc4abdc 238/357: [gnugo int] Centralize some "No stone at POS" errors., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 78edde4 247/357: [gnugo maint] Update HACKING; nfc., Stefan Monnier, 2020/11/29