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

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

[elpa] 103/255: some setter methods for the sgf backend


From: Eric Schulte
Subject: [elpa] 103/255: some setter methods for the sgf backend
Date: Sun, 16 Mar 2014 01:02:28 +0000

eschulte pushed a commit to branch go
in repository elpa.

commit 29a979ec9d6b5ad9a21d3bcade0ea41386f3f8b7
Author: Eric Schulte <address@hidden>
Date:   Sun May 27 09:52:56 2012 -0600

    some setter methods for the sgf backend
---
 go-sgf.el   |   31 ++++++++++++++++++++++++++-----
 go-trans.el |    2 +-
 go-util.el  |    8 ++++++++
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/go-sgf.el b/go-sgf.el
index fc4975d..6a2b98d 100644
--- a/go-sgf.el
+++ b/go-sgf.el
@@ -65,12 +65,32 @@
 (defmethod current ((sgf sgf))
   (go-sgf-ref (self sgf) (index sgf)))
 
+(defun set-current (sgf new)
+  (setf (go-sgf-ref (self sgf) (index sgf)) new))
+
+(defsetf current set-current)
+
 (defmethod root ((sgf sgf))
   (go-sgf-ref (self sgf) '(0)))
 
-(defmethod go->move ((sgf sgf) move))
+(defun set-root (sgf new)
+  (if (self sgf)
+      (setf (car (self sgf)) new)
+    (setf (self sgf) (list new))))
+
+(defsetf root set-root)
+
+(defmethod go->move ((sgf sgf) move)
+  (if (current sgf)
+      ;; TODO: this overwrites rather than saving alternatives
+      (setf (current sgf) (list move))
+    (rpush (list move) (go-sgf-ref (self sgf) (butlast (index sgf))))))
 
-(defmethod go->board ((sgf sgf) size))
+(defmethod go->size ((sgf sgf) size)
+  (cond
+   ((aget (root sgf)  :S) (setf (cdr (assoc  :S (root sgf))) size))
+   ((aget (root sgf) :SZ) (setf (cdr (assoc :SZ (root sgf))) size))
+   (t                     (push (cons :S size) (root sgf)))))
 
 (defmethod go->resign ((sgf sgf) resign))
 
@@ -78,9 +98,10 @@
   (decf (car (last (index sgf))))
   (alistp (current sgf)))
 
-;; (defmethod go->comment ((sgf sgf) comment)
-;;   ;; TODO: need a setf method for current
-;;   (push (cons :C comment) (current sgf)))
+(defmethod go->comment ((sgf sgf) comment)
+  (if (aget (current sgf) :C)
+      (setf (cdr (assoc :C (current sgf))) comment)
+    (push (cons :C comment) (current sgf))))
 
 (defmethod go<-size ((sgf sgf))
   (or (aget (root sgf) :S)
diff --git a/go-trans.el b/go-trans.el
index b08d50d..f6615d4 100644
--- a/go-trans.el
+++ b/go-trans.el
@@ -38,7 +38,7 @@
 (require 'eieio)
 
 (defgeneric go->move    (back-end move)    "Send MOVE to BACK-END.")
-(defgeneric go->board   (back-end size)    "Send SIZE to BACK-END.")
+(defgeneric go->size    (back-end size)    "Send SIZE to BACK-END.")
 (defgeneric go->resign  (back-end resign)  "Send RESIGN to BACK-END.")
 (defgeneric go->undo    (back-end)         "Tell BACK-END undo the last move.")
 (defgeneric go->comment (back-end comment) "Send COMMENT to BACK-END.")
diff --git a/go-util.el b/go-util.el
index 18ae372..deb5b6a 100644
--- a/go-util.el
+++ b/go-util.el
@@ -28,6 +28,14 @@
 ;;; Code:
 (eval-when-compile (require 'cl))
 
+(defun rcons (x lst)
+  (append lst (list x)))
+
+(defmacro rpush (x place)
+  "Insert X at the back of the list stored in PLACE."
+  (if (symbolp place) (list 'setq place (list 'rcons x place))
+    (list 'callf2 'rcons x place)))
+
 (defun range (a &optional b)
   (block nil
     (let (tmp)



reply via email to

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