Function: term-exec
term-exec is a byte-compiled function defined in term.el.gz.
Signature
(term-exec BUFFER NAME COMMAND STARTFILE SWITCHES)
Documentation
Start up a process in buffer for term modes.
Blasts any old process running in the buffer. Doesn't set the buffer mode.
You can use this to cheaply run a series of processes in the same term
buffer. The hook term-exec-hook is run after each exec.
Source Code
;; Defined in /usr/src/emacs/lisp/term.el.gz
(defun term-exec (buffer name command startfile switches)
"Start up a process in buffer for term modes.
Blasts any old process running in the buffer. Doesn't set the buffer mode.
You can use this to cheaply run a series of processes in the same term
buffer. The hook `term-exec-hook' is run after each exec."
(with-current-buffer buffer
(let ((proc (get-buffer-process buffer))) ; Blast any old process.
(when proc (delete-process proc)))
;; Crank up a new process
(let ((proc (term-exec-1 name buffer command switches)))
(setq-local term-ptyp process-connection-type) ; t if pty, nil if pipe.
;; Jump to the end, and set the process mark.
(goto-char (point-max))
(set-marker (process-mark proc) (point))
(set-process-filter proc #'term-emulate-terminal)
(set-process-sentinel proc #'term-sentinel)
;; Feed it the startfile.
(when startfile
;;This is guaranteed to wait long enough
;;but has bad results if the term does not prompt at all
;; (while (= size (buffer-size))
;; (sleep-for 1))
;;I hope 1 second is enough!
(sleep-for 1)
(goto-char (point-max))
(insert-file-contents startfile)
(term-send-string
proc (delete-and-extract-region (point) (point-max)))))
(run-hooks 'term-exec-hook)
buffer))