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: variable tabulated-list-format Date: Mon, 17 Oct 2022 07:24:19 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38173"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02) Cc: help-gnu-emacs@gnu.org To: John Haman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 17 06:25:19 2022 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 1okHgl-0009l5-76 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 17 Oct 2022 06:25:19 +0200 Original-Received: from localhost ([::1]:38082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okHgj-0005Th-Nk for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 17 Oct 2022 00:25:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okHg8-0005TQ-SF for help-gnu-emacs@gnu.org; Mon, 17 Oct 2022 00:24:40 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:53733) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okHg3-00072u-AV for help-gnu-emacs@gnu.org; Mon, 17 Oct 2022 00:24:40 -0400 Original-Received: from localhost ([::ffff:102.87.19.13]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000561CF.00000000634CD901.00007094; Sun, 16 Oct 2022 21:24:33 -0700 Mail-Followup-To: John Haman , help-gnu-emacs@gnu.org 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 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" Xref: news.gmane.io gmane.emacs.help:140060 Archived-At: * John Haman [2022-10-17 01:43]: > Looking at the docs for tabulated-list-mode (https://www.gnu.org/software/emacs/manual/html_node/elisp/Tabulated-List-Mode.html), > it looks like usage requires that my derived-mode specify the column names > and meta-data (tabulated-lis-format) in my definition of the derived mode. I spread SQL data into tabulated-list-mode: (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)))))) Sample call looks as following: (rcd-db-sql-report "Sample" "SELECT actives_id, actives_name FROM actives" [("ID" 5 t) ("Name" 10 t)] "actives" nil nil) That generates following: ((2 ["2" "Inactive"]) (1 ["1" "Active"])) I like to see the ID number, but it need not be shown. To do something on the entry you use (tabulated-list-get-id) or (tabulated-list-get-entry) To generate data for tabulated-list-entries you have to use the structure as above, each entry is list, first element is ID and other element is vector. Entries displayed in the current Tabulated List buffer. This should be either a function, or a list. If a list, each element has the form (ID [DESC1 ... DESCN]), where: - ID is nil, or a Lisp object uniquely identifying this entry, which is used to keep the cursor on the "same" entry when rearranging the list. Comparison is done with ‘equal’. - Each DESC is a column descriptor, one for each column specified in ‘tabulated-list-format’. The descriptor DESC is one of: - A string, which is printed as-is, and must not contain any newlines. - An image descriptor (a list), which is used to insert an image (see Info node ‘(elisp) Image Descriptors’). - A list (LABEL . PROPS), which means to use ‘insert-text-button’ to insert a text button with label LABEL and button properties PROPS. LABEL must not contain any newlines. If ‘tabulated-list-entries’ is a function, it is called with no arguments and must return a list of the above form. Automatically becomes permanently buffer-local when set. Probably introduced at or before Emacs version 29.1. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/