branch: externals/inspector commit b10f60c20ddfa7ace6fd2747128c60779aeb0c3f Author: Mariano Montone <marianomont...@gmail.com> Commit: Mariano Montone <marianomont...@gmail.com>
Fontification for each type of object --- inspector.el | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/inspector.el b/inspector.el index 8eebd71177..5dbb51d11f 100644 --- a/inspector.el +++ b/inspector.el @@ -124,6 +124,11 @@ :type 'boolean :group 'inspector) +(defcustom inspector-use-font-lock-faces t + "Use font-lock faces in inspector, instead of button faces." + :type 'boolean + :group 'inspector) + (defcustom inspector-slice-size 100 "Size of sequence slices in inspector." :type 'integer @@ -169,6 +174,29 @@ END-COLUMN controls the truncation." (or end-column inspector-end-column) nil nil t)) +(cl-defgeneric inspector--face-for-object (object) + "Return face to use for OBJECT.") + +(cl-defmethod inspector--face-for-object (object) + "Use builtin face by default for non matching OBJECTs." + (ignore object) + 'inspector-button-face) + +(cl-defmethod inspector--face-for-object ((string string)) + "Inspector face for STRING." + (ignore string) + font-lock-string-face) + +(cl-defmethod inspector--face-for-object ((symbol symbol)) + "Inspector face for SYMBOLs." + (ignore symbol) + font-lock-constant-face) + +(cl-defmethod inspector--face-for-object ((integer integer)) + "Inspector face for INTEGERs." + (ignore integer) + font-lock-constant-face)) + (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. @@ -176,6 +204,9 @@ Otherwise, button label is the printed representation of OBJECT." (insert-button (or (and label (inspector--princ-to-string label)) (inspector--print-truncated object)) :type 'inspector-button + 'face (if inspector-use-font-lock-faces + (inspector--face-for-object object) + inspector-button-face) 'action (lambda (_btn) (inspector-inspect object t)) 'follow-link t)) @@ -210,11 +241,11 @@ slice in buffer." (setq buffer-read-only nil))) 'follow-link t)))))) +;;--------- Object inspectors ---------------------------------- + (cl-defgeneric inspect-object (object) "Render inspector buffer for OBJECT.") -;;--------- Object inspectors ---------------------------------- - (cl-defmethod inspect-object ((class (subclass eieio-default-superclass))) "Render inspector buffer for EIEIO CLASS." (inspector--insert-title (format "%s class" (eieio-class-name class)))