emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [BUG] org-babel: Binding a cons in var header arg yields error [9.4.5 (9.4.5-g914fe8 @ /home/yantar92/.emacs.d/straight/build/org/)]
Date: Thu, 20 May 2021 19:09:36 +0800	[thread overview]
Message-ID: <877djtvez3.fsf@localhost> (raw)

[-- Attachment #1: Type: text/plain, Size: 345 bytes --]

With the following org file on master:

#+name: gen
#+begin_src emacs-lisp
(cons 1 2)
#+end_src

#+header: :var inp=gen()
#+begin_src emacs-lisp
inp
#+end_src

C-c C-c on the second code block yields:
executing Emacs-Lisp code block (gen)...
(1 . 2)
org-babel-disassemble-tables: Wrong type argument: listp, 2

The fix is attached.

Best,
Ihor


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-var-header-args-to-be-assigned-to-cons-cells.patch --]
[-- Type: text/x-diff, Size: 2822 bytes --]

From 761c6227e82c6e9f4d6ee701eaa0b532ac9c7916 Mon Sep 17 00:00:00 2001
Message-Id: <761c6227e82c6e9f4d6ee701eaa0b532ac9c7916.1621508858.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Thu, 20 May 2021 19:01:06 +0800
Subject: [PATCH] Allow :var header args to be assigned to cons cells

* lisp/ob-core.el (org-babel-disassemble-tables,
org-babel-gnuplot-process-vars): Use `proper-list-p' check instead of
`listp'.
(org-babel-disassemble-tables): Check list length before trying to
remove hline from a table assignment.
* testing/lisp/test-ob.el (test-ob/cons-cell-as-variable): Add the
test.
---
 lisp/ob-core.el         |  5 +++--
 lisp/ob-gnuplot.el      |  2 +-
 testing/lisp/test-ob.el | 16 ++++++++++++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 857e03e55..c04bec9ae 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -1684,9 +1684,10 @@ (defun org-babel-disassemble-tables (vars hlines colnames rownames)
     (list
      (mapcar
       (lambda (var)
-        (when (listp (cdr var))
+        (when (proper-list-p (cdr var))
           (when (and (not (equal colnames "no"))
-                     (or colnames (and (eq (nth 1 (cdr var)) 'hline)
+                     (or colnames (and (length> (cdr var) 1)
+                                       (eq (nth 1 (cdr var)) 'hline)
                                        (not (member 'hline (cddr (cdr var)))))))
             (let ((both (org-babel-get-colnames (cdr var))))
               (setq cnames (cons (cons (car var) (cdr both))
diff --git a/lisp/ob-gnuplot.el b/lisp/ob-gnuplot.el
index a9b8e65e5..ea7d29c4e 100644
--- a/lisp/ob-gnuplot.el
+++ b/lisp/ob-gnuplot.el
@@ -87,7 +87,7 @@ (defun org-babel-gnuplot-process-vars (params)
        (cons
 	(car pair) ;; variable name
 	(let* ((val (cdr pair)) ;; variable value
-	       (lp  (listp val)))
+	       (lp  (proper-list-p val)))
 	  (if lp
 	      (org-babel-gnuplot-table-to-data
 	       (let* ((first  (car val))
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 88ecb62b5..a5ae8e389 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -178,6 +178,22 @@ (ert-deftest test-ob/simple-variable-resolution ()
 			    (point-at-bol)
 			    (point-at-eol))))))
 
+(ert-deftest test-ob/cons-cell-as-variable ()
+  "Test that cons cell can be assigned as variable."
+  (org-test-with-temp-text "
+
+#+name: cons
+#+begin_src emacs-lisp
+  (cons 1 2)
+#+end_src
+
+#+begin_src emacs-lisp :var x=cons
+  x
+#+end_src"
+
+    (org-babel-next-src-block 2)
+    (should (equal (cons 1 2) (org-babel-execute-src-block)))))
+
 (ert-deftest test-ob/multi-line-header-arguments ()
   "Test that multi-line header arguments and can be read."
   (org-test-with-temp-text-in-file "
-- 
2.26.3


                 reply	other threads:[~2021-05-20 11:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877djtvez3.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).