From 327ca051ae4631fea57427290bb16bf9174a4311 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 14 Dec 2017 23:57:50 +0100 Subject: [PATCH] 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. --- lisp/ob-ref.el | 21 +++++++++------------ testing/lisp/test-ob-lob.el | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index 323cdc7ef..b44aa1e9d 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 bb933b4fd..49f1f24fb 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\")" + (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))" + (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