From c950bb79ad515e53bdac3d79da7b4352aa264e8a Mon Sep 17 00:00:00 2001 Message-ID: In-Reply-To: References: From: Ihor Radchenko Date: Sun, 30 Jun 2024 20:37:36 +0200 Subject: [PATCH 2/4] ob-shell: Arrange unique prompt in manually started shell buffers * lisp/ob-shell.el (org-babel-sh--prompt-initialized): New variable flag that indicates whether ob-shell changed the prompt in current comint buffer. (org-babel-sh-initiate-session): Set unique prompt in existing sessions if it is not yet done. Link: https://orgmode.org/list/87o782gx7o.fsf@localhost --- lisp/ob-shell.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el index 9222379a3..7b0d6ddab 100644 --- a/lisp/ob-shell.el +++ b/lisp/ob-shell.el @@ -276,16 +276,25 @@ (defvar org-babel-sh-eoe-output "org_babel_sh_eoe" (defvar org-babel-sh-prompt "org_babel_sh_prompt> " "String to set prompt in session shell.") +(defvar-local org-babel-sh--prompt-initialized nil + "When non-nil, ob-shell already initialized the prompt in current buffer.") + (defalias 'org-babel-shell-initiate-session #'org-babel-sh-initiate-session) (defun org-babel-sh-initiate-session (&optional session _params) "Initiate a session named SESSION according to PARAMS." (when (and session (not (string= session "none"))) (save-window-excursion - (or (org-babel-comint-buffer-livep session) + (or (and (org-babel-comint-buffer-livep session) + (buffer-local-value + 'org-babel-sh--prompt-initialized + (get-buffer session)) + session) (progn - (shell session) - ;; Set unique prompt for easier analysis of the output. - (org-babel-comint-wait-for-output (current-buffer)) + (if (org-babel-comint-buffer-livep session) + (set-buffer session) + (shell session) + ;; Set unique prompt for easier analysis of the output. + (org-babel-comint-wait-for-output (current-buffer))) (org-babel-comint-input-command (current-buffer) (format @@ -298,6 +307,7 @@ (defun org-babel-sh-initiate-session (&optional session _params) comint-prompt-regexp (concat "^" (regexp-quote org-babel-sh-prompt) " *")) + (setq org-babel-sh--prompt-initialized t) ;; Needed for Emacs 23 since the marker is initially ;; undefined and the filter functions try to use it without ;; checking. -- 2.45.2