From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id ULiZDXMsZmOThwAAbAwnHQ (envelope-from ) for ; Sat, 05 Nov 2022 10:27:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 4HJ3DXMsZmMFPwEAauVa8A (envelope-from ) for ; Sat, 05 Nov 2022 10:27:15 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EE53C201C9 for ; Sat, 5 Nov 2022 10:27:14 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1orFRs-00035V-LR; Sat, 05 Nov 2022 05:26:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1orFRo-00035H-H7 for emacs-orgmode@gnu.org; Sat, 05 Nov 2022 05:26:40 -0400 Received: from mail-40137.protonmail.ch ([185.70.40.137]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1orFRm-0001pw-RR for emacs-orgmode@gnu.org; Sat, 05 Nov 2022 05:26:40 -0400 Date: Sat, 05 Nov 2022 09:26:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1667640393; x=1667899593; bh=ekAabyNqfDnHCZI+P4fm0jskwqUNwRZrkAv+paoW0qg=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=S3oHUkObSbMV5xv995DrCqoqL/231U6MC4Rv8Ns4/1a4VSRuKdmfGmX4Tapk3kzSw rRyY+dfDiTAvbsvImgCw9SLtAh14JR3Ay0lNhD9Ts3ap5DY/OioYE/Bl/ybWY4EJjM KQXORkaSZHnBSi6oxRb0iT+kbbmteaeQ6JQOxHPbTcC11ZmJO4/jscnsAqbuuBNE7M YoME71m0ZVzdz0YsY5BorF54SIPM+no0kls31EVJMhCHM545kNnYmqeIG0aLrI7D4j sRtiAt9Xx52SeoCWeg6dQ66YE9qY6hfFvRVFqykrvPqGQvUCpXx17DjmfGiHnmM+A4 1GvTNJax+R8rg== To: Jean Louis From: Heime Cc: "emacs-orgmode@gnu.org" Subject: Re: Inserting tables programatically in elisp Message-ID: <6G8r6Q0wA7TY17mTPQagC7PryWleqGax0pOrX8L2xjoiPqsFkn9baSX9lFxMC6HYwVK2H1EHc0rM8cGdPDaVLmUoflOoERNI0wbf_Ro0TZg=@protonmail.com> In-Reply-To: References: Feedback-ID: 57735886:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.70.40.137; envelope-from=heimeborgia@protonmail.com; helo=mail-40137.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Emacs-orgmode" Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1667640435; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=ekAabyNqfDnHCZI+P4fm0jskwqUNwRZrkAv+paoW0qg=; b=AH4WLUgdFApU+OdyNBiImyoa4twDKzvrba8TcLQ+utdiDDqy3jySbhB/r877mLZQjmeu+P 2u2GkkBifF+56F61bILG35ybXLUQY/mqhsT6vOqnqo8qx2gnNkpzacQlZTtfwO6CV8rwDY QYUFHCHsy1faJPCImcpL/Wz5/SKyzJ3ddDErxM31EGUtfn0jUQXtYDuTlP9HYNo3j2zPpJ qHAz+Z/kEYjubgFJ/2pUG3PnRRYf8F1E0gu95KBCshgCsfm1ox7iceGEYxPwjZs4wqI7W1 GfpdAs3j0Ex9jickxpIqvRrIbBQN0Z+HKTn/bGtfG2Q6wiByYxGrjcHy3UA+6Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1667640435; a=rsa-sha256; cv=none; b=VgJV6Ayoe/K+tnOgbXDZzPXKhXKo/CSE6jsNHydpEy6Tgouv1S6PPEzZ+uth/jNVk94x7W 6lCeliYSv0Giyr96XcGXgg7F0lNkuuus3uUIiUzxHAfNRFwVmye57M/bXdYdEoMCZXFD+j CG61DNJDO4YSonUWX3HCHnGp40MtZ5+hCoWuDKsX3ZLLr9pDQmA51y6nU4t+E+bMuom8Gn tBfuI3sb0PF0yE1pvM6llDXMSwfZ/tJb+RFh3HQxB/CmlK3uTbSaLf9sIOt3DrRszzAJg0 /+bHTRd6QZwG19Olg+l8Msp/2TbQIjaHwmJILQe3u2Y3AKDoa3dbTo3R3DHg6Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=protonmail.com header.s=protonmail3 header.b=S3oHUkOb; dmarc=pass (policy=quarantine) header.from=protonmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.50 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=protonmail.com header.s=protonmail3 header.b=S3oHUkOb; dmarc=pass (policy=quarantine) header.from=protonmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: EE53C201C9 X-Spam-Score: -2.50 X-Migadu-Scanner: scn0.migadu.com X-TUID: L57SNE09XrP8 ------- Original Message ------- On Saturday, November 5th, 2022 at 9:02 AM, Jean Louis w= rote: > * Heime heimeborgia@protonmail.com [2022-11-05 10:45]: >=20 > > 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: >=20 > (setq my-table '(("ID" "Description" "Amount") ;; this must be header > (1 "Payment for domain" 10.50) > (2 "Transfer from Doe" 250))) >=20 > Then I would use some function, something like: >=20 > (my-org-table-generate my-table calculat-total 3rd-column) >=20 > Then the function would only interpolate the table with basic > small details, which allow later automatic table alignment: >=20 > (defun rcd-org-table-cell (object) > (cond ((numberp object) (format "| %.2f " object)) > (t (format "| %s " object)))) >=20 > (rcd-org-table-cell "Hello") =E2=87=92 "| Hello " >=20 > (defun rcd-org-table-horizontal-line () > "Return `|-' as horizontal-line." > "|--\n") >=20 > then for rows: >=20 > (defun rcd-org-table-row (list) > (with-temp-buffer > (while list > (insert (rcd-org-table-cell (pop list)))) > (insert "\n") > (buffer-string))) >=20 > This means you can do something like: >=20 > (rcd-org-table-row '("ID" "Description" "Amount")) =E2=87=92 "| ID | Desc= ription | Amount " >=20 > then you make the main function: >=20 > (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))))) >=20 > And now the final result: >=20 > (rcd-org-table my-table) =E2=87=92 " > | ID | Description | Amount | > |------+--------------------+--------| > | 1.00 | Payment for domain | 10.50 | > | 2.00 | Transfer from Doe | 250.00 | >=20 > " The problem I see is that the code assumes use of org-mode, whereas I am in= terested in more general tables in any buffer. At first perhaps just making a table fo= r display rather than for user interaction.=20