From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id aJQ5EAIrc2NftwAAbAwnHQ (envelope-from ) for ; Tue, 15 Nov 2022 07:00:34 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 4DQcEAIrc2P/ygAAauVa8A (envelope-from ) for ; Tue, 15 Nov 2022 07:00:34 +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 1026E20E0 for ; Tue, 15 Nov 2022 07:00:32 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouoz2-00089J-E9; Tue, 15 Nov 2022 00:59:45 -0500 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 1ouoyz-00089A-Rq for emacs-orgmode@gnu.org; Tue, 15 Nov 2022 00:59:41 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouoyx-00035B-BH for emacs-orgmode@gnu.org; Tue, 15 Nov 2022 00:59:41 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 76B7B240101 for ; Tue, 15 Nov 2022 06:59:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1668491975; bh=6e3KU5llcgz8qKkNhV/lkdxRwpGz3PPiqHSHYwfChMA=; h=From:To:Cc:Subject:Date:From; b=q8yQs5+L7tQphe1o0T2WdkILvH3gG6Ch5EhAwQ3O+o4KY1bI68lV/CUtu2ZlcqayY gZnmvxA0Ml8uElv0QQGGLHjOJ3+1Wr/OTR9RkoMhw2Qc/jJnSGNyyb2aJEhXHANZk2 Srid1yyqPgx+KBtmtEboc0VQOsd9TQLBGMfw0SXKOEqRF4P6zrtBpFwzfj52VriTjp kJvE6UuWYRap1i8wt1QIf/AeK8884A+JObwRqRZtCGjAIN/8kmXggyOn8xKlxi4c6/ jS9u0BawWeaMLQuDO90ixKJXi7R6r4ZWn0TpyuF+3s9aJpImKwMZC50rrZ5OHmZQpy rzYMcTlPMA0CQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4NBFr11K5Nz9rxG; Tue, 15 Nov 2022 06:59:28 +0100 (CET) From: Ihor Radchenko To: Alain.Cochard@unistra.fr Cc: Org Mode List Subject: [RFC] :var x=list-name should be resolved into simple lists (item1 item2 ...); not nested ((item1) (item2) ...) (was: 2 'echo' bash instructions produce a table) In-Reply-To: <87pmdqfao4.fsf@localhost> References: <25447.23346.575598.420558@gargle.gargle.HOWL> <87tu3ba40w.fsf@localhost> <25457.22124.839301.412560@gargle.gargle.HOWL> <87pmdqfao4.fsf@localhost> Date: Tue, 15 Nov 2022 06:00:04 +0000 Message-ID: <87tu30dafv.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=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-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=1668492033; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=0+uMQFgA0FAG0dJftfHLeyGXNSuWqJvkU68o7K/7YJU=; b=hGy7KNMKNx9WvHG0XLRpXDv/SB1WlIBMiIv/eCtvtmN7U6sXM1REVm/oNABE6rAC2KbQ4s 1gnf9OT8PbEzP30DDJqHKy4NH7txjX+VDV99Wbu2+rZmeyCIJlwoDjvdIiJvbB6ZzHq9Nk HhxY0sWQcG6ijn8bIG6q2xeZNnT8vgRYFnWCB1CK4mnebto2TvA6LROA2wd4yYAk7iq9ny S2sOkMKnMFTzrqQgtdonVqOgLT4wUBOgp8NhlBYSf3EFrLD2zSIvg6smScmND5mDeFOBhA JDyK1IyrTqofpx9iJoyWtL8SteHSnGJWBM1YrFcB4cUBxkWsUIe/UkFtthuVHQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1668492033; a=rsa-sha256; cv=none; b=qk3atEFH6vTYg9vtn/fjqBb1EUazQbrxf30BFbfucgiVBbXaRYZ7QFbVD1dkgo/hAW4UDE bn7puzJ5BB/oeuWEQRSawI6Z3nPexQ1w/3A+YZXXEvQ1J0JEw2iDJJd7THXY3QSOEaYT+U cECVGI6h9w4E3Dj6RqssXw5vqY8/yvaS68zGoaLIrim3Xx8F4uQq3aTKwqoktFpOp+EyTp MBM+QL7/6RnGhaGxiX1DKIUl3I2dOmRcqsfX+xmeXOafPJfjJxQ2KsxKWU95S5xHguGcNK pE4xRK76fAQ7FKtvcXwRcvVIG9XYB2huPJFLp59fNzF0/qtTT+loOOnIF1trPQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=q8yQs5+L; dmarc=pass (policy=none) header.from=posteo.net; 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: -3.74 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=q8yQs5+L; dmarc=pass (policy=none) header.from=posteo.net; 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: 1026E20E0 X-Spam-Score: -3.74 X-Migadu-Scanner: scn1.migadu.com X-TUID: Cw+qJB7bkRqt --=-=-= Content-Type: text/plain Ihor Radchenko writes: >> In section 16.4 (Environment of a Code Block) >> >> A simple named list. >> >> #+NAME: example-list >> - simple >> - not >> - nested >> - list >> >> #+BEGIN_SRC emacs-lisp :var x=example-list >> (print x) >> #+END_SRC >> >> #+RESULTS: >> | simple | list | >> >> But if I evaluate the code, I get >> >> #+RESULTS: >> | simple | (unordered (not) (nested)) | >> | list | | > > Confirmed. Need to look into this. The attached is a fix for this discrepancy with the manual. However, it looks like at least ob-java already tried to work around the erroneous return value of org-babel-read-list. Hence, we at least need to announce this fix in ORG-NEWS. Or maybe there are other objections? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-core-Resolve-named-list-references-to-simple-list.patch >From cc1dbc5ca61d04e8a52598feb031e24102575f0d Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Tue, 15 Nov 2022 13:52:04 +0800 Subject: [PATCH] ob-core: Resolve named list references to simple lists * lisp/ob-core.el (org-babel-read-list): Return a simple list instead of list of lists. Document this in the docstring. * testing/lisp/test-ob-java.el (ob-java/read-return-list): (ob-java/read-list-return-array): (ob-java/read-return-list-with-package): Fix tests assuming previous behavior. * testing/lisp/test-ob.el (test-ob/simple-variable-resolution): Add new tests. * etc/ORG-NEWS (List references in source block variable assignments are now proper lists): Document the change. This commit fixes the broken promise in the manual section 16.4 Environment of a Code Block where the named references to lists should be converted to simple lists consisting of the top-level items. The inconsistency existed for a while and possibly lurked into some third-party packages. So, announcement in NEWS is required. Reported-by: Alain.Cochard@unistra.fr Link: https://orgmode.org/list/87pmdqfao4.fsf@localhost --- etc/ORG-NEWS | 34 ++++++++++++++++++++++++++++++++++ lisp/ob-core.el | 11 +++++++++-- testing/lisp/test-ob-java.el | 10 +++++----- testing/lisp/test-ob.el | 26 +++++++++++++++++++++++--- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 04b5be64a..4e23ac0e3 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -701,6 +701,40 @@ If you prefer to keep the keybinding, you can add it back to (define-key org-mode-map (kbd "C-c SPC") #'org-table-blank-field) #+end_src +*** List references in source block variable assignments are now proper lists + +List representation of named lists is now converted to a simple list +as promised by the manual section [[info:org#Environment of a Code Block][org#Environment of a Code Block]]. +Previously, it was converted to a list of lists. + +Before: + +#+begin_src org +,#+NAME: example-list +- simple + - not + - nested +- list + +,#+BEGIN_SRC emacs-lisp :var x=example-list :results value +(format "%S" x) +,#+END_SRC + +,#+RESULTS: +: (("simple" (unordered ("not") ("nested"))) ("list")) +#+end_src + +After: + +#+begin_src org +,#+BEGIN_SRC emacs-lisp :var x=example-list :results value +(format "%S" x) +,#+END_SRC + +,#+RESULTS: +: ("simple" "list") +#+end_src + ** New features *** New citation engine diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 1259909a0..3a07c10d5 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2239,8 +2239,15 @@ (defun org-babel-read-table () (org-table-to-lisp))) (defun org-babel-read-list () - "Read the list at point into emacs-lisp." - (mapcar (lambda (el) (org-babel-read el 'inhibit-lisp-eval)) + "Read the list at point into emacs-lisp. + +Return the list of strings representing top level items: + + (item1 item2 ...) + +Only consider top level items. See Info node `(org)Environment of \ +a Code Block'." + (mapcar (lambda (el) (org-babel-read (car el) 'inhibit-lisp-eval)) (cdr (org-list-to-lisp)))) (defvar org-link-types-re) diff --git a/testing/lisp/test-ob-java.el b/testing/lisp/test-ob-java.el index 07540ed74..65b7259d3 100644 --- a/testing/lisp/test-ob-java.el +++ b/testing/lisp/test-ob-java.el @@ -379,8 +379,8 @@ (ert-deftest ob-java/read-return-list () "#+begin_src java :dir 'nil :var a=java_list :results value silent import java.util.List; import java.util.Arrays; -List b = Arrays.asList(a.get(0).get(0), - a.get(1).get(0)); +List b = Arrays.asList(a.get(0), + a.get(1)); return b; #+end_src @@ -394,7 +394,7 @@ (ert-deftest ob-java/read-list-return-array () "Read a list and return an array." (org-test-with-temp-text "#+begin_src java :dir 'nil :var a=java_list :results value silent -String[] b = {a.get(0).get(0), a.get(1).get(0)}; +String[] b = {a.get(0), a.get(1)}; return b; #+end_src @@ -411,8 +411,8 @@ (ert-deftest ob-java/read-return-list-with-package () package pkg; import java.util.List; import java.util.Arrays; -List b = Arrays.asList(a.get(0).get(0), - a.get(1).get(0)); +List b = Arrays.asList(a.get(0), + a.get(1)); return b; #+end_src diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 4beaecf7b..e4090d6d8 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -204,7 +204,27 @@ (ert-deftest test-ob/simple-variable-resolution () (forward-line 5) (should (string= ": 4" (buffer-substring (point-at-bol) - (point-at-eol)))))) + (point-at-eol))))) + ;; Test reading lists. + (org-test-with-temp-text-in-file " + +#+NAME: example-list +- simple + - not + - nested +- list + +#+BEGIN_SRC emacs-lisp :var x=example-list +(print x) +#+END_SRC" + + (should (equal '("simple" "list") (org-babel-execute-src-block))) + (forward-line 5) + (should (string= + "| simple | list |" + (buffer-substring + (point-at-bol) + (point-at-eol)))))) (ert-deftest test-ob/block-content-resolution () "Test block content resolution." @@ -218,8 +238,8 @@ (ert-deftest test-ob/block-content-resolution () #+begin_src emacs-lisp :var four=four[] (length (eval (car (read-from-string four)))) #+end_src" - (org-babel-next-src-block 2) - (should (= 4 (org-babel-execute-src-block))))) + (org-babel-next-src-block 2) + (should (= 4 (org-babel-execute-src-block))))) (ert-deftest test-ob/cons-cell-as-variable () "Test that cons cell can be assigned as variable." -- 2.35.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--