Function: eshell-close-target
eshell-close-target is a byte-compiled function defined in
esh-io.el.gz.
Signature
(eshell-close-target TARGET STATUS)
Documentation
Close an output TARGET, passing STATUS as the result.
STATUS should be non-nil on successful termination of the output.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/esh-io.el.gz
(defun eshell-close-target (target status)
"Close an output TARGET, passing STATUS as the result.
STATUS should be non-nil on successful termination of the output."
(cond
((symbolp target) nil)
;; If we were redirecting to a file, save the file and close the
;; buffer.
((markerp target)
(let ((buf (marker-buffer target)))
(when buf ; somebody's already killed it!
(save-current-buffer
(set-buffer buf)
(when eshell-output-file-buffer
(save-buffer)
(when (eq eshell-output-file-buffer t)
(or status (set-buffer-modified-p nil))
(kill-buffer buf)))))))
;; If we're redirecting to a process (via a pipe, or process
;; redirection), send it EOF so that it knows we're finished.
((eshell-processp target)
;; According to POSIX.1-2017, section 11.1.9, when communicating
;; via terminal, sending EOF causes all bytes waiting to be read
;; to be sent to the process immediately. Thus, if there are any
;; bytes waiting, we need to send EOF twice: once to flush the
;; buffer, and a second time to cause the next read() to return a
;; size of 0, indicating end-of-file to the reading process.
;; However, some platforms (e.g. Solaris) actually require sending
;; a *third* EOF. Since sending extra EOFs while the process is
;; running are a no-op, we'll just send the maximum we'd ever
;; need. See bug#56025 for further details.
(let ((i 0)
;; Only call `process-send-eof' once if communicating via a
;; pipe (in truth, this just closes the pipe).
(max-attempts (if (process-tty-name target 'stdin) 3 1)))
(while (and (<= (cl-incf i) max-attempts)
(eq (process-status target) 'run))
(process-send-eof target))))
;; A plain function redirection needs no additional arguments
;; passed.
((functionp target)
(funcall target status))
;; But a more complicated function redirection (which can only
;; happen with aliases at the moment) has arguments that need to be
;; passed along with it.
((consp target)
(apply (car target) status (cdr target)))))