branch: externals/yaml commit 01ab8d19100831697c9d20035ce200084682b577 Merge: 34c300b085 b6091cc080 Author: Zachary Romero <zacrom...@posteo.net> Commit: GitHub <nore...@github.com>
Merge pull request #30 from zkry/29-fix-list-encoding-indentation Fix list encoding indentation --- yaml-tests.el | 16 +++++++++++++++- yaml.el | 8 +++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/yaml-tests.el b/yaml-tests.el index 7a3aae569e..6993986b7c 100644 --- a/yaml-tests.el +++ b/yaml-tests.el @@ -540,10 +540,24 @@ keep: |+ (should (equal (yaml-encode [1 2 3]) "[1, 2, 3]")) + (should (equal + (yaml-encode `[((foo . bar) (baz . bax))]) + "\n- foo: bar\n baz: bax")) + (should (equal + (yaml-encode `((deeper . [((foo . bar) (baz . bax))]))) + "\ndeeper: \n- foo: bar\n baz: bax")) (should (yaml-test-round-trip '((build_the_package (script . "if [ -z \"${CUSTOM}\" ]; then ./mvnw package -fi") (stage . "build")))))) +fi") (stage . "build"))))) + (should (yaml-test-round-trip + `((deeper . [((foo . bar) (baz . bax)) + ((foo . bar) (baz . bax) (bee . bop))]) + (lower . [((foo . bar) (baz . bax)) + ((foo . [((foo . bar) (baz . bax)) + ((foo . bar) (baz . bax) (bee . bop))]) + (baz . bax) + (bee . bop))]))))) (provide 'yaml-tests) diff --git a/yaml.el b/yaml.el index 2ed9cf58a6..718e111c97 100644 --- a/yaml.el +++ b/yaml.el @@ -2787,8 +2787,10 @@ auto-detecting the indentation" (cdr l)) (insert "]")) (t - (let ((first t) - (indent-string (make-string (* 2 indent) ?\s))) + (when (zerop indent) + (setq indent 2)) + (let* ((first t) + (indent-string (make-string (- indent 2) ?\s))) (seq-do (lambda (object) (if (not first) @@ -2798,7 +2800,7 @@ auto-detecting the indentation" (insert (make-string (- indent curr-indent) ?\s) "- ")) (insert "\n" indent-string "- ")) (setq first nil)) - (yaml--encode-object object (+ indent 2) + (yaml--encode-object object indent (or (hash-table-p object) (yaml--alist-to-hash-table object))))