;; 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) (defvar clinspect-column-max-width 40) (defun clinspect--tabulated-list-format (header entries) (apply #'vector (mapcar (lambda (index) (let ((column (nth index header))) (list column (min clinspect-column-max-width (max (length column) (apply #'max (mapcar (lambda (entry) (length (prin1-to-string (nth index entry)))) entries)))) t ;; (if (numberp (nth index (car data))) ;; (lambda (a b) ;; (< (nth index a) ;; (nth index b))) ;; t) ))) (number-sequence 0 (1- (length 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)