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

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

Re: variable tabulated-list-format


From: Jean Louis
Subject: Re: variable tabulated-list-format
Date: Mon, 17 Oct 2022 07:24:19 +0300
User-agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02)

* 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/



reply via email to

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