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

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

Re: Format of lists and alists required for displaying lists of tabulate


From: Christopher Dimech
Subject: Re: Format of lists and alists required for displaying lists of tabulated data
Date: Sun, 18 Jun 2023 21:16:01 +0200

> Sent: Monday, June 19, 2023 at 3:31 AM
> From: "Jean Louis" <bugs@gnu.support>
> To: "uzibalqa" <uzibalqa@proton.me>
> Cc: "Bruno Barbier" <brubar.cs@gmail.com>, "uzibalqa via Users list for the 
> GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> Subject: Re: Format of lists and alists required for displaying lists of 
> tabulated data
>
> * uzibalqa <uzibalqa@proton.me> [2023-06-17 16:28]:
> > It would also be handy to have some conversion functions that takes a normal
> > list or alist, and converts them to ones suitable for 
> > tabulated-list-entries.
>
> Those functions would be too much specific, and you can do those functions.
>
> I have functions like these which are using SQL which get expanded into 
> tabulated-list-mode:
>
> (rcd-db-sql-report title sql cf-people-tabulated-format-with-people-list 
> "people" nil refresh-function '(">>>UNKNOWN<<<") return-function)
>
> Or like this: (cf-people-by-id-list (list introducer)) which would show 
> tabulated-list-format by list of people IDs
>
> My SQL has always ID followed by values, so here is the key function that 
> converts it:


The functions could be difficult to use because of the many calls to your 
"rcd-" functions.
Perhaps we can come up with something more adept to users to try.  Using same 
idea of
an ID followed by values.


> (defun rcd-db-sql-report (title sql format table sort-key refresh &optional 
> highlight-list return-function)
>   "Prepare SQL for tabulated list report."
>   (let* ((entries-1 (rcd-sql sql cf-db))
>        (entries-2
>         (mapcar #'(lambda (i)
>                     (list
>                      (elt i 0)
>                      (vconcat
>                       (append (list
>                                (cond ((numberp (elt i 0)) (number-to-string 
> (elt i 0)))
>                                      (t (elt i 0))))
>                               (cdr (append i nil))))))
>                 entries-1)))
>     (cond (entries-1 (rcd-db-report title entries-2 format "pg" 'cf-db table 
> sort-key refresh highlight-list nil nil return-function))
>         (t (rcd-warning-message (format "No entries for report `%s'" 
> title))))))
>
> (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))))
>
> The above workflow shall serve only as example to your own functions.
>
> --
> 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]