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

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

[elpa] 03/07: [gnugo] Support SGF[4] parsing from string data.


From: Thien-Thi Nguyen
Subject: [elpa] 03/07: [gnugo] Support SGF[4] parsing from string data.
Date: Sat, 05 Apr 2014 11:09:29 +0000

ttn pushed a commit to branch master
in repository elpa.

commit 2663701c6c673b6ab8c752cd57bdbe2fc96dca76
Author: Thien-Thi Nguyen <address@hidden>
Date:   Sat Apr 5 10:47:39 2014 +0200

    [gnugo] Support SGF[4] parsing from string data.
    
    * packages/gnugo/gnugo.el
    (gnugo-read-sgf-file): Use ‘gnugo/sgf-create’.
    (gnugo/sgf-create): Rename from ‘gnugo/sgf-read-file’;
    rename 1st arg to FILE-OR-DATA; take optional 2nd arg DATA-P;
    if DATA-P set, arrange to parse FILE-OR-DATA directly.
---
 packages/gnugo/NEWS     |    1 +
 packages/gnugo/gnugo.el |   18 +++++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/packages/gnugo/NEWS b/packages/gnugo/NEWS
index 5a4d9d0..e079fb3 100644
--- a/packages/gnugo/NEWS
+++ b/packages/gnugo/NEWS
@@ -20,6 +20,7 @@ NB: "RCS: X..Y " means that the particular release includes
   - ‘gnugo-move-history’ returns last two moves w/ RSEL ‘two’
   - performance improvements
   - of interest to hackers (see source, BI => backward incompatible)
+    - ‘gnugo/sgf-read-file’ renamed to ‘gnugo/sgf-create’ and enhanced
     - ‘:sgf-gametree’ internal representation inverted (BI)
     - ‘gnugo-magic-undo’ handles SPEC ‘0’
 
diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index d061fde..fe8fde6 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/gnugo.el
@@ -1591,7 +1591,7 @@ If FILENAME already exists, Emacs confirms that you wish 
to overwrite it."
     (user-error "Cannot load a directory (try a filename with extension 
.sgf)"))
   (let (ans play wait samep coll tree)
     ;; problem: requiring GTP `loadsgf' complicates network subproc support;
-    ;; todo: skip it altogether when confident about `gnugo/sgf-read-file'
+    ;; todo: skip it altogether when confident about `gnugo/sgf-create'
     (unless (= ?= (aref (setq ans (gnugo--q "loadsgf %s"
                                             (expand-file-name filename)))
                         0))
@@ -1603,7 +1603,7 @@ If FILENAME already exists, Emacs confirms that you wish 
to overwrite it."
     (unless samep
       (gnugo-put :gnugo-color wait)
       (gnugo-put :user-color play))
-    (setq coll (gnugo/sgf-read-file filename)
+    (setq coll (gnugo/sgf-create filename)
           tree (nth (let ((n (length coll)))
                       ;; This is better:
                       ;; (if (= 1 n)
@@ -2372,8 +2372,13 @@ starting a new one.  See `gnugo-board-mode' 
documentation for more info."
                    ;; Ugh, heuristics for the sake of performance. :-/
                    (1- (length tree))))))
 
-(defun gnugo/sgf-read-file (filename)
-  "Return the collection (list) of gametrees in SGF[4] file FILENAME."
+(defun gnugo/sgf-create (file-or-data &optional data-p)
+  "Return the SGF[4] collection parsed from FILE-OR-DATA.
+FILE-OR-DATA is a file name or SGF[4] data.
+Optional arg DATA-P non-nil means FILE-OR-DATA is
+a string containing SGF[4] data.
+A collection is a list of gametrees."
+  ;; Arg names inspired by `create-image', despite -P being frowned upon.
   (let ((keywords (or (get 'gnugo/sgf-*r4-properties* :keywords)
                       (put 'gnugo/sgf-*r4-properties* :keywords
                            (mapcar (lambda (full)
@@ -2498,7 +2503,10 @@ starting a new one.  See `gnugo-board-mode' 
documentation for more info."
                        (list ls))
                    (seek-into ?\))))))
       (with-temp-buffer
-        (insert-file-contents filename)
+        (if (not data-p)
+            (insert-file-contents file-or-data)
+          (insert file-or-data)
+          (goto-char (point-min)))
         (loop while (morep)
               collect (apply 'vector (TREE nil)))))))
 



reply via email to

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