emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/gnugo f3c90cd 187/357: [gnugo] Make ‘C-u F’ add the bl


From: Stefan Monnier
Subject: [elpa] externals/gnugo f3c90cd 187/357: [gnugo] Make ‘C-u F’ add the blurb as a comment to the last node.
Date: Sun, 29 Nov 2020 14:51:18 -0500 (EST)

branch: externals/gnugo
commit f3c90cd6eed3fd11737d279789266f25aa1849e4
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>

    [gnugo] Make ‘C-u F’ add the blurb as a comment to the last node.
    
    * packages/gnugo/gnugo.el (gnugo-display-final-score):
    ...here, if new prefix arg COMMENT is set, with "territory",
    "captures", "komi" squashed to "T", "C", "K", respectively.
---
 NEWS     |  1 +
 gnugo.el | 22 +++++++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 12ef38d..1b7ab98 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ NB: "RCS: X..Y " means that the particular release includes
   - dropped command: ‘t’ (gnugo-toggle-dead-group)
   - PASS for SZ <= 19 normalized to "" on read, written as ""
   - ‘=’ also displays move number of the stone (if any) at that position
+  - ‘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: ‘C’ (gnugo-comment)
diff --git a/gnugo.el b/gnugo.el
index 632d2bf..fe19d80 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -1985,12 +1985,14 @@ Prefix arg means to redo all the undone moves."
                  (gnugo-refresh)
                  (redisplay)))))))))
 
-(defun gnugo-display-final-score ()
+(defun gnugo-display-final-score (&optional comment)
   "Display final score and other info in another buffer (when game over).
 If the game is still ongoing, Emacs asks if you wish to stop play (by
 making sure two \"pass\" moves are played consecutively, if necessary).
-Also, add the `:RE' SGF property to the root node of the game tree."
-  (interactive)
+Also, add the `:RE' SGF property to the root node of the game tree.
+Prefix arg COMMENT means to also attach the text (slightly compacted)
+to the last move, as a comment."
+  (interactive "P")
   (let ((game-over (gnugo-get :game-over)))
     (unless (or game-over
                 (and (not (gnugo-get :waiting))
@@ -2090,6 +2092,20 @@ Also, add the `:RE' SGF property to the root node of the 
game tree."
           (yep "       end" end))))
     (setq blurb (apply 'concat (nreverse blurb)))
     (gnugo--set-root-prop :RE result)
+    (when comment
+      (let ((node (car (aref (gnugo-get :monkey) 0))))
+        (gnugo--decorate
+         (delq (assq :C node) node)
+         (with-temp-buffer
+           (insert blurb)
+           (cl-flet ((rep (old new)
+                          (goto-char (point-min))
+                          (while (search-forward old nil t)
+                            (replace-match new))))
+             (rep "territory" "T")
+             (rep "captures"  "C")
+             (rep "komi"      "K"))
+           `((:C . ,(buffer-string)))))))
     (switch-to-buffer (format "%s*GNUGO Final Score*" (gnugo-get :diamond)))
     (erase-buffer)
     (insert blurb)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]