Skip to content

Commit 66fa8fe

Browse files
ElleNajtclaude
andcommitted
Fix run-cell-and-advance to work with async execution
Find next Python block BEFORE executing current block, using a marker. This prevents async result insertion from moving point back to the executed block. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0b506de commit 66fa8fe

1 file changed

Lines changed: 15 additions & 25 deletions

File tree

ob-python-extras.el

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,36 +100,26 @@
100100
(defun ob-python-extras/run-cell-and-advance ()
101101
"Execute current source block and advance to next Python block."
102102
(interactive)
103-
(org-babel-execute-src-block)
104-
(let ((start-pos (point))
105-
(found nil)
103+
;; Find next Python block BEFORE executing (so async doesn't interfere)
104+
(let ((next-block-marker nil)
106105
(iterations 0))
107106
(save-excursion
108-
(while (and (not found)
109-
(< iterations 10) ; Safety limit
110-
(condition-case err
111-
(progn
112-
(org-babel-next-src-block)
113-
114-
t)
115-
(error
116-
117-
nil)))
107+
(while (and (not next-block-marker)
108+
(< iterations 10)
109+
(condition-case nil
110+
(progn (org-babel-next-src-block) t)
111+
(error nil)))
118112
(setq iterations (1+ iterations))
119-
(let* ((element (org-element-at-point))
120-
(element-type (org-element-type element))
121-
(info (org-babel-get-src-block-info))
113+
(let* ((info (org-babel-get-src-block-info))
122114
(lang (car info)))
123-
124115
(when (and lang (string= lang "python"))
125-
126-
(setq found (point))))))
127-
128-
(when found
129-
130-
(goto-char found))
131-
(unless found
132-
)))
116+
(setq next-block-marker (point-marker))))))
117+
;; Execute current block
118+
(org-babel-execute-src-block)
119+
;; Move to next block if found
120+
(when next-block-marker
121+
(goto-char next-block-marker)
122+
(set-marker next-block-marker nil))))
133123

134124
;;;; Cell timing and error handling
135125

0 commit comments

Comments
 (0)