[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 02/02: [gnugo int] Add abstraction: gnugo--set-root-prop
From: |
Thien-Thi Nguyen |
Subject: |
[elpa] 02/02: [gnugo int] Add abstraction: gnugo--set-root-prop |
Date: |
Tue, 18 Mar 2014 09:13:41 +0000 |
ttn pushed a commit to branch master
in repository elpa.
commit a12a06d39954c011d7f2580594628b6e30ad09d0
Author: Thien-Thi Nguyen <address@hidden>
Date: Tue Mar 18 10:14:00 2014 +0100
[gnugo int] Add abstraction: gnugo--set-root-prop
* packages/gnugo/gnugo.el (gnugo--set-root-prop): New func.
(gnugo-display-final-score, gnugo/sgf-write-file): Use it.
---
packages/gnugo/gnugo.el | 24 ++++++++++++------------
1 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index 7a3e84a..d92eea5 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/gnugo.el
@@ -373,6 +373,14 @@ when you are sure the command cannot fail."
(defsubst gnugo-treeroot (prop)
(cdr (assq prop (car (gnugo-get :sgf-gametree)))))
+(defun gnugo--set-root-prop (prop value &optional tree)
+ (let* ((root (car (or tree (gnugo-get :sgf-gametree))))
+ (cur (assq prop root)))
+ (if cur
+ (setcdr cur value)
+ (push (cons prop value)
+ (cdr (last root))))))
+
(defun gnugo-goto-pos (pos)
"Move point to board position POS, a letter-number string."
(goto-char (point-min))
@@ -1558,11 +1566,7 @@ Also, add the `:RE' SGF property to the root node of the
game tree."
(yep "Game start" beg)
(yep " end" end))))
(setq blurb (apply 'concat (nreverse blurb)))
- (let* ((root (car (gnugo-get :sgf-gametree)))
- (cur (assq :RE root)))
- (if cur
- (setcdr cur result)
- (setcdr (last root) (list (cons :RE result)))))
+ (gnugo--set-root-prop :RE result)
(switch-to-buffer (format "%s*GNUGO Final Score*" (gnugo-get :diamond)))
(erase-buffer)
(insert blurb)))
@@ -2181,13 +2185,9 @@ starting a new one. See `gnugo-board-mode'
documentation for more info."
(defun gnugo/sgf-write-file (collection filename)
;; take responsibility for our actions
- (dolist (tree collection)
- (let* ((root (car tree))
- (who (assq :AP root))
- (fruit (cons "gnugo.el" gnugo-version)))
- (if who
- (setcdr who fruit)
- (setcdr (last root) (list (cons :AP fruit))))))
+ (let ((me (cons "gnugo.el" gnugo-version)))
+ (dolist (tree collection)
+ (gnugo--set-root-prop :AP me tree)))
;; write it out
(let ((aft-newline-appreciated '(:AP :GN :PB :PW :HA :KM :RU :RE))
(specs (mapcar (lambda (full)