diff --git a/.emacs.d/lisp/package-cl-inspect-mode.el b/.emacs.d/lisp/package-cl-inspect-mode.el new file mode 100644 index 00000000..423d2bc7 --- /dev/null +++ b/.emacs.d/lisp/package-cl-inspect-mode.el @@ -0,0 +1,42 @@ +;; TODO: Name? cl-inspect? clinspect? clidget? eclidget? +;; Actually, make it independent of CL. +;; TODO: Better table abstraction? +;; Maybe https://github.com/kiwanami/emacs-ctable? + +(require 'cl-lib) + +(defun clinspect--tabulated-list-format (header _data) + ;; TODO: Use data to compute the column size. + (apply #'vector (mapcar (lambda (column) + (list column 12 t . nil)) + header))) + +(define-derived-mode clinspect-mode tabulated-list-mode "Clinspect" + "Mode to inspect Common Lisp sequences." + ;; (setq tabulated-list-padding 2) + ;; (setq tabulated-list-sort-key (cons "Size" 'flip)) + ;; (setq tabulated-list-printer #'disk-usage--print-entry) + (add-hook 'tabulated-list-revert-hook 'tabulated-list-init-header nil t)) + +(defvar clinspect-buffer-name "clinspector") + +;; Input: +;; - header: list of strings +;; - ddata: list of list of things. +(defun clinspect (header data &optional name) + "Inspect DATA." + (switch-to-buffer + (generate-new-buffer (format "*%s%s*" clinspect-buffer-name + (if name + (format "<%s>" name) + "")))) + (clinspect-mode) + (setq tabulated-list-entries + (cl-loop for line in data + for index from 1 upto (length header) + collect (list index (apply #'vector (mapcar #'prin1-to-string line))))) + + (setq tabulated-list-format (clinspect--tabulated-list-format header data)) + (tabulated-list-revert)) + +(provide 'clinspect)