[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 01/01: [gnugo sgf] Fix bug: Add ‘\’-escapes on write.
From: |
Thien-Thi Nguyen |
Subject: |
[elpa] 01/01: [gnugo sgf] Fix bug: Add ‘\’-escapes on write. |
Date: |
Thu, 10 Apr 2014 13:49:43 +0000 |
ttn pushed a commit to branch master
in repository elpa.
commit 2f9b6b08a07d4b79aee30ba2729aa49e47450e33
Author: Thien-Thi Nguyen <address@hidden>
Date: Thu Apr 10 15:51:30 2014 +0200
[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’.
---
packages/gnugo/NEWS | 1 +
packages/gnugo/gnugo.el | 19 ++++++++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/packages/gnugo/NEWS b/packages/gnugo/NEWS
index 8bd3b75..f0148f6 100644
--- a/packages/gnugo/NEWS
+++ b/packages/gnugo/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/packages/gnugo/gnugo.el b/packages/gnugo/gnugo.el
index 66af605..2009034 100644
--- a/packages/gnugo/gnugo.el
+++ b/packages/gnugo/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))