Skip to content

Commit

Permalink
refactor: Use append instead of push+reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushalmodi committed May 11, 2022
1 parent 19d128f commit 7f331a8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tomelr.el
Expand Up @@ -283,24 +283,23 @@ Return nil if OBJECT cannot be encoded as a TOML string."
;; (message "[tomelr--print-stringlike DBG] %S is symbol, type = %S, depth = %d"
;; object key-type tomelr--print-indentation-depth)
(if (null (nth tomelr--print-indentation-depth tomelr--print-table-hierarchy))
(progn
(push str tomelr--print-table-hierarchy))
(setq tomelr--print-table-hierarchy
(append tomelr--print-table-hierarchy (list str)))

;; Throw away table keys collected at higher depths, if
;; any, from earlier runs of this function.
(setq tomelr--print-table-hierarchy
(reverse (seq-take (reverse tomelr--print-table-hierarchy)
(1+ tomelr--print-indentation-depth))))
(setf (nth 0 tomelr--print-table-hierarchy) str))
(seq-take tomelr--print-table-hierarchy (1+ tomelr--print-indentation-depth)))
(setf (nth tomelr--print-indentation-depth tomelr--print-table-hierarchy) str))
;; (message "[tomelr--print-stringlike DBG] table hier: %S" tomelr--print-table-hierarchy)
)
(cond
;; TT keys
((equal key-type 'table-key)
(princ (format "[%s]" (string-join (reverse tomelr--print-table-hierarchy) "."))))
(princ (format "[%s]" (string-join tomelr--print-table-hierarchy "."))))
;; TTA keys
((equal key-type 'table-array-key)
(princ (format "[[%s]]" (string-join (reverse tomelr--print-table-hierarchy) "."))))
(princ (format "[[%s]]" (string-join tomelr--print-table-hierarchy "."))))
;; Normal keys (Alist and Plist keys)
((equal key-type 'normal-key)
(princ str))
Expand Down Expand Up @@ -426,11 +425,11 @@ Definition of a TOML Table Array (TTA):
;; Throw away table keys collected at higher depths, if
;; any, from earlier runs of this function.
(setq tomelr--print-table-hierarchy
(reverse (seq-take (reverse tomelr--print-table-hierarchy)
(1+ tomelr--print-indentation-depth))))
(seq-take tomelr--print-table-hierarchy (1+ tomelr--print-indentation-depth)))

(tomelr--print-indentation)
(insert
(format "[[%s]]" (string-join (reverse tomelr--print-table-hierarchy) "."))))
(format "[[%s]]" (string-join tomelr--print-table-hierarchy "."))))

(defun tomelr--print-array (array)
"Insert a TOML representation of ARRAY at point."
Expand Down

0 comments on commit 7f331a8

Please sign in to comment.