From d526ab538889f04afe7afcea6abafd20dc7fcfde Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Fri, 29 Dec 2023 08:43:24 -0800 Subject: [PATCH] fixup! ob-python: Test and improve robustness for externally started python * lisp/ob-python.el (org-babel-python--python-util-comint-end-of-output-p): Backport python-util-comint-end-of-output-p for emacs28. (org-babel-python-initiate-session-by-key): Use backported version of python-util-comint-end-of-output-p. --- lisp/ob-python.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 8963d2f24..6b3a608c8 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -237,6 +237,15 @@ results as a string." (substring name 1 (- (length name) 1)) name))) +(defun org-babel-python--python-util-comint-end-of-output-p () + "Return non-nil if the last prompt matches input prompt. +Backport of `python-util-comint-end-of-output-p' to emacs28. To +be removed after minimum supported version reaches emacs29." + (when-let ((prompt (python-util-comint-last-prompt))) + (python-shell-comint-end-of-output-p + (buffer-substring-no-properties + (car prompt) (cdr prompt))))) + (defvar-local org-babel-python--initialized nil "Flag used to mark that python session has been initialized.") (defun org-babel-python--setup-session () @@ -272,7 +281,7 @@ initialized session." (unless org-babel-python--initialized ;; Ensure first prompt. Based on python-tests.el ;; (`python-tests-shell-wait-for-prompt') - (while (not (python-util-comint-end-of-output-p)) + (while (not (org-babel-python--python-util-comint-end-of-output-p)) (sit-for 0.1)) (org-babel-python--setup-session)) ;; Adding to `python-shell-first-prompt-hook' immediately