branch: externals/yaml
commit adb3e52a214a5154267085639f95a3ffae1ec2d3
Merge: 01ab8d1910 c81f87f0fd
Author: Zachary Romero <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #32 from zkry/fix-encoding-deeply-nested-lists
Fix encoding deeply nested lists
---
yaml-tests.el | 6 ++++++
yaml.el | 8 ++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/yaml-tests.el b/yaml-tests.el
index 6993986b7c..9396dd7b32 100644
--- a/yaml-tests.el
+++ b/yaml-tests.el
@@ -546,6 +546,12 @@ keep: |+
(should (equal
(yaml-encode `((deeper . [((foo . bar) (baz . bax))])))
"\ndeeper: \n- foo: bar\n baz: bax"))
+ (should (equal (yaml-parse-string
+ (yaml-encode [1 [2 [3] 2] 1])
+ :object-type 'alist
+ :sequence-type 'array)
+ [1 [2 [3] 2] 1]))
+ (should (yaml-test-round-trip `[1 [2 [[4 4 4] 3 ((a . 1) (b . 2) (c . 3)) 3]
2] 1]))
(should (yaml-test-round-trip
'((build_the_package (script . "if [ -z \"${CUSTOM}\" ]; then
./mvnw package
diff --git a/yaml.el b/yaml.el
index 718e111c97..f0a38eda53 100644
--- a/yaml.el
+++ b/yaml.el
@@ -2800,10 +2800,10 @@ auto-detecting the indentation"
(insert (make-string (- indent curr-indent) ?\s) "-
"))
(insert "\n" indent-string "- "))
(setq first nil))
- (yaml--encode-object object indent
- (or
- (hash-table-p object)
- (yaml--alist-to-hash-table object))))
+ (if (or (hash-table-p object)
+ (yaml--alist-to-hash-table object))
+ (yaml--encode-object object indent t)
+ (yaml--encode-object object (+ indent 2) nil)))
l))))))
(defun yaml--encode-auto-detect-indent ()