From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id yfRiMFLv5mDydQAAgWs5BA (envelope-from ) for ; Thu, 08 Jul 2021 14:28:02 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id iMWBK1Lv5mDBfQAA1q6Kng (envelope-from ) for ; Thu, 08 Jul 2021 12:28:02 +0000 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 F328A824F for ; Thu, 8 Jul 2021 14:28:01 +0200 (CEST) Received: from localhost ([::1]:35878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1T8K-0007Mn-SN for larch@yhetil.org; Thu, 08 Jul 2021 08:28:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1T5x-0004k2-0w for emacs-orgmode@gnu.org; Thu, 08 Jul 2021 08:25:33 -0400 Received: from mailer-211-159.hitrost.net ([91.185.211.159]:34939) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1T5t-00080E-EK for emacs-orgmode@gnu.org; Thu, 08 Jul 2021 08:25:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=christianmoe.com; s=x; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:In-reply-to:Subject:Cc:To:From:References:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kuX7Adoet7wZC7/x/3SaskmOFyXVAhHDASgByMqgF3Y=; b=QIc8xxUJjXoLDIhmHXu5sz6E4A /nK+yGZ7N7/S4Hm5YVltWtskF1uUgbCkSuXrGSH0M/6zLc3m5PCbIcL9LklKKr8h9GgQ2rFmEG3rN /qOfr/Z+hjIH0H37kSYNHVbVbUoJoWrGfgstofmFgHS/5jnZuxkIj0842kIBTZ8+qIB0jZiZyKgUP yckMIxfaWAZTaozwqKyh5iHwrJzMKISGtDTTyrLediZVxc2pXxssQhZVl3GvAQeho1PxT/5C7tTiy ZKYhqYNA9Fw944yGoH2wwnqo98POQFnPxYaqNx3tB0Ghd5Z1oSR2DiSCeuwe0w2n2NPgn2E+sIRs2 e0TMdGsQ==; Received: from [193.77.114.89] (helo=Tauriel) by b1.hitrost.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1m1T5m-00GkzE-4k; Thu, 08 Jul 2021 14:25:22 +0200 References: <26be9301-9e1a-0dc0-47c7-53e7ffc3e6d3@free.fr> User-agent: mu4e 0.9.19; emacs 25.3.2 From: Christian Moe To: Matt Price Subject: Re: convert subtree or nested list to table In-reply-to: Date: Thu, 08 Jul 2021 14:22:25 +0200 Message-ID: <87v95l2dxa.fsf@christianmoe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-GeoIP: Country [IP], SI [193.77.114.89] X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-Authenticated-Id: mail@christianmoe.com Received-SPF: pass client-ip=91.185.211.159; envelope-from=mail@christianmoe.com; helo=mailer-211-159.hitrost.net X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tbanelwebmin , Org Mode Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1625747282; 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=kuX7Adoet7wZC7/x/3SaskmOFyXVAhHDASgByMqgF3Y=; b=rqF00JEvDV7Fsl8L4gu41m391wxghiEQT1ZqLKdidOVswWQ9CDbL09YZB3No15wRfg2Z1w 3vWX/FO7glk/iLDis61rzI/AdPH9i8wWA6gl5Y+7ExShZnv657Mee4JtPejS4CowRY7e8/ Q6hm9o/iV3Jov2AYkzpNnXhigwk/DYRqTfFqxW8Feq/BeWMycxKaSEzTJRCMFy9L8Mgflf mfZg59IGXcJ1MVcPRa1QYlLU3rfTJRe0fQ/xMhcnY4ugbVK0JHCYNu90Wc4uP3h2bbvRur 6GC2LIJSHTsAGd5bO6RUyCKQG+4ZIxxRze9EG0NroOOm2qJ6zemFDAqIx+4O/Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1625747282; a=rsa-sha256; cv=none; b=EAWB8c8VlMN66a8UrxMKunZlsqfDHn/8k1pF/YGioweWmKV3O+AhiISn89Ip2dit46itq2 4zGhZujTA5GQSO7QdsbOj0l6gGqjEtjKMOHV8r4rx+tzjc5cr/UcW/uFo/5ureUFRr5GBK 7ElqPHdXwgF+KzOu3WUlf2762FadgYgsmP7bE9Hq5mXHlYlkWCsnmt4BjTFnoIuW1P8I/V 9FjBjhdxCPYnTnVAYFvjPC9NRLVBNPxMMrM9fssLVJFt0IQ6AcV+cq0pzzLkszfqhM2pHL z1dYw5BRZxWJETdY1Bnyk7wEJgYXYN9FZwbqReaBAHkG/SDqQY7ZdIZTbyam5A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=christianmoe.com header.s=x header.b=QIc8xxUJ; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.41 Authentication-Results: aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=christianmoe.com header.s=x header.b=QIc8xxUJ; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: F328A824F X-Spam-Score: -2.41 X-Migadu-Scanner: scn0.migadu.com X-TUID: DOszUh4yibq3 Hi, Matt, Here's a version of this with a bit more processing. Define this somewhere in your document #+NAME: list2table #+BEGIN_SRC elisp :var order="columns" (let (longest) (setq data (map 'list 'flatten data)) (setq data (map 'list (lambda (x) (seq-difference x '(unordered ordered))) data)) ;; Pad out lists to equal length (setq longest (seq-max (map 'list 'length data))) (setq data (map 'list (lambda (l) (append l (make-list (- longest (length l)) ""))) data)) ;; Order by columns or rows (if (string= order "columns") (apply #'mapcar* #'list data) ; transpose data)) #+END_SRC Here is an example list to try it out with: #+NAME: testlist - Letters 1. a 2. b 3. c - Roman numerals 1. i 2. ii 3. iii - Greek letters 1. alpha 2. beta 3. gamma Now you can call the src block, passing the name of the list to the "data" variable. #+CALL: list2table(data=testlist) #+RESULTS: | Letters | Roman numerals | Greek letters | | a | i | alpha | | b | ii | beta | | c | iii | gamma | The default here is that each top item and its sublist forms a column. To get rows instead, pass order="rows" (or anything other than order="columns" really): #+CALL: list2table(data=testlist, order="rows") #+RESULTS: | Letters | a | b | c | | Roman numerals | i | ii | iii | | Greek letters | alpha | beta | gamma | You can use numbered or unnumbered lists. Sublists don't strictly have to be the same length - the code pads them out to equal length with the empty string before transposing. However, I would strongly recommend using numbered sublists of the same length (with blank items as needed), so you can make sure that items line up correctly. If you want column headers or rownames, you will need to take care of that manually before exporting. Using ":colnames yes" will lead to errors when the source is a list. Might be away to hack org-babel to get around this but I don't know how. (The only automatic solution I can think of would be by naming the calls in an unexported section and referencing them with another layer of calls in the exported section, using a src block that only passes the data on with :colnames yes. But that's fiddly.) Will this work for you? Yours, Christian Matt Price writes: > I think this is exactly what I want (with just a little moreprocessing). > Thank you so much for the idea! > > I'm having a little bit of trouble getting the same output as you though, > and I'm wondering if there might be a setting that I need to change. > > Here is what I tried, and the result. Do you have an idea of what is going > wrong here? > > Thank you! > > > ------------ > #+NAME:essay-rubric > - Category > - A > - B > - C > - D > - F > - Writing > - great > - good > - ok > - lousy > - awful > > #+begin_src emacs-lisp :var contents=essay-rubric :results table > contents > #+end_src > > #+RESULTS: > #+begin_src emacs-lisp > | (("Category" | > #+end_src > ------------- > On Wed, Jul 7, 2021 at 6:29 AM tbanelwebmin wrote: > >> Hi Matt >> >> Le 05/07/2021 à 21:44, Matt Price a écrit : >> > I have to write a number of text-heavy documents which need to be >> > delivered as tables with wrapped paragraphs in most cells. Working >> > directly in table format is pretty arduous and uncomfortable. Has >> > anyone ever written a function to accept a list or subtree as input >> > and process it into a table? >> > >> > If anyone has done something similar, I'd love some tips! >> >> Maybe you could use builtin Babel >> Hereafter you have a starting point >> - Give a name to your input Org list >> - Process it with Emacs-Lisp (or whatever language you are comfortable >> with) to output it as a table >> >> >> ____ self contained Org Mode example _____ >> >> Example of a named list >> #+NAME: BBB >> - abc >> + 123 >> + 456 >> - def >> + red >> + blue >> - ghi >> + big >> + small >> >> Example of converting the named list into a table with Emacs-Lisp >> #+begin_src elisp :var bbb=BBB :results table >> bbb >> #+end_src >> >> #+RESULTS: >> | abc | (unordered (123) (456)) | >> | def | (unordered (red) (blue)) | >> | ghi | (unordered (big) (small)) | >> ___________________________________________ >> >> >>