[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gnugo 876e0d3 195/357: [gnugo] New command: ‘C-c C-a’
From: |
Stefan Monnier |
Subject: |
[elpa] externals/gnugo 876e0d3 195/357: [gnugo] New command: ‘C-c C-a’ (gnugo-toggle-abdication) |
Date: |
Sun, 29 Nov 2020 14:51:20 -0500 (EST) |
branch: externals/gnugo
commit 876e0d352a482db08620ca9232b9f1538fafbec3
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>
[gnugo] New command: ‘C-c C-a’ (gnugo-toggle-abdication)
* packages/gnugo/gnugo.el (gnugo-refresh):
Include "Abd" in mode line if abdication enabled.
(gnugo-get-move-insertion-filter): If abdication enabled,
create and save a timer object to call ‘gnugo-get-move’
w/ the opposite of the current ‘color’.
(gnugo-toggle-abdication): New command.
(gnugo-board-mode-map): Add binding for ‘C-c C-a’.
---
NEWS | 1 +
gnugo.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/NEWS b/NEWS
index 0c17337..02c9337 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ NB: "RCS: X..Y " means that the particular release includes
- new command: ‘o’ (gnugo-oops)
- new command: ‘O’ (gnugo-okay)
- new command: ‘L’ (gnugo-frolic-in-the-leaves)
+ - new command: ‘C-c C-a’ (gnugo-toggle-abdication)
- new major mode: GNUGO Frolic (gnugo-frolic-mode)
- ‘gnugo-move-history’ returns last two moves w/ RSEL ‘two’
- performance improvements
diff --git a/gnugo.el b/gnugo.el
index 97d406d..0224f9f 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -1555,7 +1555,10 @@ its move."
;; this dynamicism is nice but excessive in its wantonness
;;- `(" [" (:eval ,form) "]")
;; this dynamicism is ok because the user triggers it
- (list (format " [%s]" (eval form))))))
+ (list (format " [%s]" (eval form))
+ '(:eval (if (gnugo-get :abd)
+ " Abd"
+ ""))))))
(force-mode-line-update))
;; last user move
(when (setq last (gnugo-get :last-user-bpos))
@@ -1597,8 +1600,19 @@ its move."
(message "%sSuggestion: %s"
(gnugo-get :diamond)
pos-or-pass))
- (gnugo-push-move color pos-or-pass)
- (gnugo--finish-move (current-buffer))))))))
+ (let* ((donep (gnugo-push-move color pos-or-pass))
+ (buf (current-buffer)))
+ (gnugo--finish-move buf)
+ (when (gnugo-get :abd)
+ (gnugo-put :abd
+ (unless donep
+ (run-at-time
+ 2 ;;; sec (frettoloso? dubioso!)
+ nil (lambda (buf color)
+ (with-current-buffer buf
+ (gnugo-get-move color)))
+ buf
+ (gnugo-other color))))))))))))
(defun gnugo-get-move (color &optional suggestion)
(gnugo-put :waiting (cons color suggestion))
@@ -2238,6 +2252,42 @@ If COMMENT is nil or the empty string, remove the
property entirely."
(unless (zerop (length comment))
(gnugo--decorate node `((:C . ,comment)))))
+(defun gnugo-toggle-abdication ()
+ "Toggle abdication, i.e., letting GNU Go play for you.
+When enabled, the mode line includes \"Abd\".
+Enabling signals error if the game is over.
+Disabling signals error if the color \"to play\" is the user color.
+This is to ensure that the user is the next to play after disabling."
+ (interactive)
+ (let ((last-mover (gnugo-get :last-mover))
+ (abd (gnugo-get :abd))
+ (warning ""))
+ (if abd
+ ;; disable
+ (destructuring-bind (gcolor ucolor &optional color . suggestion)
+ (list* (gnugo-get :gnugo-color)
+ (gnugo-get :user-color)
+ (gnugo-get :waiting))
+ (assert (not suggestion))
+ (when (string= last-mover gcolor)
+ (user-error "Sorry, too soon -- please wait for \"(%s to play\)\""
+ gcolor))
+ (when (timerp abd)
+ (cancel-timer abd))
+ (gnugo-put :abd nil)
+ (unless color
+ (gnugo-get-move gcolor)))
+ ;; enable
+ (when (gnugo-get :game-over)
+ (user-error "Sorry, game over"))
+ (gnugo-put :abd t)
+ (gnugo-get-move (gnugo-other last-mover)))
+ (message "Abdication %sabled%s"
+ (if (gnugo-get :abd)
+ "en"
+ "dis")
+ warning)))
+
;;;---------------------------------------------------------------------------
;;; Command properties and gnugo-command
@@ -2551,6 +2601,7 @@ starting a new one. See `gnugo-board-mode' documentation
for more info."
("F" . gnugo-display-final-score)
("A" . gnugo-switch-to-another)
("C" . gnugo-comment)
+ ("\C-c\C-a" . gnugo-toggle-abdication)
;; mouse
([(down-mouse-1)] . gnugo-mouse-move)
([(down-mouse-2)] . gnugo-mouse-move) ; mitigate accidents
- [elpa] externals/gnugo 62a7c8d 052/357: [gnugo slog] Specify second arg to ‘unintern’., (continued)
- [elpa] externals/gnugo 62a7c8d 052/357: [gnugo slog] Specify second arg to ‘unintern’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo eae8444 113/357: [gnugo int] Specify STREAM to ‘pp’ directly., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 00ae088 120/357: [gnugo int] Use ‘gnugo--tree-ends’ more., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo fa99b79 134/357: [gnugo int] Make ‘gnugo-board-buffer-p’ precise., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 8f99c83 151/357: [gnugo frolic int] Don't bother to awake w/ ‘col’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 283534a 157/357: [gnugo sgf int] Consolidate loops., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 671d7aa 147/357: [gnugo frolic] Sync column headers w/ buffer text; handle offsets., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 45fe672 169/357: [gnugo int] Move :SZ access into ‘gnugo--as-pos-func’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 5e24ee5 182/357: [gnugo int] Use GTP ‘reg_genmove’ instead of ‘genmove’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo e387d96 193/357: [gnugo int] Accept color for ‘gnugo-push-move’ 1st arg., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 876e0d3 195/357: [gnugo] New command: ‘C-c C-a’ (gnugo-toggle-abdication),
Stefan Monnier <=
- [elpa] externals/gnugo 1fa7d59 204/357: [gnugo int] Add abstraction: gnugo--plant-and-climb, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo d96223f 209/357: [gnugo] Move most of ‘gnugo-board-mode’ to ‘gnugo’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo eb77485 215/357: [gnugo int] Don't make ‘font-lock-defaults’ buffer-local., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 4d5f998 217/357: [gnugo int] Decruft: Drop unused local var., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo e6c0a07 229/357: [gnugo int] Fix bug: On -l/--infile, don't set :last-mover., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 11543e5 232/357: [gnugo] Reduce modifier key bouncing for "quick peek" frolics., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo dae8f08 231/357: [gnugo] Fix bug: DTRT for :last-user-bpos in undo-one-move ME-NEXT., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo f102d7f 240/357: [gnugo] Allow user to move for GNU Go., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 9969838 260/357: [gnugo int] Drop abstractions: gnugo--{ERR-wait, gate-game-over}, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo b9fa668 265/357: [gnugo int] Drop redundant ‘gnugo-gate’ calls., Stefan Monnier, 2020/11/29