From 7c21098323bf0097c7903b014564cd6056bda374 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 16 Nov 2011 06:15:31 -0700 Subject: [PATCH] Don't match partial names when resolving code or data references * lisp/ob.el (org-babel-named-src-block-regexp-for-name): Ensure that partial names are not matched. (org-babel-named-data-regexp-for-name): Ensure that partial names are not matched. * testing/lisp/test-ob.el (test-ob/do-not-resolve-to-partial-names-data): Test to ensure that partial names are not matched. --- lisp/ob.el | 5 +++-- testing/lisp/test-ob.el | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index 5e721ba41..26a3af718 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -433,12 +433,13 @@ can not be resolved.") (defun org-babel-named-src-block-regexp-for-name (name) "This generates a regexp used to match a src block named NAME." - (concat org-babel-src-name-regexp (regexp-quote name) "[ \t\n]*" + (concat org-babel-src-name-regexp (regexp-quote name) + "\\([ \t]\\|$\\|(\\)" ".*[\r\n]" (substring org-babel-src-block-regexp 1))) (defun org-babel-named-data-regexp-for-name (name) "This generates a regexp used to match data named NAME." - (concat org-babel-result-regexp (regexp-quote name) "[ \t]*.*$")) + (concat org-babel-result-regexp (regexp-quote name) "\\([ \t]\\|$\\)")) ;;; functions (defvar call-process-region) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index c993fbef8..d145f4e3a 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -463,6 +463,40 @@ on two lines (org-babel-next-src-block 2) (should (string= (org-babel-execute-src-block) "baz")))) +(ert-deftest test-ob/do-not-resolve-to-partial-names-data () + (org-test-with-temp-text " +#+tblname: base_plus +| 1 | +| 2 | + +#+tblname: base +| 3 | +| 4 | + +#+begin_src emacs-lisp :var x=base + x +#+end_src" + (org-babel-next-src-block 1) + (should (equal (org-babel-execute-src-block) '((3) (4)))))) + +(ert-deftest test-ob/do-not-resolve-to-partial-names-code () + (org-test-with-temp-text " +#+name: base_plus +#+begin_src emacs-lisp + 'bar +#+end_src + +#+name: base +#+begin_src emacs-lisp + 'foo +#+end_src + +#+begin_src emacs-lisp :var x=base + x +#+end_src" + (org-babel-next-src-block 3) + (should (equal (org-babel-execute-src-block) "foo")))) + (provide 'test-ob) ;;; test-ob ends here