Skip to main content
edited tags
Link
Drew
  • 79.1k
  • 10
  • 123
  • 257
Source Link
lucky1928
  • 1.7k
  • 10
  • 31

elisp - How to dump plist to property value pairs

Below example dump it as a list, but I wish to dump it in property value pairs:

#+BEGIN_SRC elisp :results output
(defun dump-plist(obj level)
  (if (listp obj)
      (dolist (item obj)
        (dump-plist item (1+ level)))
    (progn
      (while (> level 1)
        (princ "  ")
        (setq level (1- level)))
      (princ obj)
      (princ "\n"))))

(defun test()
  (let* ((my-plist (list :a 1 :b 2 :c 3 :more (list 4 5 6))))
    (print my-plist)
    (dump-plist my-plist 0)
    ))

(test)
#+END_SRC

#+RESULTS:
#+begin_example

(:a 1 :b 2 :c 3 :more (4 5 6))
:a
1
:b
2
:c
3
:more
  4
  5
  6
#+end_example

expected output is:

:a 1
:b 2
:c 3
:more (4 5 6)