From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vladimir Panteleev Subject: [PATCH v2 2/3] ob-table: Fix org-sbe's handling of list arguments Date: Mon, 19 Mar 2018 00:23:13 +0000 Message-ID: <20180319002314.8162-3-git@thecybershadow.net> References: <20180319002314.8162-1-git@thecybershadow.net> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exiaK-0002ja-Ak for emacs-orgmode@gnu.org; Sun, 18 Mar 2018 20:23:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exiaI-0000bl-4O for emacs-orgmode@gnu.org; Sun, 18 Mar 2018 20:23:32 -0400 Received: from mail-wr0-f174.google.com ([209.85.128.174]:47000) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1exiaH-0000a4-UL for emacs-orgmode@gnu.org; Sun, 18 Mar 2018 20:23:30 -0400 Received: by mail-wr0-f174.google.com with SMTP id s10so4018451wra.13 for ; Sun, 18 Mar 2018 17:23:29 -0700 (PDT) In-Reply-To: <20180319002314.8162-1-git@thecybershadow.net> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Cc: Vladimir Panteleev * ob-table.el (org-sbe): Add an explicit case for handling list arguments. This avoids doing the wrong thing (%s-formatting a list, thus losing syntax like double-quotes). This enables passing org-table ranges through org-sbe in a simple and correct manner. * test-ob-table.el: Add test. --- lisp/ob-table.el | 17 +++++++++++------ testing/lisp/test-ob-table.el | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lisp/ob-table.el b/lisp/ob-table.el index 105aca5e2..17810dd74 100644 --- a/lisp/ob-table.el +++ b/lisp/ob-table.el @@ -132,12 +132,17 @@ as shown in the example below. "(" (mapconcat (lambda (var-spec) - (if (> (length (cdr var-spec)) 1) - (format "%S='%S" - (car var-spec) - (mapcar #'read (cdr var-spec))) - (format "%S=%s" - (car var-spec) (cadr var-spec)))) + (cond + ((> (length (cdr var-spec)) 1) + (format "%S='%S" + (car var-spec) + (mapcar #'read (cdr var-spec)))) + ((stringp (cadr var-spec)) + (format "%S=%s" + (car var-spec) (cadr var-spec))) + (t + (format "%S=%S" + (car var-spec) (cadr var-spec))))) ',variables ", ") ")"))))) (org-babel-execute-src-block diff --git a/testing/lisp/test-ob-table.el b/testing/lisp/test-ob-table.el index 3d9b1d160..fb6d05796 100644 --- a/testing/lisp/test-ob-table.el +++ b/testing/lisp/test-ob-table.el @@ -52,6 +52,29 @@ 1 "#+TBLFM: $2 = '(org-sbe identity (x $$1))")) +(ert-deftest test-ob-table/sbe-list () + "Test that `org-sbe' can correctly handle ranges as lists." + (org-test-table-target-expect + " +#+name: concat +#+begin_src emacs-lisp :eval yes + (mapconcat #'identity x \"\") +#+end_src + +| foo | bar | replace | +" + " +#+name: concat +#+begin_src emacs-lisp :eval yes + (mapconcat #'identity x \"\") +#+end_src + +| foo | bar | foobar | +" + 1 + "#+TBLFM: $3 = '(org-sbe concat (x (list $1..$2)))" + "#+TBLFM: $3 = '(org-sbe concat (x $ (list $1..$2)))")) + (provide 'test-ob-table) ;;; test-ob-table.el ends here -- 2.16.2