Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pervognsen/14379dbcc59a30694192 to your computer and use it in GitHub Desktop.
Save pervognsen/14379dbcc59a30694192 to your computer and use it in GitHub Desktop.
inspector.el
(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