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

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

[elpa] externals/yaml 6d52649383 076/124: Fix list encoding indentation


From: ELPA Syncer
Subject: [elpa] externals/yaml 6d52649383 076/124: Fix list encoding indentation #29
Date: Fri, 29 Nov 2024 16:00:03 -0500 (EST)

branch: externals/yaml
commit 6d52649383e8d80b8744ffb52b1dbe20e6870758
Author: Zachary Romero <zacromero@posteo.net>
Commit: Zachary Romero <zacromero@posteo.net>

    Fix list encoding indentation #29
---
 yaml-tests.el | 6 ++++++
 yaml.el       | 8 +++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/yaml-tests.el b/yaml-tests.el
index 7a3aae569e..739dfec945 100644
--- a/yaml-tests.el
+++ b/yaml-tests.el
@@ -540,6 +540,12 @@ 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
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))))



reply via email to

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