Last active
August 29, 2015 14:10
-
-
Save pervognsen/14379dbcc59a30694192 to your computer and use it in GitHub Desktop.
inspector.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'cl) | |
(defvar inspector-id 0) | |
(defvar inspector-keymap | |
(let ((keymap (make-sparse-keymap))) | |
(define-key keymap (kbd "<tab>") | |
(lambda () | |
(interactive) | |
(save-excursion | |
(let ((value (get-text-property (point) 'inspector-value))) | |
(goto-char (field-beginning)) | |
(delete-field) | |
(insert (inspector value)))))) | |
keymap)) | |
(defun subinspector (x) | |
(cond | |
((or (numberp x) (symbolp x) (stringp x)) | |
(prin1-to-string x)) | |
((consp x) | |
(propertize "(...)" | |
'inspector-value x | |
'field (incf inspector-id) | |
'keymap inspector-keymap | |
'front-sticky t | |
'rear-nonsticky t)) | |
(t | |
"<unknown>"))) | |
(defun inspector (x) | |
(if (consp x) | |
(format "(%s . %s)" (subinspector (car x)) (subinspector (cdr x))) | |
(subinspector x))) | |
(defun inspect (x) | |
(interactive "XLisp expression: ") | |
(insert (inspector x))) | |
(provide 'inspector) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment