Hi, `org-babel-tangle-jump-to-org’ – and therefore `org-babel-detangle’ and the tangle-sync machinery built on it – signals “Not in tangled code” whenever a tangled block’s *body* contains a literal `[[...]]' Org bracket link.
Tested with Org 9.8.4 on Emacs 30.1. Reproduction ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― 1. test.org: ┌──── │ #+begin_src emacs-lisp :tangle test.el :comments link │ (message "see [[file:foo.org][foo]]") │ (message "second line") │ #+end_src └──── 1. Tangle it (C-c C-v t). The resulting test.el is: ┌──── │ ;; [[file:test.org::*Heading][Heading:1]] │ (message "see [[file:foo.org][foo]]") │ (message "second line") │ ;; Heading:1 ends here └──── 1. In test.el, move point onto the last body line and run M-x org-babel-tangle-jump-to-org (or M-x org-babel-detangle on the file). => error: “Not in tangled code” Cause ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― To delimit the block, `org-babel-tangle-jump-to-org’ searches backward for the enclosing `[[file:...][Name:N]]' comment. Its inner check discards the result of the “… ends here” search and sets END unconditionally: ┌──── │ (save-excursion │ (save-match-data │ (re-search-forward │ (concat " " (regexp-quote block-name) " ends here") nil t) │ (setq end (line-beginning-position)))) ; runs even when the search fails └──── So the in-body link `[[file:foo.org][foo]]' is accepted as the block delimiter, END collapses onto that line, and the subsequent guard (unless (and start (< start mid) (< mid end)) (error “Not in tangled code”)) fails because mid is no longer < end. Suggested fix ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― Only set END when the “ends here” marker is actually found, so a stray in-body link is rejected and the backward search widens to the real delimiter: ┌──── │ (and (re-search-forward │ (concat " " (regexp-quote block-name) " ends here") nil t) │ (setq end (line-beginning-position))) └──── With this change the backward search skips the in-body link and detangle/sync round-trips correctly. Thanks, Ben
