summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-12-14 23:57:50 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-12-15 00:00:30 +0100
commit327ca051ae4631fea57427290bb16bf9174a4311 (patch)
treeede7102c3de73fd718707c2b84a8db11aacbed62
parentfe98379fce44927b2a25fc817a4da76f7eec866d (diff)
downloadorg-mode-327ca051ae4631fea57427290bb16bf9174a4311.tar.gz
ob-ref: Fix parsing arguments with a newline character
* lisp/ob-ref.el (org-babel-ref-split-regexp): Remove variable. (org-babel-ref-parse): Handle arguments containing a newline character (e.g., strings). * testing/lisp/test-ob-lob.el (test-ob-lob/assignment-with-newline): New test.
-rw-r--r--lisp/ob-ref.el21
-rw-r--r--testing/lisp/test-ob-lob.el25
2 files changed, 34 insertions, 12 deletions
diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el
index 323cdc7..b44aa1e 100644
--- a/lisp/ob-ref.el
+++ b/lisp/ob-ref.el
@@ -65,24 +65,21 @@
(declare-function org-show-context "org" (&optional key))
(declare-function org-trim "org" (s &optional keep-lead))
-(defvar org-babel-ref-split-regexp
- "[ \f\t\n\r\v]*\\(.+?\\)[ \f\t\n\r\v]*=[ \f\t\n\r\v]*\\(.+\\)[ \f\t\n\r\v]*")
-
(defvar org-babel-update-intermediate nil
"Update the in-buffer results of code blocks executed to resolve references.")
(defun org-babel-ref-parse (assignment)
"Parse a variable ASSIGNMENT in a header argument.
+
If the right hand side of the assignment has a literal value
-return that value, otherwise interpret as a reference to an
-external resource and find its value using
-`org-babel-ref-resolve'. Return a list with two elements. The
-first element of the list will be the name of the variable, and
-the second will be an emacs-lisp representation of the value of
-the variable."
- (when (string-match org-babel-ref-split-regexp assignment)
- (let ((var (match-string 1 assignment))
- (ref (match-string 2 assignment)))
+return that value, otherwise interpret it as a reference to an
+external resource and find its value using `org-babel-ref-resolve'.
+
+Return a list with two elements: the name of the variable, and an
+Emacs Lisp representation of the value of the variable."
+ (when (string-match "\\(.+?\\)=" assignment)
+ (let ((var (org-trim (match-string 1 assignment)))
+ (ref (org-trim (substring assignment (match-end 0)))))
(cons (intern var)
(let ((out (save-excursion
(when org-babel-current-src-block-location
diff --git a/testing/lisp/test-ob-lob.el b/testing/lisp/test-ob-lob.el
index bb933b4..49f1f24 100644
--- a/testing/lisp/test-ob-lob.el
+++ b/testing/lisp/test-ob-lob.el
@@ -168,6 +168,31 @@ for export
(should
(eq (org-babel-execute-src-block nil (org-babel-lob-get-info)) 1)))))
+(ert-deftest test-ob-lob/assignment-with-newline ()
+ "Test call lines with an argument containing a newline character."
+ (should
+ (equal " foo"
+ (org-test-with-temp-text "
+#+name: test-newline
+#+begin_src emacs-lisp :var x=\"a\"
+'foo
+#+end_src
+
+call_test-newline[:eval yes :results raw](\"a\nb\")<point>"
+ (org-babel-execute-src-block nil (org-babel-lob-get-info))
+ (buffer-substring (point) (point-max)))))
+ (should
+ (equal " bar"
+ (org-test-with-temp-text "
+#+name: test-newline
+#+begin_src emacs-lisp :var x=\"a\"
+'bar
+#+end_src
+
+call_test-newline[:eval yes :results raw]('(1\n2))<point>"
+ (org-babel-execute-src-block nil (org-babel-lob-get-info))
+ (buffer-substring (point) (point-max))))))
+
(provide 'test-ob-lob)
;;; test-ob-lob.el ends here