[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/inspector b3833deecb 33/93: Better symbol inspector
From: |
ELPA Syncer |
Subject: |
[elpa] externals/inspector b3833deecb 33/93: Better symbol inspector |
Date: |
Tue, 24 May 2022 18:57:57 -0400 (EDT) |
branch: externals/inspector
commit b3833deecb36338c053568439c188d00203299e7
Author: Mariano Montone <marianomontone@gmail.com>
Commit: Mariano Montone <marianomontone@gmail.com>
Better symbol inspector
---
inspector.el | 97 ++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 62 insertions(+), 35 deletions(-)
diff --git a/inspector.el b/inspector.el
index b900ff54ad..d27e4367af 100644
--- a/inspector.el
+++ b/inspector.el
@@ -30,6 +30,8 @@
(require 'eieio)
(require 'debug)
+;;---- Utils ----------
+
(defun princ-to-string (object)
"Print OBJECT to string using `princ'."
(with-output-to-string
@@ -59,6 +61,17 @@
(push (car cons) plist))
plist))
+(defun 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))))
+
+;;--- Customization ----------------------------
+
(defgroup inspector nil
"Emacs Lisp inspector customizations."
:group 'lisp)
@@ -88,6 +101,19 @@
"Face for type description in inspector."
:group 'inspector)
+(defcustom inspector-end-column 80
+ "Control print truncation size in inspector."
+ :type 'integer
+ :group 'inspector)
+
+;;-------- Inspector code -------------------
+
+(defvar-local inspector-history nil
+ "The inspector buffer history.")
+
+(defvar-local inspector-inspected-object nil
+ "The current inspected object.")
+
(defun inspector--insert-horizontal-line (&rest width)
"Insert an horizontal line with width WIDTH."
(insert (make-string (or width 80) ?\u2500)))
@@ -107,24 +133,27 @@
(inspector--insert-horizontal-line)
(newline))
-(defun 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))))
-
-(defvar-local inspector-history nil
- "The inspector buffer history.")
+(defun inspector--print-truncated (object &optional end-column)
+ "Print OBJECT truncated. END-COLUMN controls the truncation."
+ (truncate-string-to-width (prin1-to-string object)
+ (or end-column inspector-end-column)
+ nil nil t))
-(defvar-local inspector-inspected-object nil
- "The current inspected object.")
+(defun inspector--insert-inspect-button (object &optional label)
+ "Insert button for inspecting OBJECT.
+If LABEL has a value, then it is used as button label. Otherwise, button
label is the printed representation of OBJECT."
+ (insert-button (or (and label (princ-to-string label))
+ (inspector--print-truncated object))
+ 'action (lambda (btn)
+ (ignore btn)
+ (inspector-inspect object t))
+ 'follow-link t))
(cl-defgeneric inspect-object (object)
"Main generic interface for filling inspector buffers for the different
types of OBJECT.")
+;;--------- Object inspectors ----------------------------------
+
(cl-defmethod inspect-object ((class (subclass eieio-default-superclass)))
(inspector--insert-title (format "%s class" (eieio-class-name class)))
(insert "Direct superclasses: ")
@@ -154,7 +183,19 @@
(insert "Value: nil"))
(cl-defmethod inspect-object ((object symbol))
- (insert (format "Symbol: %s" object)))
+ (inspector--insert-title "Symbol")
+ (inspector--insert-label "Name")
+ (inspector--insert-value (symbol-name object))
+ (newline)
+ (inspector--insert-label "Is bound")
+ (inspector--insert-value (format "%s" (boundp object)))
+ (newline)
+ (inspector--insert-label "Function")
+ (inspector--insert-inspect-button (symbol-function object))
+ (newline)
+ (inspector--insert-label "Property list")
+ (inspector--insert-inspect-button (symbol-plist object))
+ (newline))
(cl-defmethod inspect-object ((object t))
(cond
@@ -184,27 +225,6 @@
(newline)))
(t (error "Cannot inspect object: %s" object))))
-(defcustom inspector-end-column 80
- "Control print truncation size in inspector."
- :type 'integer
- :group 'inspector)
-
-(defun inspector--print-truncated (object &optional end-column)
- "Print OBJECT truncated. END-COLUMN controls the truncation."
- (truncate-string-to-width (prin1-to-string object)
- (or end-column inspector-end-column)
- nil nil t))
-
-(defun inspector--insert-inspect-button (object &optional label)
- "Insert button for inspecting OBJECT.
-If LABEL has a value, then it is used as button label. Otherwise, button
label is the printed representation of OBJECT."
- (insert-button (or (and label (princ-to-string label))
- (inspector--print-truncated object))
- 'action (lambda (btn)
- (ignore btn)
- (inspector-inspect object t))
- 'follow-link t))
-
(cl-defmethod inspect-object ((cons cons))
(cond
((and (inspector--proper-list-p cons) (plistp cons))
@@ -282,6 +302,8 @@ If LABEL has a value, then it is used as button label.
Otherwise, button label
(newline))
hash-table))
+;;--- Buffers ------------------------------
+
(defun inspector-make-inspector-buffer ()
"Create an inspector buffer."
(let ((buffer (get-buffer-create "*inspector*")))
@@ -293,6 +315,9 @@ If LABEL has a value, then it is used as button label.
Otherwise, button label
(make-local-variable '*))
buffer))
+
+;;------ Commands -----------------------------
+
(defun inspect-expression (exp)
"Evaluate and inspect EXP expression."
(interactive (list (read--expression "Eval and inspect: ")))
@@ -339,6 +364,8 @@ When ADD-TO-HISTORY is T, OBJECT is added to inspector
history for navigation pu
(locals (backtrace--locals nframe base)))
(inspector-inspect (alist-to-plist locals))))
+;;--------- Inspector mode ---------------------------------
+
;; Press letter 'i' in debugger backtrace to inspect locals.
(define-key debugger-mode-map (kbd "i") 'debugger-inspect-locals)
- [elpa] externals/inspector f8affefb73 35/93: Major mode for inspector, (continued)
- [elpa] externals/inspector f8affefb73 35/93: Major mode for inspector, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 49c8c75ada 44/93: Fixes to Emacs debug backtrace inspection, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 5b808173cc 52/93: Slice with [more] button, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector bc118aa31a 65/93: Show length of lists, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 094cd26780 78/93: More tests, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 902ffcfdfc 79/93: .gitignore, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector e9b4f2e276 85/93: tests: adjustment, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 8a3d1b8627 88/93: Display some more buffer properties, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 20260fc077 15/93: Clean inspector history on exit, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 3e2e8d3476 31/93: Faces, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector b3833deecb 33/93: Better symbol inspector,
ELPA Syncer <=
- [elpa] externals/inspector 0fa89e3177 41/93: Make customization group for faces, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 143668d367 01/93: First commit, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 8c083d0ae2 45/93: Update README.md, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 182c1de703 46/93: Inspect record types, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector c8b15291cc 57/93: Tweeks for inspector buffer display, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 584ea2b3e3 62/93: README: demo video, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector b4ff75dda1 61/93: Paginate hash-table inspection, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 0304d42ed1 63/93: Bind 'n' and 'p' to forward and backward button for faster navigation, ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 0f444b2b72 64/93: README: navigate buttons with 'n' and 'p', ELPA Syncer, 2022/05/24
- [elpa] externals/inspector 84b0f72a5c 74/93: inspector-tests, ELPA Syncer, 2022/05/24