[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/inspector 8b1c3d945e 1/2: tree-inspector: fontification
From: |
ELPA Syncer |
Subject: |
[elpa] externals/inspector 8b1c3d945e 1/2: tree-inspector: fontification |
Date: |
Thu, 16 Mar 2023 12:58:31 -0400 (EDT) |
branch: externals/inspector
commit 8b1c3d945ea53003355b278e8806e8b08b6803f5
Author: Mariano Montone <marianomontone@gmail.com>
Commit: Mariano Montone <marianomontone@gmail.com>
tree-inspector: fontification
---
tree-inspector.el | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/tree-inspector.el b/tree-inspector.el
index 74365fe3d7..6d0831c046 100644
--- a/tree-inspector.el
+++ b/tree-inspector.el
@@ -96,6 +96,10 @@ in a format understood by `kbd'. Commands a names of Lisp
functions."
:type 'number
:group 'tree-inspector)
+(defcustom tree-inspector-font-lock t
+ "Toggle syntax highlighting in tree inspector."
+ :type 'boolean
+ :group 'tree-inspector)
;;-------- Utils ----------------------------------------------------------
@@ -145,10 +149,32 @@ in a format understood by `kbd'. Commands a names of
Lisp functions."
;;-------------- treeview functions
--------------------------------------------
+(defvar tree-inspector--fontification-buffer nil)
+
+(defun tree-inspector--get-fontification-buffer ()
+ (or tree-inspector--fontification-buffer
+ (let ((buffer (get-buffer-create "*tree-inspector-fontification*")))
+ (with-current-buffer buffer
+ (emacs-lisp-mode)
+ (setf tree-inspector--fontification-buffer buffer)))))
+
+(defun tree-inspector--fontify-string (string)
+ "Fontify STRING as `font-lock-mode' does in emacs-lisp mode."
+ (with-current-buffer (tree-inspector--get-fontification-buffer)
+ (erase-buffer)
+ (insert string)
+ (let ((font-lock-verbose nil))
+ (font-lock-ensure))
+ ;;(font-lock-fontify-region (point-min) (point-max))
+ (buffer-substring (point-min) (point-max))))
+
(defun tree-inspector--print-object (object)
"Print OBJECT, truncated."
(truncate-string-to-width
- (prin1-to-string object)
+ (if tree-inspector-font-lock
+ (tree-inspector--fontify-string
+ (prin1-to-string object))
+ (prin1-to-string object))
tree-inspector-print-object-truncated-max
nil nil "..."))