org-babel-tangle-single-block: Do not rely on match-data from `org-back-to-heading'

* lisp/ob-tangle.el (org-babel-tangle-single-block): Explicitly move
to the beginning of title instead of assuming that
`org-back-to-heading' sets match data appropriately (it is not
documented to do so).
* testing/lisp/test-ob-tangle.el (ob-tangle/comment-org): Add test.

Reported-by: Nick Dokos <ndokos@redhat.com>
Link: https://orgmode.org/list/87bkh8k3at.fsf@alphaville.usersys.redhat.com
This commit is contained in:
Ihor Radchenko 2023-06-22 12:54:23 +03:00
parent 7b3b7b92e7
commit 79ec91584c
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 18 additions and 1 deletions

View File

@ -571,7 +571,7 @@ non-nil, return the full association list to be used by
(max (condition-case nil
(save-excursion
(org-back-to-heading t) ; Sets match data
(match-end 0))
(re-search-forward org-outline-regexp))
(error (point-min)))
(save-excursion
(if (re-search-backward

View File

@ -99,6 +99,23 @@ echo 1
(buffer-string)))
(delete-file "test-ob-tangle.sh"))))))
(ert-deftest ob-tangle/comment-org ()
"Test :commends org."
(should
(string-match
(regexp-quote ";; Function heading")
(org-test-with-temp-text-in-file
"* Function heading
#+begin_src elisp :tangle \"test-ob-tange.el\" :comments org
(message \"FOO\")
#+end_src"
(unwind-protect
(progn (org-babel-tangle)
(with-temp-buffer (insert-file-contents "test-ob-tange.el")
(buffer-string)))
(delete-file "test-ob-tange.el"))))))
(ert-deftest ob-tangle/comment-links-numbering ()
"Test numbering of source blocks when commenting with links."
(should