|
@@ -42,6 +42,23 @@
|
|
|
(defvar org-babel-default-header-args:shell '())
|
|
|
(defvar org-babel-shell-names)
|
|
|
|
|
|
+(defconst org-babel-shell-set-prompt-commands
|
|
|
+ '(("fish" . "function fish_prompt\n\techo \"%s\"\nend")
|
|
|
+ ("csh" . "set prompt=\"%s\"")
|
|
|
+ ("posh" . "function prompt { \"%s\" }")
|
|
|
+ (t . "PS1=\"%s\""))
|
|
|
+ "Alist assigning shells with their prompt setting command.
|
|
|
+
|
|
|
+Each element of the alist associates a shell type from
|
|
|
+`org-babel-shell-names' with a template used to create a command to
|
|
|
+change the default prompt. The template is an argument to `format'
|
|
|
+that will be called with a single additional argument: prompt string.
|
|
|
+
|
|
|
+The fallback association template is defined in (t . \"template\")
|
|
|
+alist element.")
|
|
|
+
|
|
|
+(defvar org-babel-prompt-command)
|
|
|
+
|
|
|
(defun org-babel-shell-initialize ()
|
|
|
"Define execution functions associated to shell names.
|
|
|
This function has to be called whenever `org-babel-shell-names'
|
|
@@ -51,7 +68,10 @@ is modified outside the Customize interface."
|
|
|
(eval `(defun ,(intern (concat "org-babel-execute:" name))
|
|
|
(body params)
|
|
|
,(format "Execute a block of %s commands with Babel." name)
|
|
|
- (let ((shell-file-name ,name))
|
|
|
+ (let ((shell-file-name ,name)
|
|
|
+ (org-babel-prompt-command
|
|
|
+ (or (alist-get ,name org-babel-shell-set-prompt-commands)
|
|
|
+ (alist-get t org-babel-shell-set-prompt-commands))))
|
|
|
(org-babel-execute:shell body params))))
|
|
|
(eval `(defalias ',(intern (concat "org-babel-variable-assignments:" name))
|
|
|
'org-babel-variable-assignments:shell
|
|
@@ -206,6 +226,13 @@ var of the same value."
|
|
|
(mapconcat echo-var var "\n"))
|
|
|
(t (funcall echo-var var)))))
|
|
|
|
|
|
+(defvar org-babel-sh-eoe-indicator "echo 'org_babel_sh_eoe'"
|
|
|
+ "String to indicate that evaluation has completed.")
|
|
|
+(defvar org-babel-sh-eoe-output "org_babel_sh_eoe"
|
|
|
+ "String to indicate that evaluation has completed.")
|
|
|
+(defvar org-babel-sh-prompt "org_babel_sh_prompt> "
|
|
|
+ "String to set prompt in session shell.")
|
|
|
+
|
|
|
(defun org-babel-sh-initiate-session (&optional session _params)
|
|
|
"Initiate a session named SESSION according to PARAMS."
|
|
|
(when (and session (not (string= session "none")))
|
|
@@ -213,17 +240,20 @@ var of the same value."
|
|
|
(or (org-babel-comint-buffer-livep session)
|
|
|
(progn
|
|
|
(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 org-babel-prompt-command org-babel-sh-prompt))
|
|
|
+ (setq-local comint-prompt-regexp
|
|
|
+ (concat "^" (regexp-quote org-babel-sh-prompt)
|
|
|
+ " *"))
|
|
|
;; Needed for Emacs 23 since the marker is initially
|
|
|
;; undefined and the filter functions try to use it without
|
|
|
;; checking.
|
|
|
(set-marker comint-last-output-start (point))
|
|
|
(get-buffer (current-buffer)))))))
|
|
|
|
|
|
-(defvar org-babel-sh-eoe-indicator "echo 'org_babel_sh_eoe'"
|
|
|
- "String to indicate that evaluation has completed.")
|
|
|
-(defvar org-babel-sh-eoe-output "org_babel_sh_eoe"
|
|
|
- "String to indicate that evaluation has completed.")
|
|
|
-
|
|
|
(defun org-babel-sh-evaluate (session body &optional params stdin cmdline)
|
|
|
"Pass BODY to the Shell process in BUFFER.
|
|
|
If RESULT-TYPE equals `output' then return a list of the outputs
|