[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/inspector e2e56201a0 01/39: Starting a tree-inspector w
From: |
ELPA Syncer |
Subject: |
[elpa] externals/inspector e2e56201a0 01/39: Starting a tree-inspector with treeview |
Date: |
Sat, 10 Sep 2022 17:57:46 -0400 (EDT) |
branch: externals/inspector
commit e2e56201a096f81f7a8e91ec43128a216f544125
Author: Mariano Montone <marianomontone@gmail.com>
Commit: Mariano Montone <marianomontone@gmail.com>
Starting a tree-inspector with treeview
---
tree-inspector.el | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/tree-inspector.el b/tree-inspector.el
new file mode 100644
index 0000000000..d69389e0b5
--- /dev/null
+++ b/tree-inspector.el
@@ -0,0 +1,85 @@
+(require 'eieio)
+(require 'treeview)
+(require 'mule-util)
+
+;;---- Utils ----------
+
+(defun tree-inspector--princ-to-string (object)
+ "Print OBJECT to string using `princ'."
+ (with-output-to-string
+ (princ object)))
+
+(defun tree-inspector--proper-list-p (val)
+ "Is VAL a proper list?"
+ (if (fboundp 'format-proper-list-p)
+ ;; Emacs stable.
+ (with-no-warnings (format-proper-list-p val))
+ ;; Function was renamed in Emacs master:
+ ;;
http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=2fde6275b69fd113e78243790bf112bbdd2fe2bf
+ (with-no-warnings (proper-list-p val))))
+
+(defun tree-inspector--plistp (list)
+ "Return T if LIST is a property list."
+ (let ((expected t))
+ (and (tree-inspector--proper-list-p list)
+ (cl-evenp (length list))
+ (cl-every (lambda (x)
+ (setq expected (if (eql expected t) 'symbol t))
+ (cl-typep x expected))
+ list))))
+
+(defun tree-inspector--alistp (list)
+ "Return T if LIST is an association list."
+ (and (tree-inspector--proper-list-p list)
+ (cl-every (lambda (x) (consp x)) list)))
+
+(defun tree-inspector--alist-to-plist (alist)
+ "Convert association list ALIST to a property list."
+ (let ((plist))
+ (dolist (cons (reverse alist))
+ (push (cdr cons) plist)
+ (push (car cons) plist))
+ plist))
+
+(cl-defgeneric tree-inspector--make-node (object)
+ (:documentation "Create treeview node for Emacs Lisp OBJECT."))
+
+(cl-defmethod tree-inspector--make-node ((object number))
+ (let ((node (treeview-new-node)))
+ (treeview-set-node-name node (prin1-to-string object))
+ node))
+
+(cl-defmethod tree-inspector--make-node ((object cons))
+ (cond
+ ((tree-inspector--proper-list-p object)
+ (let ((node (treeview-new-node)))
+ (treeview-set-node-name node
+ (truncate-string-to-width (prin1-to-string object)
+ 30 nil nil "..."))
+ (treeview-set-node-children node
+ (mapcar (lambda (item)
+ (let ((child (tree-inspector--make-node item)))
+ (treeview-set-node-parent child node)
+ child))
+ object))))))
+
+(defun tree-inspector-inspect (data)
+ (let ((buffer (get-buffer-create (format "*tree-inspector: %s*" data))))
+ (with-current-buffer buffer
+ ;; (setq-local treeview-get-root-node-function
+ ;; (lambda () (tree-inspector--make-node data)))
+ (setq-local treeview-get-indent-function
+ (lambda (node) (list " ")))
+ (setq-local treeview-get-label-function
+ #'first)
+ (setq-local treeview-get-control-function
+ (lambda (node)
+ (if (treeview-get-node-children node)
+ "[+]"
+ nil)))
+ (treeview-display-node (tree-inspector--make-node data))
+
+ (display-buffer buffer))))
+
+(tree-inspector-inspect 2)
+(tree-inspector-inspect (list 1 2 3))
- [elpa] externals/inspector updated (f04c60a5d3 -> 0b213e931c), ELPA Syncer, 2022/09/10
- [elpa] externals/inspector e2e56201a0 01/39: Starting a tree-inspector with treeview,
ELPA Syncer <=
- [elpa] externals/inspector 06eb60bcff 03/39: tree-inspector: indentation, ELPA Syncer, 2022/09/10
- [elpa] externals/inspector 56579dae8a 05/39: tree-inspector: hash-table inspector, ELPA Syncer, 2022/09/10
- [elpa] externals/inspector 838b08706a 02/39: tree-inspector work, ELPA Syncer, 2022/09/10
- [elpa] externals/inspector faf590dded 06/39: tree-inspector: alist inspector, ELPA Syncer, 2022/09/10
- [elpa] externals/inspector 068b754a0a 07/39: tree-inspector: vectors, ELPA Syncer, 2022/09/10
- [elpa] externals/inspector d43bb09ae9 11/39: tree-inspector: housekeeping, ELPA Syncer, 2022/09/10
- [elpa] externals/inspector 4066d7b441 13/39: Starting some tree-inspector tests, ELPA Syncer, 2022/09/10
- [elpa] externals/inspector 8b000e4e4e 15/39: tree-inspector: tests, ELPA Syncer, 2022/09/10
- [elpa] externals/inspector 130c43c6b6 19/39: tree-inspector: records, ELPA Syncer, 2022/09/10
- [elpa] externals/inspector 394fb22811 09/39: ..., ELPA Syncer, 2022/09/10