From 82c0f9bf69966f9d5737baa98f068725c82af2c4 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 20 Nov 2011 09:40:08 -0700 Subject: [PATCH] Allow spaces around "=" in code block variable specifications * lisp/ob.el (org-babel-join-splits-near-ch): Rejoins a list of a split string when a character appears on either side of the split. (org-babel-parse-multiple-vars): Rejoin splits around "=" signs. --- lisp/ob.el | 15 ++++++++++++++- testing/lisp/test-ob.el | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lisp/ob.el b/lisp/ob.el index 26a3af718..33013b817 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1151,6 +1151,18 @@ instances of \"[ \t]:\" set ALTS to '((32 9) . 58)." (string-to-list string)) (nreverse (cons (apply #'string (nreverse partial)) lst))))) +(defun org-babel-join-splits-near-ch (ch list) + "Join splits where \"=\" is on either end of the split." + (flet ((last= (str) (= ch (aref str (1- (length str))))) + (first= (str) (= ch (aref str 0)))) + (reverse + (org-reduce (lambda (acc el) + (let ((head (car acc))) + (if (and head (or (last= head) (first= el))) + (cons (concat head el) (cdr acc)) + (cons el acc)))) + list :initial-value nil)))) + (defun org-babel-parse-header-arguments (arg-string) "Parse a string of header arguments returning an alist." (when (> (length arg-string) 0) @@ -1179,7 +1191,8 @@ shown below. (mapc (lambda (pair) (if (eq (car pair) :var) (mapcar (lambda (v) (push (cons :var (org-babel-trim v)) results)) - (org-babel-balanced-split (cdr pair) 32)) + (org-babel-join-splits-near-ch + 61 (org-babel-balanced-split (cdr pair) 32))) (push pair results))) header-arguments) (nreverse results))) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index d145f4e3a..47d3b16af 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -497,6 +497,13 @@ on two lines (org-babel-next-src-block 3) (should (equal (org-babel-execute-src-block) "foo")))) +(ert-deftest test-ob/allow-spaces-around-=-in-var-specs () + (org-test-with-temp-text "#+begin_src emacs-lisp :var a = 1 b = 2 c= 3 d =4 + (+ a b c d) +#+end_src +" + (should (= 10 (org-babel-execute-src-block))))) + (provide 'test-ob) ;;; test-ob ends here