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

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

[elpa] externals/tomelr ca9245038a 35/84: fix: Attempt to make tomelr--t


From: ELPA Syncer
Subject: [elpa] externals/tomelr ca9245038a 35/84: fix: Attempt to make tomelr--toml-table-p more robust
Date: Tue, 3 May 2022 09:58:10 -0400 (EDT)

branch: externals/tomelr
commit ca9245038a74f272b246979271cbf2adef09eb89
Author: Kaushal Modi <kaushal.modi@gmail.com>
Commit: Kaushal Modi <kaushal.modi@gmail.com>

    fix: Attempt to make tomelr--toml-table-p more robust
---
 tomelr.el | 41 +++++++++++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/tomelr.el b/tomelr.el
index 99fc776d99..fc504b5a29 100644
--- a/tomelr.el
+++ b/tomelr.el
@@ -250,12 +250,41 @@ Signal `tomelr-key-format' if it cannot be encoded as a 
string."
 
 ;;;; Objects
 (defun tomelr--toml-table-p (object)
-  "Return non-nil if OBJECT can represent a TOML Table."
-  ;; TODO: Need to find a robust way of detecting TOML tables.
-  ;; (message "[tomelr--print-pair DBG] object type = %S" (type-of object))
-  (and (mapp object)
-       (consp object)         ;      object = ((KEY . VAL)) <- cons
-       (consp (car object)))) ;(car object) =  (KEY . VAL)  <- also cons
+  "Return non-nil if OBJECT can represent a TOML Table.
+
+Definition of a TOML Table (TT):
+
+- OBJECT is TT if it is of type ((KEY1 . VAL1) (KEY2 . VAL2) ..)
+- If OBJECT if of type ((SYMBOL . (WHATEVER))), it's possible that
+  OBJECT is a nested TT.  In that case, pass (WHATEVER) to
+  `tomelr--toml-table-p'."
+  (let (tablep)
+    ;; (message "[tomelr--toml-table-p DBG] object = %S, type = %S, mapp = %S, 
length = %d"
+    ;;          object (type-of object) (mapp object) (safe-length object))
+    (when (listp object)
+      ;; (message "[tomelr--toml-table-p DBG] first elem = %S, type = %S"
+      ;;          (car object) (type-of (car object)))
+      (setq tablep
+            (cond
+             ((seq-every-p
+               ;; Ensure that every element in the `object' is a (KEY
+               ;; . VAL) kind of cons.
+               (lambda (elem)
+                 ;; (message "  [tomelr--toml-table-p DBG] elem = %S, type = 
%S"
+                 ;;          elem (type-of elem))
+                 ;; (when (listp elem)
+                 ;;   (message "  [tomelr--toml-table-p DBG] sub-elem 0 = %S, 
type = %S"
+                 ;;            (nth 0 elem) (type-of (nth 0 elem))))
+                 (and (consp elem)
+                      (= 1 (safe-length elem))))
+               object)
+              t)
+             ((and (listp (car object))
+                   (symbolp (car (car object))))
+              (tomelr--toml-table-p (cdr (car object))))
+             (t
+              nil))))
+    tablep))
 
 (defun tomelr--print-pair (key val)
   "Insert TOML representation of KEY - VAL pair at point."



reply via email to

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