branch: externals/inspector commit 130c43c6b6655d4488b1ab61e40a653e6459ce1f Author: Mariano Montone <marianomont...@gmail.com> Commit: Mariano Montone <marianomont...@gmail.com>
tree-inspector: records --- tree-inspector-tests.el | 48 +++++++++++++++++++++++------------------------- tree-inspector.el | 22 +++++++++++++++++++--- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/tree-inspector-tests.el b/tree-inspector-tests.el index 6f9bf8595d..2479f395a0 100644 --- a/tree-inspector-tests.el +++ b/tree-inspector-tests.el @@ -160,38 +160,36 @@ (should (cl-search "44" buffer-string)))) (ert-deftest inspector-tests--inspect-hash-table-test () - (inspector-inspect (let ((table (make-hash-table))) - (puthash :a 22 table) - (puthash :b "foo" table) - table)) - (let ((buffer-string (buffer-string))) - (should (cl-search "hash-table" buffer-string)) - (should (cl-search "a" buffer-string)) - (should (cl-search "22" buffer-string)) - (should (cl-search "b" buffer-string)) - (should (cl-search "foo" buffer-string))) - (inspector-quit)) + (let ((table (make-hash-table))) + (puthash :a 22 table) + (puthash :b "foo" table) + + (tree-inspector-tests--with-tree-inspector-contents + (buffer-string table) + (should (cl-search "hash-table" buffer-string)) + (should (cl-search "a" buffer-string)) + (should (cl-search "22" buffer-string)) + (should (cl-search "b" buffer-string)) + (should (cl-search "foo" buffer-string))))) (ert-deftest inspector-tests--inspect-function-test () - (inspector-inspect (symbol-function 'car)) - (let ((buffer-string (buffer-string))) - (should (cl-search "function" buffer-string)) - (should (cl-search "car" buffer-string))) - (inspector-quit)) + (tree-inspector-tests--with-tree-inspector-contents + (buffer-string (symbol-function 'print)) + (should (cl-search "subr" buffer-string)) + (should (cl-search "print" buffer-string)))) -(defun inspector-tests--factorial (integer) +(defun tree-inspector-tests--factorial (integer) "Compute factorial of INTEGER." (if (= 1 integer) 1 - (* integer (inspector-tests--factorial (1- integer))))) + (* integer (tree-inspector-tests--factorial (1- integer))))) -(ert-deftest inspector-tests--inspect-compiled-function-test () - (inspector-inspect (byte-compile 'inspector-tests--factorial)) - (let ((buffer-string (buffer-string))) - (should (cl-search "function" buffer-string))) - (inspector-quit)) +(ert-deftest tree-inspector-tests--inspect-compiled-function-test () + (tree-inspector-tests--with-tree-inspector-contents + (buffer-string (byte-compile 'inspector-tests--factorial)) + (should (cl-search "factorial" buffer-string)))) -(ert-deftest inspector-tests--inspect-record-test () - (inspector-inspect (record 'foo 23 [bar baz] "rats")) +(ert-deftest tree-inspector-tests--inspect-record-test () + (tree-inspector-inspect (record 'foo 23 [bar baz] "rats")) (let ((buffer-string (buffer-string))) (should (cl-search "record" buffer-string)) (should (cl-search "foo" buffer-string)) diff --git a/tree-inspector.el b/tree-inspector.el index 62e1002d63..f8ae574ee5 100644 --- a/tree-inspector.el +++ b/tree-inspector.el @@ -71,12 +71,12 @@ in a format understood by `kbd'. Commands a names of Lisp functions." :type 'boolean :group 'inspector) -(defcustom tree-inspector-indent-unit " | " +(defcustom tree-inspector-indent-unit " | " "Symbol to indent directories when the parent is not the last child." :group 'tree-inspector :type 'string) -(defcustom tree-inspector-indent-last-unit " " +(defcustom tree-inspector-indent-last-unit " " "Symbol to indent directories when the parent is the last child of its parent." :group 'tree-inspector :type 'string) @@ -221,7 +221,23 @@ in a format understood by `kbd'. Commands a names of Lisp functions." (:documentation "Create treeview node for Emacs Lisp OBJECT.")) (cl-defmethod tree-inspector--make-node ((object t)) - (error "Implement tree-inspector--make-node for %s" (type-of object))) + (cond + ((recordp object) + (let ((node (treeview-new-node))) + (treeview-set-node-name node (tree-inspector--print-object object)) + (let (children) + (cl-do ((i 1 (cl-incf i))) + ((= i (length object))) + (push (tree-inspector--make-node (aref object i)) children)) + (tree-inspector--set-node-children node children) + node))) + (t + (error "Implement tree-inspector--make-node for %s" (type-of object))))) + +(cl-defmethod tree-inspector--make-node ((object subr)) + (let ((node (treeview-new-node))) + (treeview-set-node-name node (prin1-to-string object)) + node)) (cl-defmethod tree-inspector--make-node ((object (eql t))) (let ((node (treeview-new-node)))