Thanks Ihor
On closer inspection, there is a larger error that (point) in the code
is the point in the org-mode buffer whereas mid, end and body-start
were calculated as positions inside the code block in the tangled
buffer. E.g. in my case the tangled buffer is stripped of titles,
headings, results etc.
The following works in my MWE but not sure if it will throw for
whatever reason. I send you a patch with
(let* ((el (org-element-at-point))
(org-block-size (length (org-element-property :value el)))
(offset (min org-block-size (- mid body-start)))
)
(forward-char offset))
that replaces
(let ((offset (- mid body-start)))
(when (> end (+ offset (point)))
(forward-char offset)))
Just before the forward-char, the point is at the beginning of the
body part of the block. So it will move by the intended offset in the
tangled file "mid - body-start" but not more than the size of the
block in org-mode.
George
PS. Resending to all.
On Sun, 1 Mar 2026 at 11:59, Ihor Radchenko <[email protected]> wrote:
>
> George Moutsopoulos <[email protected]> writes:
>
> > I try to work with the tangled file in order to be able to use
> > python-mode features. Eventually I detangle.
> >
> > The changes I make in each code block in the tangled source code file
> > are many and the code block will change in size. I believe this
> > creates a bug because of the following lines in
> > org-babel-tangle-jump-to-org
> >
> > ;; Try to preserve location of point within the source code in
> > ;; tangled code file.
> > (let ((offset (- mid body-start)))
> > (when (> end (+ offset (point)))
> > (forward-char offset)))
>
> Thanks for reporting!
> Would you be interested to fix this bug by providing a patch?
>
> --
> Ihor Radchenko // yantar92,
> Org mode maintainer,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
From acf69346f0a67a36457c9d42fe4adf92048ebed4 Mon Sep 17 00:00:00 2001
From: George Moutsopoulos <[email protected]>
Date: Mon, 2 Mar 2026 01:31:14 +0000
Subject: [PATCH] fixes offset in org-babel-tangle-jump-to-org
---
lisp/ob-tangle.el | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 6fe553469..62a10604d 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -720,9 +720,11 @@ of the current buffer."
(forward-line 1)
;; Try to preserve location of point within the source code in
;; tangled code file.
- (let ((offset (- mid body-start)))
- (when (> end (+ offset (point)))
- (forward-char offset)))
+ (let* ((el (org-element-at-point))
+ (org-block-size (length (org-element-property :value el)))
+ (offset (min org-block-size (- mid body-start)))
+ )
+ (forward-char offset))
(setq target-char (point)))
(org-src-switch-to-buffer target-buffer t)
(goto-char target-char)
--
2.43.0