From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vladimir Panteleev Subject: [PATCH 2/3] ob-table: Fix org-sbe's handling of list arguments Date: Wed, 7 Mar 2018 22:58:46 +0000 Message-ID: <20180307225847.24068-3-git@thecybershadow.net> References: <20180307225847.24068-1-git@thecybershadow.net> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eti1V-0001aV-3J for emacs-orgmode@gnu.org; Wed, 07 Mar 2018 17:59:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eti1R-0000sR-Sy for emacs-orgmode@gnu.org; Wed, 07 Mar 2018 17:59:01 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38628) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eti1R-0000s3-LK for emacs-orgmode@gnu.org; Wed, 07 Mar 2018 17:58:57 -0500 Received: by mail-wm0-f65.google.com with SMTP id z9so7677681wmb.3 for ; Wed, 07 Mar 2018 14:58:57 -0800 (PST) In-Reply-To: <20180307225847.24068-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 | 20 ++++++++++++++++++++ 2 files changed, 31 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 725cf6bdd..40cc877d8 100644 --- a/testing/lisp/test-ob-table.el +++ b/testing/lisp/test-ob-table.el @@ -40,6 +40,26 @@ (should (equal "a\"b\"c" (eval '(org-sbe identity (x $ "a\"b\"c"))))))) +(ert-deftest test-ob-table/sbe-list () + "Test that `org-sbe' can correctly handle list arguments." + (org-test-with-temp-text-in-file " +#+name: concat +#+begin_src emacs-lisp :eval yes + (mapconcat #'identity x \"\") +#+end_src" + (should (equal "foobar" + (eval '(org-sbe concat (x '("foo" "bar")))))))) + +(ert-deftest test-ob-table/sbe-$-list () + "Test that `org-sbe' can correctly handle $-prefixed list arguments." + (org-test-with-temp-text-in-file " +#+name: concat +#+begin_src emacs-lisp :eval yes + (mapconcat #'identity x \"\") +#+end_src" + (should (equal "foobar" + (eval '(org-sbe concat (x $ '("foo" "bar")))))))) + (provide 'test-ob-table) ;;; test-ob-table.el ends here -- 2.16.2