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

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

[elpa] externals/gnugo 7025924 156/357: [gnugo sgf] Fix bug: Add ‘\’-es


From: Stefan Monnier
Subject: [elpa] externals/gnugo 7025924 156/357: [gnugo sgf] Fix bug: Add ‘\’-escapes on write.
Date: Sun, 29 Nov 2020 14:51:11 -0500 (EST)

branch: externals/gnugo
commit 70259248fc5c929a426c295245acae949c23a9d6
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>

    [gnugo sgf] Fix bug: Add ‘\’-escapes on write.
    
    * packages/gnugo/gnugo.el (gnugo/sgf-write-file esc):
    New internal func.
    (gnugo/sgf-write-file >>one)
    (gnugo/sgf-write-file >>two): Use ‘esc’.
---
 NEWS     |  1 +
 gnugo.el | 19 ++++++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 8bd3b75..f0148f6 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ NB: "RCS: X..Y " means that the particular release includes
 
 - next | NOT YET RELEASED
   - bugfixes
+    - on write, use ‘\’ to escape certain chars
     - preserve whitespace for value type ‘text’
     - don't special-case property value type ‘none’
     - handle subtrees on write
diff --git a/gnugo.el b/gnugo.el
index 66af605..2009034 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -2774,10 +2774,23 @@ A collection is a list of gametrees, each a vector of 
four elements:
                                (cdddr full)))
                        gnugo/sgf-*r4-properties*))
         p name v spec)
-    ;; todo: escape special chars for `text' and `simpletext'.
     (cl-labels
-        ((>>one (v) (insert (format "[%s]" v)))
-         (>>two (v) (insert (format "[%s:%s]" (car v) (cdr v))))
+        ((esc (composed fmt arg)
+              (mapconcat (lambda (c)
+                           (case c
+                             ;; ‘?\[’ is not strictly required
+                             ;; but neither is it forbidden.
+                             ((?\[ ?\] ?\\) (format "\\%c" c))
+                             (?: (concat (if composed "\\" "") ":"))
+                             (t (string c))))
+                         (string-to-list (format fmt arg))
+                         ""))
+         (>>one (v) (insert "[" (esc nil "%s" v) "]"))
+         (>>two (v) (insert "["
+                            (esc t "%s" (car v))
+                            ":"
+                            (esc t "%s" (cdr v))
+                            "]"))
          (>>nl () (cond ((memq name aft-newline-appreciated)
                          (insert "\n"))
                         ((< 60 (current-column))



reply via email to

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