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

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

[elpa] 02/02: [gnugo sgf] Fix bug: Output subtrees correctly.


From: Thien-Thi Nguyen
Subject: [elpa] 02/02: [gnugo sgf] Fix bug: Output subtrees correctly.
Date: Fri, 14 Mar 2014 08:02:06 +0000

ttn pushed a commit to branch master
in repository elpa.

commit 6660bd425070bd3049808d5e5900b247cdf56822
Author: Thien-Thi Nguyen <address@hidden>
Date:   Fri Mar 14 09:05:22 2014 +0100

    [gnugo sgf] Fix bug: Output subtrees correctly.
    
    Long-standing -- from inception -- omission.
    
    * packages/gnugo/gnugo.el (gnugo/sgf-write-file >>tree):
    Don't assume all elements of a tree are nodes; instead,
    handle nodes as before, and recurse on trailing subtree elems.
---
 packages/gnugo/NEWS     |    1 +
 packages/gnugo/gnugo.el |   18 ++++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/packages/gnugo/NEWS b/packages/gnugo/NEWS
index fbfec3b..7ca102b 100644
--- a/packages/gnugo/NEWS
+++ b/packages/gnugo/NEWS
@@ -11,6 +11,7 @@ Hint: (highlight-phrase 
"[0-9][.][0-9][.][0-9]+\\|[0-9]+[.][.][0-9]+"
 - next | NOT YET RELEASED
   - bugfixes
     - don't special-case property value type ‘none’
+    - handle subtrees on write
   - new keybinding for ‘gnugo-undo-one-move’: M-u
   - ‘gnugo-undo-one-move’ can optionally switch colors
   - performance improvements
diff --git a/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index 02fe4e3..39531e9 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/gnugo.el
@@ -2155,6 +2155,7 @@ starting a new one.  See `gnugo-board-mode' documentation 
for more info."
                          ;; hmm
                          ;;  ‘append’ => ([NODE...] [SUBTREE...])
                          ;;  ‘cons’   => (([NODE...]) . [SUBTREE...])
+                         ;; see consequent hair in -write-file
                          (append
                           ;; nodes
                           (loop while (seek ?\;)
@@ -2224,8 +2225,21 @@ starting a new one.  See `gnugo-board-mode' 
documentation for more info."
                  (unless (zerop (current-column))
                    (newline))
                  (insert "(")
-                 (dolist (node tree)
-                   (>>node node))
+                 ;; The IR (see "hmm" above) prioritizes space
+                 ;; efficiency; no cost if no subtrees (common case).
+                 ;; The downside, however, is that subtree access
+                 ;; requires this somewhat-funky border search.
+                 (let (x subtrees)
+                   (while (setq x (pop tree))
+                     (if (symbolp (caar x))
+                         (>>node x)
+                       (setq
+                        ;; Add back the first subtree.
+                        subtrees (cons x tree)
+                        ;; Arrange to stop searching.
+                        tree nil)))
+                   (dolist (sub subtrees)
+                     (>>tree sub)))
                  (insert ")")))
       (with-temp-buffer
         (dolist (tree collection)



reply via email to

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