branch: externals/tomelr commit a7b3a5703729682e88d6352932e235cbe04deb28 Author: Kaushal Modi <kaushal.m...@gmail.com> Commit: Kaushal Modi <kaushal.m...@gmail.com>
feat: Make a very basic nested array of TTA work --- test/ttable-array.el | 37 +++++++++++++++++++++++++++++++++++++ tomelr.el | 15 ++++++++++----- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/test/ttable-array.el b/test/ttable-array.el index 37392ba28d..5d1b2c4333 100644 --- a/test/ttable-array.el +++ b/test/ttable-array.el @@ -62,5 +62,42 @@ See [org#Drawers](https://www.gnu.org/software/emacs/manual/html_mono/org.html#D (push (tomelr-encode el) out)) (should (equal ref (nreverse out))))) +;;;; Nested array of tables +(ert-deftest test-nested-array-of-tables () + (let ((inp '( + ((fruits . (((varieties . (((name . "red delicious")) + ((name . "granny smith")))))))) + ;; ((fruits . (((name . "apple") + ;; (physical . ((color . "red") + ;; (shape . "round"))) + ;; (varieties . (((name . "red delicious")) + ;; ((name . "granny smith"))))) + ;; ((name . "banana") + ;; (varieties . (((name . "plantain")))))))) + )) + (ref '("[[fruits]] + [[fruits.varieties]] + name = \"red delicious\" + [[fruits.varieties]] + name = \"granny smith\"" + ;; "[[fruits]] + ;; name = \"apple\" + ;; [fruits.physical] + ;; color = \"red\" + ;; shape = \"round\" + ;; [[fruits.varieties]] + ;; name = \"red delicious\" + ;; [[fruits.varieties]] + ;; name = \"granny smith\" + ;; [[fruits]] + ;; name = \"banana\" + ;; [[fruits.varieties]] + ;; name = \"plantain\"" + )) + out) + (dolist (el inp) + (push (tomelr-encode el) out)) + (should (equal ref (nreverse out))))) + (provide 'ttable-array) diff --git a/tomelr.el b/tomelr.el index f61c10db9d..fc5bdc72a9 100644 --- a/tomelr.el +++ b/tomelr.el @@ -54,7 +54,9 @@ ordered alphabetically.") Dictates repetitions of `tomelr-encoding-default-indentation'.") (defvar tomelr--print-table-hierarchy () - "Internal variable used to save the TOML Table hierarchy.") + "Internal variable used to save TOML Table hierarchies. +This variable is used for both TOML Tables and Arrays of TOML +Tables.") (defvar tomelr--print-table-array-key "" "Internal variable used to save the TOML Table Array name.") @@ -219,8 +221,7 @@ Return nil if OBJECT cannot be encoded as a TOML string." (string-trim-left (symbol-name object) ":")) ((symbolp object) (symbol-name object))))) - (cond - ((equal type 'table) + (when type ;; (message "[tomelr--print-stringlike DBG] %S is symbol, type = %S, depth = %d" ;; object type tomelr--print-indentation-depth) (if (null (nth tomelr--print-indentation-depth tomelr--print-table-hierarchy)) @@ -236,9 +237,12 @@ Return nil if OBJECT cannot be encoded as a TOML string." sym-name)) ;; (message "[tomelr--print-stringlike DBG] table hier: %S" ;; tomelr--print-table-hierarchy) + ) + (cond + ((equal type 'table) (princ (format "[%s]" (string-join tomelr--print-table-hierarchy ".")))) ((equal type 'table-array) - (let ((tta-name (format "[[%s]]" sym-name))) + (let ((tta-name (format "[[%s]]" (string-join tomelr--print-table-hierarchy ".")))) (setq tomelr--print-table-array-key tta-name) (princ tta-name))) ((stringp object) @@ -417,7 +421,8 @@ See `tomelr-encode-array' that returns the same as a string." (mapc (lambda (elt) (if first (setq first nil) - (insert (format "\n%s" tomelr--print-table-array-key))) + (tomelr--print-indentation) + (insert tomelr--print-table-array-key)) (tomelr--print elt)) array)))) (t