all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: John Haman <mail@johnhaman.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: variable tabulated-list-format
Date: Mon, 17 Oct 2022 07:24:19 +0300	[thread overview]
Message-ID: <Y0zY83Muix347RQZ@protected.localdomain> (raw)
In-Reply-To: <tii1bs$tln$1@ciao.gmane.io>

* John Haman <mail@johnhaman.org> [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/



      parent reply	other threads:[~2022-10-17  4:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-16 22:42 variable tabulated-list-format John Haman
2022-10-17  4:17 ` Jean Louis
2022-10-17 18:42   ` John Haman
2022-10-18  1:01   ` John Haman
2022-10-17  4:24 ` Jean Louis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y0zY83Muix347RQZ@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mail@johnhaman.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.