branch: externals/org
commit 9fd547dd3a16c473b2109bfd7bad7f1cb015a5b2
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    org-babel-where-is-src-block-result: Fix inside affiliated parsed keyword
    
    * lisp/ob-core.el (org-babel-where-is-src-block-result): Do not assume
    that parent has contents-end and that we are inside contents, but not
    inside secondary object/affiliated keyword.
    *
    testing/lisp/test-ob.el 
(test-ob/inline-src_blk-default-results-replace-line-1):
    Add tests.
    
    Reported-by: Tom Gillespie <tgb...@gmail.com>
    Link: 
https://orgmode.org/list/ca+g3_pnt7wqkczchv+dx1fespgtevknse41a3qc5wv3g+jt...@mail.gmail.com
---
 lisp/ob-core.el         |  7 ++-----
 testing/lisp/test-ob.el | 16 +++++++++++++++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 13e1ef49ae..abf48dd649 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2187,11 +2187,8 @@ to HASH."
         ((or `inline-babel-call `inline-src-block)
          ;; Results for inline objects are located right after them.
          ;; There is no RESULTS line to insert either.
-         (let ((limit (pcase (org-element-type (org-element-parent context))
-                         (`section (org-element-end
-                                    (org-element-parent context)))
-                         (_ (org-element-contents-end
-                            (org-element-parent context))))))
+         (let ((limit (or (org-element-contents-end (org-element-parent 
context))
+                           (org-element-end (org-element-parent context)))))
            (goto-char (org-element-end context))
            (skip-chars-forward " \t\n" limit)
            (throw :found
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index c8dbd44f44..42c77ca56c 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -404,7 +404,21 @@ at the beginning of a line."
       "src_emacs-lisp{(+ 1 2)}\n{{{results(=3=)}}}"
       (org-test-with-temp-text "src_emacs-lisp{(+ 1 2)}\n{{{results(=2=)}}}"
        (let ((org-babel-inline-result-wrap "=%s=")) (org-babel-execute-maybe))
-       (buffer-string))))))
+       (buffer-string)))))
+  ;; Handle inline src blocks inside parsed affiliated keyword.
+  (should
+   (equal
+    "#+caption: src_elisp{1} {{{results(=1=)}}}\n#+begin_src 
emacs-lisp\n1\n#+end_src"
+    (org-test-with-temp-text "#+caption: <point>src_elisp{1}\n#+begin_src 
emacs-lisp\n1\n#+end_src"
+      (let ((org-babel-inline-result-wrap "=%s=")) (org-babel-execute-maybe))
+      (buffer-string))))
+  ;; Handle inline src blocks inside heading title.
+  (should
+   (equal
+    "* Heading src_elisp{1} {{{results(=1=)}}}"
+    (org-test-with-temp-text "* Heading <point>src_elisp{1}"
+      (let ((org-babel-inline-result-wrap "=%s=")) (org-babel-execute-maybe))
+      (buffer-string)))))
 
 (ert-deftest test-ob/inline-src_blk-default-results-replace-line-2 ()
   ;; src_ at bol line 2...

Reply via email to