I'm writing my own mode in Elisp. It's basically a simple crud application showing rows of data which can be manipulated via the minibuffer. I'd like to create a view for these rows which looks like the emacs package manager: columns of data nicely aligned. What's the best way to implement such a view?
The answer from phils got me on track. There are no tutorials or simple examples anywhere though, so I created one. Here is an example of a tabulated-list-mode derivative which has static data and can print the ID of the current column:
(define-derived-mode mymode tabulated-list-mode "mymode" "Major mode My Mode, just a test"
(setq tabulated-list-format [("Col1" 18 t)
("Col2" 12 nil)
("Col3" 10 t)
("Col4" 0 nil)])
(setq tabulated-list-padding 2)
(setq tabulated-list-sort-key (cons "Col3" nil))
(tabulated-list-init-header))
(defun print-current-line-id ()
(interactive)
(message (concat "current line ID is: " (tabulated-list-get-id))))
(defun my-listing-command ()
(interactive)
(pop-to-buffer "*MY MODE*" nil)
(mymode)
(setq tabulated-list-entries (list
(list "1" ["1" "2" "3" "4"])
(list "2" ["a" "b" "c" "d"])))
(tabulated-list-print t))
If you look at the code for the package listing function you mention, you'll see that it employs package-menu-mode
which derives from tabulated-list-mode
.
find-function
RET package-menu-mode
RET
tabulated-list-mode
RET
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With