Skip to content

Commit e12e026

Browse files
ElleNajtclaude
andcommitted
Make ob-python-extras-execute-org-file run in background
Spawns emacs --batch process so it doesn't block the main Emacs. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0d710ac commit e12e026

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

ob-python-extras.el

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,18 +1030,36 @@ print = __original_print"
10301030
(alert (format "Finished processing %s" file))))))))))
10311031

10321032
(defun ob-python-extras-execute-org-file (file)
1033-
"Execute all Python blocks in FILE and save results.
1033+
"Execute all Python blocks in FILE in a background Emacs process.
10341034
Can be called via emacsclient:
10351035
emacsclient --eval '(ob-python-extras-execute-org-file \"/path/to/file.org\")'"
10361036
(interactive "fOrg file: ")
1037-
(let ((file (expand-file-name file)))
1037+
(let* ((file (expand-file-name file))
1038+
(ob-python-extras-lib (locate-library "ob-python-extras"))
1039+
(python-scripts-dir (ob-python-extras/find-python-scripts-dir))
1040+
(process-name (format "org-execute-%s" (file-name-base file))))
10381041
(unless (file-exists-p file)
10391042
(error "File does not exist: %s" file))
1040-
(with-current-buffer (find-file-noselect file)
1041-
(setq org-confirm-babel-evaluate nil)
1042-
(org-babel-execute-buffer)
1043-
(save-buffer)
1044-
(message "Executed and saved: %s" file))))
1043+
(message "Starting background execution of %s..." file)
1044+
(start-process
1045+
process-name "*org-execute*"
1046+
"emacs" "--batch"
1047+
"--eval" (format "(setq ob-python-extras-python-path \"%s\")" python-scripts-dir)
1048+
"-l" ob-python-extras-lib
1049+
"--eval"
1050+
(format "(progn
1051+
(require 'ob-python)
1052+
(setq org-confirm-babel-evaluate nil)
1053+
(find-file \"%s\")
1054+
(org-babel-execute-buffer)
1055+
(save-buffer)
1056+
(message \"Done: %s\")
1057+
(kill-emacs 0))" file file))
1058+
(set-process-sentinel
1059+
(get-process process-name)
1060+
(lambda (process event)
1061+
(when (string-match "finished" event)
1062+
(message "Finished executing: %s" file))))))
10451063

10461064
(provide 'ob-python-extras)
10471065
;;; ob-python-extras.el ends here

0 commit comments

Comments
 (0)