I want to print an alist in a specific named buffer, which I have to create if it does not exist. either by tabulated-list-format
or using table-contents
. How can I adapt these two functions to print an alist
in a specified named buffer ?
(defun print-alist (alist)
(let ((buffer (get-buffer-create "*Messages*")))
(with-current-buffer buffer
(setq tabulated-list-format
[("Key" 20 t)
("Value" 20 t)])
(setq tabulated-list-sort-key (cons "Key" nil))
(setq tabulated-list-entries
(mapcar (lambda (pair)
(list (car pair) (cdr pair)))
alist))
(tabulated-list-init-header)
(tabulated-list-print))
(display-buffer buffer)))
(defun print-alist2 (alist)
(let ((table-format '("%-20s %-20s\n"))
(table-contents (mapcar (lambda (pair)
(list (car pair) (cdr pair)))
alist)))
(message (apply 'format table-format
(cons '("Key" "Value") table-contents)))))