From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Format of lists and alists required for displaying lists of tabulated data Date: Sun, 18 Jun 2023 18:31:10 +0300 Message-ID: References: <648d6296.050a0220.f0b55.8bfc@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33871"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.10+64 (b470a9a) (2023-06-05) Cc: Bruno Barbier , uzibalqa via Users list for the GNU Emacs text editor To: uzibalqa Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 18 20:17:11 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qAwxb-0008aj-0I for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 18 Jun 2023 20:17:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qAwwy-0003C8-1J; Sun, 18 Jun 2023 14:16:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAwwt-0003By-B6 for help-gnu-emacs@gnu.org; Sun, 18 Jun 2023 14:16:27 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAwwr-0002r1-Ju for help-gnu-emacs@gnu.org; Sun, 18 Jun 2023 14:16:27 -0400 Original-Received: from localhost ([::ffff:41.75.180.1]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000010385B.00000000648F49D7.00006052; Sun, 18 Jun 2023 11:15:50 -0700 Mail-Followup-To: uzibalqa , Bruno Barbier , uzibalqa via Users list for the GNU Emacs text editor Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143992 Archived-At: * uzibalqa [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: (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/