Emacs tabulated list mode
A simple example of tabulated-list-mode usage in Emacs. For more details see docs
Tabulated list is a major mode, so in order to use it we need to:
- Extend tabulated-list-mode
- Specify tabulated-list-format (Format of the Tabulated List data)
- Specify tabulated-list-revert-hook Optional (Hook run before reverting a Tabulated List buffer. This is commonly used to recompute `tabulated-list-entries’)
- Compute tabulated-list-entries (Entries displayed in the Tabulated List buffer)
- Define tabulated-list-printer (Function called to insert an entry at point, including its terminating newline)
- Specify tabulated-list-padding
- Call tabulated-list-init-header (Function which will populate a header with the names of the columns)
Define major mode:
(define-derived-mode list-demo-mode tabulated-list-mode "list-demo-mode"
"Major mode for tabulated list example."
(setq tabulated-list-format [("Column_1" 10 t)
("Column_2" 10 nil)
("Column_3" 10 t)
("Column_4" 0 nil)]);; last columnt takes what left
(setq tabulated-list-entries (list
(list "1" ["50" "A2" "A3" "A4"])
(list "2" ["10" "B2" "B3" "B4"])
(list "3" ["15" "C2" "C3" "C4"])))
(setq tabulated-list-padding 4)
(setq tabulated-list-sort-key (cons "Column_1" nil))
(tabulated-list-init-header)
(tabulated-list-print t))