diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-03-18 10:28:15 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2017-03-18 10:28:15 +0100 |
commit | b72920344f7c940701b85aa157e1a1c88d93e4fd (patch) | |
tree | 43cb229a8595562e66491360f5fb2b16c6139f40 | |
parent | d262ae53c966c7a745c0fa779149f9eb7486333d (diff) | |
download | org-mode-b72920344f7c940701b85aa157e1a1c88d93e4fd.tar.gz |
ob-exp: Fix export of src blocks with pathological name
* lisp/ob-exp.el (org-babel-exp-process-buffer): Discard false
positives.
* testing/lisp/test-ob-exp.el (ob-exp/src-block-with-affiliated-keyword):
New test.
Reported-by: Skip Collins <skip.collins@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/112797>
-rw-r--r-- | lisp/ob-exp.el | 20 | ||||
-rw-r--r-- | testing/lisp/test-ob-exp.el | 12 |
2 files changed, 30 insertions, 2 deletions
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 95853a6..2556362 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -159,8 +159,24 @@ this template." (goto-char (point-min)) (while (re-search-forward regexp nil t) (unless (save-match-data (org-in-commented-heading-p)) - (let* ((element (save-match-data (org-element-context))) - (type (org-element-type element)) + (let* ((object? (match-end 1)) + (element (save-match-data + (if object? (org-element-context) + ;; No deep inspection if we're + ;; just looking for an element. + (org-element-at-point)))) + (type + (pcase (org-element-type element) + ;; Discard block elements if we're looking + ;; for inline objects. False results + ;; happen when, e.g., "call_" syntax is + ;; located within affiliated keywords: + ;; + ;; #+name: call_src + ;; #+begin_src ... + ((and (or `babel-call `src-block) (guard object?)) + nil) + (type type))) (begin (copy-marker (org-element-property :begin element))) (end diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el index 744234c..982b26c 100644 --- a/testing/lisp/test-ob-exp.el +++ b/testing/lisp/test-ob-exp.el @@ -584,6 +584,18 @@ src_emacs-lisp{(+ 1 1)}" (org-babel-exp-process-buffer)) (buffer-string))))) +(ert-deftest ob-exp/src-block-with-affiliated-keyword () + "Test exporting a code block with affiliated keywords." + ;; Pathological case: affiliated keyword matches inline src block + ;; syntax. + (should + (equal "#+name: call_foo\n#+BEGIN_SRC emacs-lisp\n42\n#+END_SRC" + (org-test-with-temp-text + "#+name: call_foo\n#+BEGIN_SRC emacs-lisp\n42\n#+END_SRC" + (let ((org-export-use-babel t)) + (org-babel-exp-process-buffer)) + (buffer-string))))) + (provide 'test-ob-exp) |