[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gnugo a35f657 115/357: [gnugo] Support SGF[4] parsing f
From: |
Stefan Monnier |
Subject: |
[elpa] externals/gnugo a35f657 115/357: [gnugo] Support SGF[4] parsing from string data. |
Date: |
Sun, 29 Nov 2020 14:51:02 -0500 (EST) |
branch: externals/gnugo
commit a35f65733002f84ff934af936f9b991c724a7daa
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>
[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.
---
NEWS | 1 +
gnugo.el | 18 +++++++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index 5a4d9d0..e079fb3 100644
--- a/NEWS
+++ b/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/gnugo.el b/gnugo.el
index d061fde..fe8fde6 100644
--- a/gnugo.el
+++ b/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)))))))
- [elpa] externals/gnugo f9668f0 090/357: [gnugo int] Add abstraction: gnugo--blackp, (continued)
- [elpa] externals/gnugo f9668f0 090/357: [gnugo int] Add abstraction: gnugo--blackp, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo c164c40 092/357: [gnugo int] Add abstraction: gnugo--passp, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo bf04735 094/357: [gnugo] Fix bug: Don't misuse SGF prop ‘:EV’ for "resign" state., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo e036fed 096/357: [gnugo] Fix bug: On load, follow mainline through subtrees., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo eaaa7c8 102/357: [gnugo int] Invert gametree IR to hang by the leaves., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo ed11a74 101/357: [gnugo int] Embrace (NODE[...] [SUBTREE...]) IR, for now., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo b7843bf 103/357: [gnugo maint] Move hi-lock hint from NEWS to HACKING; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo ae888ba 105/357: [gnugo] Add command ‘gnugo-oops’ and keybinding., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 2c5e356 107/357: [gnugo maint] Add some debugging aids to HACKING; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo a708759 110/357: [gnugo int] Use ‘cl-labels’ less., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo a35f657 115/357: [gnugo] Support SGF[4] parsing from string data.,
Stefan Monnier <=
- [elpa] externals/gnugo 3d8db48 119/357: [gnugo] Declare dependency on ‘ascii-art-to-unicode’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 4b866c7 127/357: [gnugo int] Avoid lower move-num candidates in déjà-vu search., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 5b51e4f 129/357: [gnugo int] Decruft: Consolidate "breathe in" loops., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo fda0ca5 130/357: [gnugo int] Move precise fanout computation to "breathe in"., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo cbf99df 131/357: [gnugo int] Insert frolic xrep starting w/ the leaves., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 5c87b11 141/357: [gnugo frolic int] Use ‘move-to-column’ more., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo d62412f 144/357: [gnugo int] Add abstraction: gnugo--move-to-bcol, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 4680536 143/357: [gnugo int] Fix bug: Unbreak SGF file output., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 806a2f2 133/357: [gnugo] Add some navigation commands for GNUGO Frolic mode., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo c6795aa 140/357: [gnugo frolic int] Assign ‘pop’ rv to avoid byte-compiler warning., Stefan Monnier, 2020/11/29