help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing a header with tabulated-list-mode


From: Jean Louis
Subject: Re: Printing a header with tabulated-list-mode
Date: Sat, 24 Jun 2023 22:03:05 +0300
User-agent: Mutt/2.2.10+64 (b470a9a) (2023-06-05)

* Heime <heimeborgia@protonmail.com> [2023-06-15 13:21]:
> 
> I want to print an alist with a header using tabulated-list-print
> 
> (setq foo '((a . ["a1" "a2"]) (b . ["bb1" "bb2"]) (c . ["ccc1" "ccc2"])))
> (tlprint-alist foo)
> 
> But the header is not being displayed.
> 
> (defun tlprint-alist (alist &optional outbufr keytl valtl)
>   "Print an associated list via `tabulated-list-print'."
> 
>   (let*
>       ( (bufr (or outbufr (get-buffer-create "*Alist*")))
>         (keytl (or keytl "Key Title"))
>         (valtl (or valtl "Value Title")) )
> 
>     (with-current-buffer bufr
>       (tabulated-list-mode)
>       (setq tabulated-list-format
>              (vector (list keytl 20 t) (list valtl 20 t)))
>       (setq tabulated-list-sort-key (cons keytl nil))
>       (setq tabulated-list-entries
>             (mapcar (lambda (pair)
>                       (list (car pair) (cdr pair)))
>                     alist))
>       (tabulated-list-init-header)
>       (tabulated-list-print) )))

This is my main function using tabulated-list-mode, if you can get anything 
from it:

(defun rcd-db-report (title entries format database-type db-handle table 
sort-key 
                            &optional refresh highlight-list place id 
return-function)
  "RCD database report.

TITLE is buffer name."
  (setq rcd-db-current-database-type database-type)
  (let* ((buffer (generate-new-buffer-name (rcd-notes-name title))))
    (let* ((buffer (get-buffer-create buffer))
           (mode-map (rcd-db-table-mode-map table)))
      (cond ((string-equal table "edit") (switch-to-buffer buffer))
            (rcd-dont-switch-windows (switch-to-buffer buffer))
            (t (switch-to-buffer-other-window buffer)))
      (setq tabulated-list-format format)
      (setq tabulated-list-entries entries)
      (setq rcd-db-edited-table table)
      (setq rcd-db-current-database-type database-type)
      (setq rcd-tabulated-refresh-function refresh)
      (setq rcd-current-return-function return-function)
      (rcd-db-list-mode)
      (use-local-map mode-map)
      (setq rcd-tabulated-marked-items nil)
      (setq rcd-db-current-database-handle db-handle)
      (setq rcd-db-current-table (or (alist-get "table" place nil nil 'equal) 
table))
      (setq rcd-db-current-table-id id)
      (setq tabulated-list-padding 1)
      (tabulated-list-init-header))
    (setq tabulated-list-sort-key sort-key)
    (tabulated-list-print t)
    (when highlight-list
      (rcd-highlight-list highlight-list))))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]