all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Format of lists and alists required for displaying lists of tabulated data
@ 2023-06-16 21:08 uzibalqa
  2023-06-17  7:36 ` Bruno Barbier
  0 siblings, 1 reply; 18+ messages in thread
From: uzibalqa @ 2023-06-16 21:08 UTC (permalink / raw)
  To: uzibalqa via Users list for the GNU Emacs text editor



The file tabulated-list.el does not describe the format of lists and alists
required for displaying lists of tabulated data.

Could some information be added, please ?



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-16 21:08 Format of lists and alists required for displaying lists of tabulated data uzibalqa
@ 2023-06-17  7:36 ` Bruno Barbier
  2023-06-17 12:33   ` uzibalqa
  0 siblings, 1 reply; 18+ messages in thread
From: Bruno Barbier @ 2023-06-17  7:36 UTC (permalink / raw)
  To: uzibalqa, uzibalqa via Users list for the GNU Emacs text editor

uzibalqa <uzibalqa@proton.me> writes:

> The file tabulated-list.el does not describe the format of lists and alists
> required for displaying lists of tabulated data.
>
> Could some information be added, please ?

The documentation of 'tabulated-list-mode'
    (describe-function 'tabulated-list-mode)

points to the documentation of 'tabulated-list-format' and the
documentation of 'tabulated-list-entries'.

Is that what you're looking for ?


Bruno





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-17  7:36 ` Bruno Barbier
@ 2023-06-17 12:33   ` uzibalqa
  2023-06-17 20:54     ` Tim Landscheidt
  2023-06-18 15:31     ` Jean Louis
  0 siblings, 2 replies; 18+ messages in thread
From: uzibalqa @ 2023-06-17 12:33 UTC (permalink / raw)
  To: Bruno Barbier; +Cc: uzibalqa via Users list for the GNU Emacs text editor


------- Original Message -------
On Saturday, June 17th, 2023 at 7:36 PM, Bruno Barbier <brubar.cs@gmail.com> wrote:


> uzibalqa uzibalqa@proton.me writes:
> 
> > The file tabulated-list.el does not describe the format of lists and alists
> > required for displaying lists of tabulated data.
> > 
> > Could some information be added, please ?
> 
> 
> The documentation of 'tabulated-list-mode'
> (describe-function 'tabulated-list-mode)
> 
> points to the documentation of 'tabulated-list-format' and the
> documentation of 'tabulated-list-entries'.
> 
> Is that what you're looking for ?
> 
> Bruno

Yes, the description of tabulated-list-entries states that the input
if a list, each element has the form (ID [DESC1 ... DESCN]).

Perhaps things can be made clearer and more readily available.  Because
it is important for people to know the exact data input format required.

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.





^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-17 12:33   ` uzibalqa
@ 2023-06-17 20:54     ` Tim Landscheidt
  2023-06-18 10:36       ` uzibalqa
  2023-06-18 15:31     ` Jean Louis
  1 sibling, 1 reply; 18+ messages in thread
From: Tim Landscheidt @ 2023-06-17 20:54 UTC (permalink / raw)
  To: uzibalqa; +Cc: Bruno Barbier, help-gnu-emacs

uzibalqa <uzibalqa@proton.me> wrote:

>> > The file tabulated-list.el does not describe the format of lists and alists
>> > required for displaying lists of tabulated data.
>> >
>> > Could some information be added, please ?

>> The documentation of 'tabulated-list-mode'
>> (describe-function 'tabulated-list-mode)

>> points to the documentation of 'tabulated-list-format' and the
>> documentation of 'tabulated-list-entries'.

>> Is that what you're looking for ?

> Yes, the description of tabulated-list-entries states that the input
> if a list, each element has the form (ID [DESC1 ... DESCN]).

> […]

Not only that, but it also explains what ID is and what DESC
can be and what effects it has.  So what data have you set
tabulated-list-entries to and how does it fail to do what
you want?

Tim



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-17 20:54     ` Tim Landscheidt
@ 2023-06-18 10:36       ` uzibalqa
  2023-06-18 11:29         ` Tim Landscheidt
  0 siblings, 1 reply; 18+ messages in thread
From: uzibalqa @ 2023-06-18 10:36 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: Bruno Barbier, help-gnu-emacs




------- Original Message -------
On Sunday, June 18th, 2023 at 8:54 AM, Tim Landscheidt <tim@tim-landscheidt.de> wrote:


> uzibalqa uzibalqa@proton.me wrote:
> 
> > > > The file tabulated-list.el does not describe the format of lists and alists
> > > > required for displaying lists of tabulated data.
> > > > 
> > > > Could some information be added, please ?
> 
> > > The documentation of 'tabulated-list-mode'
> > > (describe-function 'tabulated-list-mode)
> 
> > > points to the documentation of 'tabulated-list-format' and the
> > > documentation of 'tabulated-list-entries'.
> 
> > > Is that what you're looking for ?
> 
> > Yes, the description of tabulated-list-entries states that the input
> > if a list, each element has the form (ID [DESC1 ... DESCN]).
> 
> > […]
> 
> 
> Not only that, but it also explains what ID is and what DESC
> can be and what effects it has. So what data have you set
> tabulated-list-entries to and how does it fail to do what
> you want?
> 
> Tim

I am trying to print a header and also some text to the buffer, and
not being successful.



(defun tlprint-alist (alist &optional outbufr keytl valtl)
  "Print an associated list via `tabulated-list-print'."

  (let*
      ( (bufr (or outbufr (get-buffer-create "*Alist2*")))
        (keytl (or keytl "Key Title"))
        (valtl (or valtl "Value Title")) )

    (with-current-buffer bufr
      (tabulated-list-mode)
      (setq buffer-read-only nil)
      (setq tabulated-list-format
             (vector (list keytl 20 t) (list valtl 20 t)))
      (setq tabulated-list-sort-key (cons keytl nil))
      (setq tabulated-list-entries
            (mapcar (lambda (dyad)
                      (list (car dyad) (cdr dyad)))
                    alist))
      (tabulated-list-init-header)
      (insert keytl valtl "\n")
      (insert "TEST \n")
      (princ "Text to be written" (current-buffer))
      (tabulated-list-print) )))

(setq foo '((a . ["aa1" "aa2"]) (b . ["bb1" "bb2"]) (c . ["cc1" "cc2"])))
(tlprint-alist foo)




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-18 10:36       ` uzibalqa
@ 2023-06-18 11:29         ` Tim Landscheidt
  2023-06-18 13:20           ` uzibalqa
  2023-06-18 13:37           ` uzibalqa
  0 siblings, 2 replies; 18+ messages in thread
From: Tim Landscheidt @ 2023-06-18 11:29 UTC (permalink / raw)
  To: uzibalqa; +Cc: Bruno Barbier, help-gnu-emacs

uzibalqa <uzibalqa@proton.me> wrote:

>> > > > The file tabulated-list.el does not describe the format of lists and alists
>> > > > required for displaying lists of tabulated data.
>> > > >
>> > > > Could some information be added, please ?

>> > > The documentation of 'tabulated-list-mode'
>> > > (describe-function 'tabulated-list-mode)

>> > > points to the documentation of 'tabulated-list-format' and the
>> > > documentation of 'tabulated-list-entries'.

>> > > Is that what you're looking for ?

>> > Yes, the description of tabulated-list-entries states that the input
>> > if a list, each element has the form (ID [DESC1 ... DESCN]).

>> > […]

>> Not only that, but it also explains what ID is and what DESC
>> can be and what effects it has. So what data have you set
>> tabulated-list-entries to and how does it fail to do what
>> you want?

> I am trying to print a header and also some text to the buffer, and
> not being successful.

> […]

That is not the purpose of tabulated-list-mode and will
likely not work.  tabulated-list-mode is for buffers that
display an interactive table (and nothing else), like
list-packages, etc.

http://rgrinberg.com/posts/emacs-table-display/ has some
code to show how it can be used without defining a derived
mode (and how to populate tabulated-list-entries).

Tim



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-18 11:29         ` Tim Landscheidt
@ 2023-06-18 13:20           ` uzibalqa
  2023-06-18 13:37           ` uzibalqa
  1 sibling, 0 replies; 18+ messages in thread
From: uzibalqa @ 2023-06-18 13:20 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: Bruno Barbier, help-gnu-emacs


------- Original Message -------
On Sunday, June 18th, 2023 at 11:29 PM, Tim Landscheidt <tim@tim-landscheidt.de> wrote:


> uzibalqa uzibalqa@proton.me wrote:
> 
> > > > > > The file tabulated-list.el does not describe the format of lists and alists
> > > > > > required for displaying lists of tabulated data.
> > > > > > 
> > > > > > Could some information be added, please ?
> 
> > > > > The documentation of 'tabulated-list-mode'
> > > > > (describe-function 'tabulated-list-mode)
> 
> > > > > points to the documentation of 'tabulated-list-format' and the
> > > > > documentation of 'tabulated-list-entries'.
> 
> > > > > Is that what you're looking for ?
> 
> > > > Yes, the description of tabulated-list-entries states that the input
> > > > if a list, each element has the form (ID [DESC1 ... DESCN]).
> 
> > > > […]
> 
> > > Not only that, but it also explains what ID is and what DESC
> > > can be and what effects it has. So what data have you set
> > > tabulated-list-entries to and how does it fail to do what
> > > you want?
> 
> > I am trying to print a header and also some text to the buffer, and
> > not being successful.
> 
> > […]
> 
> 
> That is not the purpose of tabulated-list-mode and will
> likely not work. tabulated-list-mode is for buffers that
> display an interactive table (and nothing else), like
> list-packages, etc.
> 
> http://rgrinberg.com/posts/emacs-table-display/ has some
> code to show how it can be used without defining a derived
> mode (and how to populate tabulated-list-entries).
> 
> Tim

So only a table ? Just a single table ?  It should also be able to print
a header I think.  Are there any other routines to print a table in a buffer.

I find the table implementation is quite limited.




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-18 11:29         ` Tim Landscheidt
  2023-06-18 13:20           ` uzibalqa
@ 2023-06-18 13:37           ` uzibalqa
  2023-06-18 13:51             ` uzibalqa
  1 sibling, 1 reply; 18+ messages in thread
From: uzibalqa @ 2023-06-18 13:37 UTC (permalink / raw)
  To: Tim Landscheidt; +Cc: Bruno Barbier, help-gnu-emacs

------- Original Message -------
On Sunday, June 18th, 2023 at 11:29 PM, Tim Landscheidt <tim@tim-landscheidt.de> wrote:


> uzibalqa uzibalqa@proton.me wrote:
> 
> > > > > > The file tabulated-list.el does not describe the format of lists and alists
> > > > > > required for displaying lists of tabulated data.
> > > > > > 
> > > > > > Could some information be added, please ?
> 
> > > > > The documentation of 'tabulated-list-mode'
> > > > > (describe-function 'tabulated-list-mode)
> 
> > > > > points to the documentation of 'tabulated-list-format' and the
> > > > > documentation of 'tabulated-list-entries'.
> 
> > > > > Is that what you're looking for ?
> 
> > > > Yes, the description of tabulated-list-entries states that the input
> > > > if a list, each element has the form (ID [DESC1 ... DESCN]).
> 
> > > > […]
> 
> > > Not only that, but it also explains what ID is and what DESC
> > > can be and what effects it has. So what data have you set
> > > tabulated-list-entries to and how does it fail to do what
> > > you want?
> 
> > I am trying to print a header and also some text to the buffer, and
> > not being successful.
> 
> > […]
> 
> 
> That is not the purpose of tabulated-list-mode and will
> likely not work. tabulated-list-mode is for buffers that
> display an interactive table (and nothing else), like
> list-packages, etc.
> 
> http://rgrinberg.com/posts/emacs-table-display/ has some
> code to show how it can be used without defining a derived
> mode (and how to populate tabulated-list-entries).
> 
> Tim

There are some problems with that code such as the use of -reduce-from



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-18 13:37           ` uzibalqa
@ 2023-06-18 13:51             ` uzibalqa
  0 siblings, 0 replies; 18+ messages in thread
From: uzibalqa @ 2023-06-18 13:51 UTC (permalink / raw)
  To: uzibalqa; +Cc: Tim Landscheidt, Bruno Barbier, help-gnu-emacs






Sent with Proton Mail secure email.

------- Original Message -------
On Monday, June 19th, 2023 at 1:37 AM, uzibalqa <uzibalqa@proton.me> wrote:


> ------- Original Message -------
> On Sunday, June 18th, 2023 at 11:29 PM, Tim Landscheidt tim@tim-landscheidt.de wrote:
> 
> 
> 
> > uzibalqa uzibalqa@proton.me wrote:
> > 
> > > > > > > The file tabulated-list.el does not describe the format of lists and alists
> > > > > > > required for displaying lists of tabulated data.
> > > > > > > 
> > > > > > > Could some information be added, please ?
> > 
> > > > > > The documentation of 'tabulated-list-mode'
> > > > > > (describe-function 'tabulated-list-mode)
> > 
> > > > > > points to the documentation of 'tabulated-list-format' and the
> > > > > > documentation of 'tabulated-list-entries'.
> > 
> > > > > > Is that what you're looking for ?
> > 
> > > > > Yes, the description of tabulated-list-entries states that the input
> > > > > if a list, each element has the form (ID [DESC1 ... DESCN]).
> > 
> > > > > […]
> > 
> > > > Not only that, but it also explains what ID is and what DESC
> > > > can be and what effects it has. So what data have you set
> > > > tabulated-list-entries to and how does it fail to do what
> > > > you want?
> > 
> > > I am trying to print a header and also some text to the buffer, and
> > > not being successful.
> > 
> > > […]
> > 
> > That is not the purpose of tabulated-list-mode and will
> > likely not work. tabulated-list-mode is for buffers that
> > display an interactive table (and nothing else), like
> > list-packages, etc.
> > 
> > http://rgrinberg.com/posts/emacs-table-display/ has some
> > code to show how it can be used without defining a derived
> > mode (and how to populate tabulated-list-entries).
> > 
> > Tim
> 
> 
> There are some problems with that code such as the use of -reduce-from

And forces dash and popwin which I don't like.  Could you help me write something similar
but with only standard calls without dependencies?



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-17 12:33   ` uzibalqa
  2023-06-17 20:54     ` Tim Landscheidt
@ 2023-06-18 15:31     ` Jean Louis
  2023-06-18 19:11       ` uzibalqa
  2023-06-18 19:16       ` Christopher Dimech
  1 sibling, 2 replies; 18+ messages in thread
From: Jean Louis @ 2023-06-18 15:31 UTC (permalink / raw)
  To: uzibalqa
  Cc: Bruno Barbier,
	uzibalqa via Users list for the GNU Emacs text editor

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

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



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-18 15:31     ` Jean Louis
@ 2023-06-18 19:11       ` uzibalqa
  2023-06-19 18:46         ` Jean Louis
  2023-06-18 19:16       ` Christopher Dimech
  1 sibling, 1 reply; 18+ messages in thread
From: uzibalqa @ 2023-06-18 19:11 UTC (permalink / raw)
  To: Jean Louis
  Cc: Bruno Barbier,
	uzibalqa via Users list for the GNU Emacs text editor

------- Original Message -------
On Monday, June 19th, 2023 at 3:31 AM, Jean Louis <bugs@gnu.support> wrote:


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

Are your tools designed for possibility of having multiple columns ?
 
 
> 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/



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-18 15:31     ` Jean Louis
  2023-06-18 19:11       ` uzibalqa
@ 2023-06-18 19:16       ` Christopher Dimech
  2023-06-19 18:49         ` Jean Louis
  1 sibling, 1 reply; 18+ messages in thread
From: Christopher Dimech @ 2023-06-18 19:16 UTC (permalink / raw)
  To: Jean Louis
  Cc: uzibalqa, Bruno Barbier,
	uzibalqa via Users list for the GNU Emacs text editor


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



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-18 19:11       ` uzibalqa
@ 2023-06-19 18:46         ` Jean Louis
  0 siblings, 0 replies; 18+ messages in thread
From: Jean Louis @ 2023-06-19 18:46 UTC (permalink / raw)
  To: uzibalqa
  Cc: Bruno Barbier,
	uzibalqa via Users list for the GNU Emacs text editor

* uzibalqa <uzibalqa@proton.me> [2023-06-18 22:12]:
> > (rcd-db-sql-report title sql cf-people-tabulated-format-with-people-list "people" nil refresh-function '(">>>UNKNOWN<<<") return-function)
> 
> Are your tools designed for possibility of having multiple columns ?

Yes, I have multiple columns. See the screenshot here:
https://gnu.support/images/2023/06/2023-06-19/Screenshot-2023-06-19-21-43-51-669841653.png


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-18 19:16       ` Christopher Dimech
@ 2023-06-19 18:49         ` Jean Louis
  2023-06-19 18:59           ` uzibalqa
  0 siblings, 1 reply; 18+ messages in thread
From: Jean Louis @ 2023-06-19 18:49 UTC (permalink / raw)
  To: Christopher Dimech
  Cc: uzibalqa, Bruno Barbier,
	uzibalqa via Users list for the GNU Emacs text editor

* Christopher Dimech <dimech@gmx.com> [2023-06-18 22:16]:
> 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.

Yes, good idea. But I did not find use of it for me. All my PostgreSQL database tables follow certain pattern as described by:

GeDaFe - PostgreSQL Generic Database Interface:
http://gedafe.github.io/doc/gedafe-sql.en.html 

and should be compatible with the web interface as well in that
sense. I did not test it for years, since I switched to Emacs
interface.

They follow this pattern "mytable_" plus "_id", so there is always
"ID" which serves handy for tabulated-list-mode

-- ------------------------------------------
-- ------------ Table mytable
-- ------------------------------------------
DROP SEQUENCE mytable_id_seq;

CREATE TABLE mytable (
mytable_id SERIAL NOT NULL PRIMARY KEY,
mytable_uuid UUID NOT NULL DEFAULT gen_random_uuid() UNIQUE,
mytable_datecreated TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
mytable_datemodified TIMESTAMP,
mytable_usercreated TEXT NOT NULL DEFAULT current_user,
mytable_usermodified TEXT NOT NULL DEFAULT current_user,
mytable_name TEXT,
mytable_title TEXT,
mytable_description TEXT,
mytable_ TEXT
);

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-19 18:49         ` Jean Louis
@ 2023-06-19 18:59           ` uzibalqa
  2023-06-21  4:48             ` Jean Louis
  0 siblings, 1 reply; 18+ messages in thread
From: uzibalqa @ 2023-06-19 18:59 UTC (permalink / raw)
  To: Jean Louis
  Cc: Christopher Dimech, Bruno Barbier,
	uzibalqa via Users list for the GNU Emacs text editor

------- Original Message -------
On Tuesday, June 20th, 2023 at 6:49 AM, Jean Louis <bugs@gnu.support> wrote:


> * Christopher Dimech dimech@gmx.com [2023-06-18 22:16]:
> 
> > 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.
> 
> 
> Yes, good idea. But I did not find use of it for me. All my PostgreSQL database tables follow certain pattern as described by:
> 
> GeDaFe - PostgreSQL Generic Database Interface:
> http://gedafe.github.io/doc/gedafe-sql.en.html
> 
> and should be compatible with the web interface as well in that
> sense. I did not test it for years, since I switched to Emacs
> interface.
> 
> They follow this pattern "mytable_" plus "id", so there is always
> "ID" which serves handy for tabulated-list-mode
> 
> -- ------------------------------------------
> -- ------------ Table mytable
> -- ------------------------------------------
> DROP SEQUENCE mytable_id_seq;
> 
> CREATE TABLE mytable (
> mytable_id SERIAL NOT NULL PRIMARY KEY,
> mytable_uuid UUID NOT NULL DEFAULT gen_random_uuid() UNIQUE,
> mytable_datecreated TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
> mytable_datemodified TIMESTAMP,
> mytable_usercreated TEXT NOT NULL DEFAULT current_user,
> mytable_usermodified TEXT NOT NULL DEFAULT current_user,
> mytable_name TEXT,
> mytable_title TEXT,
> mytable_description TEXT,
> mytable TEXT
> );

How can I adapt the following to print a table with multiple values rather that one ?

(setq foo '((a . ["aa1" "aa2"]) (b . ["bb1" "bb2"]) (c . ["cc1" "cc2"])))
(tlprint-alist foo)

(defun tlprint-alist (alist &optional outbufr keytl valtl)
  "Print an associated list via `tabulated-list-print'."

  (let*
      ( (bufr (or outbufr (get-buffer-create "*Alist2*")))
        (keytl (or keytl "Key Title"))
        (valtl (or valtl "Value Title")) )

    (with-current-buffer bufr
      (tabulated-list-mode)
      (setq buffer-read-only nil)
      (setq tabulated-list-format
             (vector (list keytl 20 t) (list valtl 20 t)))
      (setq tabulated-list-sort-key (cons keytl nil))
      (setq tabulated-list-entries
            (mapcar (lambda (dyad)
                      (list (car dyad) (cdr dyad)))
                    alist))
      (tabulated-list-init-header)
      (tabulated-list-print) )))




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-19 18:59           ` uzibalqa
@ 2023-06-21  4:48             ` Jean Louis
  2023-06-21 10:45               ` uzibalqa
  0 siblings, 1 reply; 18+ messages in thread
From: Jean Louis @ 2023-06-21  4:48 UTC (permalink / raw)
  To: uzibalqa
  Cc: Christopher Dimech, Bruno Barbier,
	uzibalqa via Users list for the GNU Emacs text editor

* uzibalqa <uzibalqa@proton.me> [2023-06-19 22:00]:
> (setq foo '((a . ["aa1" "aa2"]) (b . ["bb1" "bb2"]) (c . ["cc1" "cc2"])))
> (tlprint-alist foo)
> 
> (defun tlprint-alist (alist &optional outbufr keytl valtl)
>   "Print an associated list via `tabulated-list-print'."
> 
>   (let*
>       ( (bufr (or outbufr (get-buffer-create "*Alist2*")))
>         (keytl (or keytl "Key Title"))
>         (valtl (or valtl "Value Title")) )
> 
>     (with-current-buffer bufr
>       (tabulated-list-mode)
>       (setq buffer-read-only nil)
>       (setq tabulated-list-format
>              (vector (list keytl 20 t) (list valtl 20 t)))
>       (setq tabulated-list-sort-key (cons keytl nil))
>       (setq tabulated-list-entries
>             (mapcar (lambda (dyad)
>                       (list (car dyad) (cdr dyad)))
>                     alist))
>       (tabulated-list-init-header)
>       (tabulated-list-print) )))

It works!

Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-21  4:48             ` Jean Louis
@ 2023-06-21 10:45               ` uzibalqa
  2023-06-24 19:19                 ` Jean Louis
  0 siblings, 1 reply; 18+ messages in thread
From: uzibalqa @ 2023-06-21 10:45 UTC (permalink / raw)
  To: Jean Louis
  Cc: Christopher Dimech, Bruno Barbier,
	uzibalqa via Users list for the GNU Emacs text editor


------- Original Message -------
On Wednesday, June 21st, 2023 at 4:48 PM, Jean Louis <bugs@gnu.support> wrote:


> * uzibalqa uzibalqa@proton.me [2023-06-19 22:00]:
> 
> > (setq foo '((a . ["aa1" "aa2"]) (b . ["bb1" "bb2"]) (c . ["cc1" "cc2"])))
> > (tlprint-alist foo)
> > 
> > (defun tlprint-alist (alist &optional outbufr keytl valtl)
> > "Print an associated list via `tabulated-list-print'."
> > 
> > (let*
> > ( (bufr (or outbufr (get-buffer-create "Alist2")))
> > (keytl (or keytl "Key Title"))
> > (valtl (or valtl "Value Title")) )
> > 
> > (with-current-buffer bufr
> > (tabulated-list-mode)
> > (setq buffer-read-only nil)
> > (setq tabulated-list-format
> > (vector (list keytl 20 t) (list valtl 20 t)))
> > (setq tabulated-list-sort-key (cons keytl nil))
> > (setq tabulated-list-entries
> > (mapcar (lambda (dyad)
> > (list (car dyad) (cdr dyad)))
> > alist))
> > (tabulated-list-init-header)
> > (tabulated-list-print) )))
> 
> 
> It works! - Jean

It works indeed.  But instead of just a dyad (a key and value), I want to handle
an arbitrary number of values.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Format of lists and alists required for displaying lists of tabulated data
  2023-06-21 10:45               ` uzibalqa
@ 2023-06-24 19:19                 ` Jean Louis
  0 siblings, 0 replies; 18+ messages in thread
From: Jean Louis @ 2023-06-24 19:19 UTC (permalink / raw)
  To: uzibalqa
  Cc: Christopher Dimech, Bruno Barbier,
	uzibalqa via Users list for the GNU Emacs text editor

* uzibalqa <uzibalqa@proton.me> [2023-06-21 13:46]:

> It works indeed.  But instead of just a dyad (a key and value), I
> want to handle an arbitrary number of values.

I am always inside tabulated-list-mode as I use heavily my software: RCD Notes & Hyperscope for GNU Emacs, which may not be easy to install.

So I have made functions making my life easy. Let me point out what I mean.

Let us say I wish to find who introduced the person in the list:

(defun cf-people-jump-to-introducer (&optional id)
  "Jump to introducer of person with ID"
  (interactive)
  (when-tabulated-id "people"
      (let ((introducer (rcd-db-get-entry "people" "people_introducedby" id cf-db)))
	(cond (introducer (cf-people-by-id-list (list introducer)))
	      (t (rcd-warning-message "Cannot find introducer for person with ID %s" id))))))

I am pointing now to the function `cf-people-by-id-list'. The rest is only finding the ID of introducer, and then that function is opening that contact of introducer.

Let us say I need people by their relation type:

(defun cf-people-by-relation-type (&optional id)
  "List of people by relation type ID."
  (interactive)
  (when-tabulated-id "relationtypes"
      (let* ((id-list (rcd-sql-list "SELECT peoplerelations_people1 
                                       FROM peoplerelations
                                      WHERE peoplerelations_relationtypes = $1" 
				    cf-db id))
	     (relation-name (rcd-db-get-entry "relationtypes" "relationtypes_name" id cf-db))
	     (title (format "People with relation `%s'" relation-name)))
	(cf-people-by-id-list id-list title))))

Then that function `cf-by-people-id-list` does something more complex:

(defun cf-people-by-id-list (list &optional title refresh-function return-function)
  (rcd-db-log-function 'cf-people-by-id-list)
  (let* ((limit (or (cf-user-number-of-latest-entries) cf-people-list-limit))
	 (refresh-function (or refresh-function (lambda () (cf-people-by-id-list list))))
	 (list (cond ((> (length list) limit) (seq-subseq list 0 limit))
		     (t list)))
	 (sql-id-list (rcd-sql-id-list list)))
    (cond (list (let ((sql (format "SELECT DISTINCT ON (people_id) 
                                           people_id, get_full_contacts_name(people_id), 
                                           coalesce((SELECT get_contacts_name(peoplerelations_people2) 
                                                       FROM peoplerelations 
                                                      WHERE peoplerelations_people1 = people_id 
                                                   ORDER BY peoplerelations_default, peoplerelations_id LIMIT 1),
                                                     '>>>UNKNOWN<<<') 
                                       FROM people 
                                      WHERE people_id IN (%s) 
                                   ORDER BY people_id DESC" sql-id-list))
		      (title (or title "People"))
		      (gc-cons-threshold 500000000))
		  (rcd-message "Fetching list of people")
		  (prog2 (rcd-db-sql-report title sql cf-people-tabulated-format-with-people-list "people" nil refresh-function '(">>>UNKNOWN<<<") return-function)
		      (rcd-message "Total of %s %s" 
				   (rcd-propertize-bold (number-to-string (length list)))
				   (rcd-propertize-bold "people")))))
	(t (rcd-warning-message (cond (title (format "NO REPORT FOR: %s" title))
				      (t "NO REPORT FOR PEOPLE LIST")))))))

So by using that function I am making 2 SQL calls, it could be faster if I am not using that function, right now there are no noticable differences.

However, it is not really arbitrary data, a there is format `cf-people-tabulated-format-with-people-list' which is always used for table `people':

cf-people-tabulated-format-with-people-list ➜ [("ID" 8 rcd-tabulated-number-as-string-predicate) ("Name" 40 t) ("List of people" 40 t)]

To make it more arbitrary one would need to make dynamic format for
tabulated-list-mode, it means your program should figure out how many
columns are there and what are columns names, and maybe even their
width. I think I do not have that possibility currently.

What I have are database table combined views or "combos", so for each table I am sometimes automatically generating the combo view, which has it's ID and NAME, and then I can edit the entry with arbitrary number of lines. Not arbitrary number of columns, even though that is possible too.

For example, I have the entry like:

 33446      countries                    Country                                  public  table   maddox     32 kB

then I press "l" for the list, and I get:

 1          AFGHANISTAN
 2          ÅLAND ISLANDS
 3          ALBANIA
 4          ALGERIA
 5          AMERICAN SAMOA
 6          ANDORRA
 7          ANGOLA
 8          ANGUILLA
 9          ANTARCTICA
 10         ANTIGUA AND BARBUDA
 11         ARGENTINA

then on some of those entries I press `e' to edit:

                             ID   5
                        Country   "AMERICAN SAMOA"
                           Code   "AS"
                 Dialing Prefix   1
                      Apostille   nil
                       Offshore   nil
                      Continent   nil
           Company registration   nil
                            CRS   t
                         Tag #1   nil
                         Tag #2   nil
                         Tag #3   nil
                      EU Member   nil
                     Flag image   nil
                       Schengen   nil
                     Flag emoji   nil
             Potential Schengen   nil

so that is arbitrary number of rows, not columns, as in some other list:

 1          Europe
 2          Africa
 3          North America
 4          South America
 5          Asia
 6          Australia
 7          Antarctica

I would get different rows:

                             ID   2
                           Name   "Africa"
                      Area km^2   30370000.0
                    Description   nil

However, in the same manner one can make a function to recognize number of columns.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2023-06-24 19:19 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-16 21:08 Format of lists and alists required for displaying lists of tabulated data uzibalqa
2023-06-17  7:36 ` Bruno Barbier
2023-06-17 12:33   ` uzibalqa
2023-06-17 20:54     ` Tim Landscheidt
2023-06-18 10:36       ` uzibalqa
2023-06-18 11:29         ` Tim Landscheidt
2023-06-18 13:20           ` uzibalqa
2023-06-18 13:37           ` uzibalqa
2023-06-18 13:51             ` uzibalqa
2023-06-18 15:31     ` Jean Louis
2023-06-18 19:11       ` uzibalqa
2023-06-19 18:46         ` Jean Louis
2023-06-18 19:16       ` Christopher Dimech
2023-06-19 18:49         ` Jean Louis
2023-06-19 18:59           ` uzibalqa
2023-06-21  4:48             ` Jean Louis
2023-06-21 10:45               ` uzibalqa
2023-06-24 19:19                 ` Jean Louis

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.