From: Heime <heimeborgia@protonmail.com>
To: Jean Louis <bugs@gnu.support>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: Inserting tables programatically in elisp
Date: Sat, 05 Nov 2022 09:26:14 +0000 [thread overview]
Message-ID: <6G8r6Q0wA7TY17mTPQagC7PryWleqGax0pOrX8L2xjoiPqsFkn9baSX9lFxMC6HYwVK2H1EHc0rM8cGdPDaVLmUoflOoERNI0wbf_Ro0TZg=@protonmail.com> (raw)
In-Reply-To: <Y2YmlSFr/HcO/94Q@protected.localdomain>
------- Original Message -------
On Saturday, November 5th, 2022 at 9:02 AM, Jean Louis <bugs@gnu.support> wrote:
> * Heime heimeborgia@protonmail.com [2022-11-05 10:45]:
>
> > Have been introspecting the possibility of conveniently inserting table programatically
> > in elisp and encountered "table.el".
> I would go programmatically not by hard coding the table walk, but by
> using some structure, for example:
>
> (setq my-table '(("ID" "Description" "Amount") ;; this must be header
> (1 "Payment for domain" 10.50)
> (2 "Transfer from Doe" 250)))
>
> Then I would use some function, something like:
>
> (my-org-table-generate my-table calculat-total 3rd-column)
>
> Then the function would only interpolate the table with basic
> small details, which allow later automatic table alignment:
>
> (defun rcd-org-table-cell (object)
> (cond ((numberp object) (format "| %.2f " object))
> (t (format "| %s " object))))
>
> (rcd-org-table-cell "Hello") ⇒ "| Hello "
>
> (defun rcd-org-table-horizontal-line ()
> "Return `|-' as horizontal-line."
> "|--\n")
>
> then for rows:
>
> (defun rcd-org-table-row (list)
> (with-temp-buffer
> (while list
> (insert (rcd-org-table-cell (pop list))))
> (insert "\n")
> (buffer-string)))
>
> This means you can do something like:
>
> (rcd-org-table-row '("ID" "Description" "Amount")) ⇒ "| ID | Description | Amount "
>
> then you make the main function:
>
> (defun rcd-org-table (structure)
> (let ((header (pop structure)))
> (with-temp-buffer
> (insert "\n")
> (insert (rcd-org-table-row header))
> (insert (rcd-org-table-horizontal-line))
> (while structure
> (insert (rcd-org-table-row (pop structure))))
> (insert "\n")
> (org-mode)
> (goto-char 2)
> (org-table-align)
> (buffer-substring-no-properties (point-min) (point-max)))))
>
> And now the final result:
>
> (rcd-org-table my-table) ⇒ "
> | ID | Description | Amount |
> |------+--------------------+--------|
> | 1.00 | Payment for domain | 10.50 |
> | 2.00 | Transfer from Doe | 250.00 |
>
> "
The problem I see is that the code assumes use of org-mode, whereas I am interested in
more general tables in any buffer. At first perhaps just making a table for display rather
than for user interaction.
next prev parent reply other threads:[~2022-11-05 9:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-05 7:41 Inserting tables programatically in elisp Heime
2022-11-05 8:49 ` Ihor Radchenko
2022-11-05 9:20 ` Heime
2022-11-05 9:02 ` Jean Louis
2022-11-05 9:26 ` Heime [this message]
2022-11-05 10:05 ` Jean Louis
2022-11-05 10:23 ` Jean Louis
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='6G8r6Q0wA7TY17mTPQagC7PryWleqGax0pOrX8L2xjoiPqsFkn9baSX9lFxMC6HYwVK2H1EHc0rM8cGdPDaVLmUoflOoERNI0wbf_Ro0TZg=@protonmail.com' \
--to=heimeborgia@protonmail.com \
--cc=bugs@gnu.support \
--cc=emacs-orgmode@gnu.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.