aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell/esh-io.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/eshell/esh-io.el')
-rw-r--r--lisp/eshell/esh-io.el50
1 files changed, 24 insertions, 26 deletions
diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el
index 68e52a2c9c8..27703976f6d 100644
--- a/lisp/eshell/esh-io.el
+++ b/lisp/eshell/esh-io.el
@@ -254,6 +254,30 @@ a nil value of mode defaults to `insert'."
254 (setq idx (1+ idx)))) 254 (setq idx (1+ idx))))
255 handles) 255 handles)
256 256
257(defun eshell-close-handles (&optional exit-code result handles)
258 "Close all of the current HANDLES, taking refcounts into account.
259If HANDLES is nil, use `eshell-current-handles'.
260
261EXIT-CODE is the process exit code (zero, if the command
262completed successfully). If nil, then use the exit code already
263set in `eshell-last-command-status'.
264
265RESULT is the quoted value of the last command. If nil, then use
266the value already set in `eshell-last-command-result'."
267 (when exit-code
268 (setq eshell-last-command-status exit-code))
269 (when result
270 (cl-assert (eq (car result) 'quote))
271 (setq eshell-last-command-result (cadr result)))
272 (let ((handles (or handles eshell-current-handles)))
273 (dotimes (idx eshell-number-of-handles)
274 (when-let ((handle (aref handles idx)))
275 (setcdr handle (1- (cdr handle)))
276 (when (= (cdr handle) 0)
277 (dolist (target (ensure-list (car (aref handles idx))))
278 (eshell-close-target target (= eshell-last-command-status 0)))
279 (setcar handle nil))))))
280
257(defun eshell-close-target (target status) 281(defun eshell-close-target (target status)
258 "Close an output TARGET, passing STATUS as the result. 282 "Close an output TARGET, passing STATUS as the result.
259STATUS should be non-nil on successful termination of the output." 283STATUS should be non-nil on successful termination of the output."
@@ -305,32 +329,6 @@ STATUS should be non-nil on successful termination of the output."
305 ((consp target) 329 ((consp target)
306 (apply (car target) status (cdr target))))) 330 (apply (car target) status (cdr target)))))
307 331
308(defun eshell-close-handles (exit-code &optional result handles)
309 "Close all of the current handles, taking refcounts into account.
310EXIT-CODE is the process exit code; mainly, it is zero, if the command
311completed successfully. RESULT is the quoted value of the last
312command. If nil, then the meta variables for keeping track of the
313last execution result should not be changed."
314 (let ((idx 0))
315 (cl-assert (or (not result) (eq (car result) 'quote)))
316 (setq eshell-last-command-status exit-code
317 eshell-last-command-result (cadr result))
318 (while (< idx eshell-number-of-handles)
319 (let ((handles (or handles eshell-current-handles)))
320 (when (aref handles idx)
321 (setcdr (aref handles idx)
322 (1- (cdr (aref handles idx))))
323 (when (= (cdr (aref handles idx)) 0)
324 (let ((target (car (aref handles idx))))
325 (if (not (listp target))
326 (eshell-close-target target (= exit-code 0))
327 (while target
328 (eshell-close-target (car target) (= exit-code 0))
329 (setq target (cdr target)))))
330 (setcar (aref handles idx) nil))))
331 (setq idx (1+ idx)))
332 nil))
333
334(defun eshell-kill-append (string) 332(defun eshell-kill-append (string)
335 "Call `kill-append' with STRING, if it is indeed a string." 333 "Call `kill-append' with STRING, if it is indeed a string."
336 (if (stringp string) 334 (if (stringp string)