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 yMNmJodyM2NRPwEAbAwnHQ (envelope-from ) for ; Wed, 28 Sep 2022 00:00:39 +0200 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 cCBTJodyM2OpvAAAauVa8A (envelope-from ) for ; Wed, 28 Sep 2022 00:00:39 +0200 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 2FD061A7C8 for ; Wed, 28 Sep 2022 00:00:39 +0200 (CEST) Received: from localhost ([::1]:45844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odId4-0000US-1k for larch@yhetil.org; Tue, 27 Sep 2022 18:00:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odIc8-0000U2-6s for emacs-orgmode@gnu.org; Tue, 27 Sep 2022 17:59:40 -0400 Received: from stw1.rcdrun.com ([217.170.207.13]:43665) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odIc5-0001zA-L2 for emacs-orgmode@gnu.org; Tue, 27 Sep 2022 17:59:39 -0400 Received: from localhost ([::ffff:102.83.37.37]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000BA40E.0000000063337247.00005BB4; Tue, 27 Sep 2022 14:59:34 -0700 Date: Wed, 28 Sep 2022 00:41:41 +0300 From: Jean Louis To: Greg Minshall Cc: emacs-orgmode@gnu.org Subject: Re: form-like process for entering rows in an org-mode table? Message-ID: Mail-Followup-To: Greg Minshall , emacs-orgmode@gnu.org References: <278048.1658506324@apollo2.minshall.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <278048.1658506324@apollo2.minshall.org> User-Agent: Mutt/+ () (2022-06-11) Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" 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=1664316039; 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; bh=5go/WUpEZ63zNUwMe+CT/aj3F7vE4ty6x6fyVoo8wqw=; b=kIKN5LcuA8V7cNbhlWUW3ntSKf8330vDH1dnwUKcXK0OJN22ap/3TV04l2Dxy31e4PECQ6 X8KjqnTNQ8MQNQVCXX0AmHOfx4Esbs1shxHhGB8v5A+HvB1ahbmB+zt5oeeZDGiSzOWCzH n62nVdFtfrbs4qOu+gVX5mO0DvB+ZBpbic/1PCpMKk2WqLEU03WVUpBVG0u/Oou472idgD j6Qtk+2XmGDLKrSjVlJHeZniXY1v6eWwH9LUkuPe0c2RqKF7A2rBxM940ODSphtw7j2d4N SuBPQDr8Jv0oX7EXyejRQv5PGGFBgHYwH24iHyVFjVcW/9G46aB9SE7WiCAiDQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664316039; a=rsa-sha256; cv=none; b=jw19bo/TsV1iclP2sRsSjw6rPvgbGtdURRWD6PUbqx33c+1GEL3/010j9Fj1hXrfMRypnj fzW1g6US8VHli5KTpner1Qpn9RoSXIQ0dEgeSFqkf8c4cpixnoHbtAigqYh8dXAFv8ujjp FUxuluyEXatK71ssN2Kibi4qab5Y1AqbzylnBX4A+tbd6RqijuS+htB9oyxTHkK/fr39qD sLQv1isJT+UY7VharZ+PGBZNA2l3jyrWmgMbWuBrRxiIIt7s6HtJnFqRZbbNoK0Cd5d43Z 6lRXP09mKONRmsL3DR2DPbTZ8jJHlJnaDRvAVsMsymU0eUaO/36WFZDAKb00SA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; 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: -0.14 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; 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: 2FD061A7C8 X-Spam-Score: -0.14 X-Migadu-Scanner: scn1.migadu.com X-TUID: wVwGgsFxkLcw * Greg Minshall [2022-07-22 19:14]: > hi. does anyone have any code, or know of any existing package, that > would allow for some sort of form-like (or "transient"-like) interface > for adding rows to an org-mode table? in particular, that provides some > sort of =completing-read= interface for a given set of choices for a > given column, etc. I have total understanding for this use case, as I do similar all the time. Just that I don't use Org tables, I use database tables. I would complete from database like (rcd-completing-read-sql-hash "Choose person" "SELECT people_id, people_name FROM people" cf-db) That would give me person to choose from. (defun rcd-completing-read-sql-hash (prompt sql pg &optional history initial-input not-require-match auto-initial-input) "Complete selection by using SQL. First column shall be unique id, followed by text representation. Example SQL query: SELECT people_id, people_firstname || ' ' || people_lastname FROM people PG is database handle. HISTORY is supported with INITIAL-INPUT Argument PROMPT will be displayed to user." (let* ((hash (rcd-sql-hash-with-key sql pg)) (completion-ignore-case t) (require-match (if not-require-match nil t)) (history (or history (rcd-ask-history-variable prompt))) (initial-input (or initial-input (when auto-initial-input (car (symbol-value history))))) (choice (completing-read prompt hash nil require-match initial-input history)) (choice (string-trim choice)) (id (gethash choice hash))) (if id id (if not-require-match choice)))) I find parsing text table rather difficult. If you have extensive work, I would recommend keeping information in the database table, and then inserting it into Org mode by using source blocks or functions. Then I am thinking as following: - psql command line tool has csv format among others - pandoc can convert from csv to org and here it is: $ psql -A -t -X -q -c "select peoplenames_peoplename, peoplenames_peopleid as people from peoplenames where peoplenames_peoplename ~* 'minsh' limit 5;" Greg Minshall|320418 then that CSV may be converted by using pandoc: psql -A -t -X -q -c "select peoplenames_peoplename, peoplenames_peopleid as people from peoplenames where peoplenames_peoplename ~* 'minsh' limit 5;" | pandoc -f csv -t org | Greg Minshall|320418 | |----------------------| then that may be beautified... OK not moving so well, let me try with HTML to Org: psql -A -t -H -q -c "select peoplenames_peoplename, peoplenames_peopleid as people from peoplenames where peoplenames_peoplename ~* 'min' limit 5;" | pandoc -f html -t org | Ali Amini | 131 | | Jasmin Hatipović | 187 | | Lamin Bangura | 211 | | Errol Anthony Flemmings | 259 | | Carlene Cummins | 302 | So there it is, conversion from PostgreSQL to HTML to Org. 500 people are converted with his timing: real 0m0.558s user 0m0.445s sys 0m0.121s Let us say I wish to enter new identity from which to send emails, letters, then I have this function: (defun rcd-db-table-identities-insert-new-row (&optional id) "Add new identity." (interactive) (when-tabulated-id "identities" (let* ((name (rcd-ask-get "Identity name: ")) (first-name (rcd-ask-get "First name: ")) (last-name (rcd-ask-get "Last name: ")) (e-mail (rcd-ask-get "E-mail: ")) (signature (rcd-ask-or-null "Signature: ")) (signature (if signature (sql-escape-string signature) "NULL")) (signature-file (read-file-name "File name: ")) (signature-file (if signature-file (sql-escape-string signature-file) "NULL")) (organization (rcd-ask "Organization: ")) (organization (if organization (sql-escape-string organization) "NULL")) (account (cf-accounts-select)) (language (rcd-db-language-select)) (sql (format "INSERT INTO identities (identities_name, identities_firstname, identities_lastname, identities_email, identities_signature, identities_signaturefile, identities_organization, identities_accounts, identities_languages) VALUES ($1, $2, $3, $4, %s, %s, %s, $5, $6)" signature signature-file organization))) (rcd-sql sql cf-db name first-name last-name e-mail account language) (rcd-tabulated-refresh)))) $ time psql -A -t -H -q -c "select peoplelisttypes_name from peoplelisttypes;" | pandoc -f html -t org | Competitor | | Integrator | | Investor | | Partner | | Reseller | | Our company | | Accounting | | Mailing List | | Mobile Network Provider | | Family | | Default | | Managed Company or Business | | Country | | Company | | Cooperative Society | | Business | | Press | | Sales Leads | real 0m0.317s user 0m0.302s sys 0m0.021s For more help let me know. Keeping stuff in the ordered database is useful. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/