1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-21 06:55:35 +00:00

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
This commit is contained in:
Ihor Radchenko 2024-06-30 20:37:36 +02:00
parent 5ebe761ae4
commit 76c5f2238f
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B

View File

@ -276,16 +276,25 @@ var of the same value."
(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 @@ var of the same value."
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.