Function: eshell-get-target
eshell-get-target is a byte-compiled function defined in esh-io.el.gz.
Signature
(eshell-get-target TARGET &optional MODE)
Documentation
Convert TARGET, which is a raw argument, into a valid output target.
MODE is either overwrite, append or insert; if it is omitted or nil,
it defaults to insert.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/esh-io.el.gz
(defun eshell-get-target (target &optional mode)
"Convert TARGET, which is a raw argument, into a valid output target.
MODE is either `overwrite', `append' or `insert'; if it is omitted or nil,
it defaults to `insert'."
(setq mode (or mode 'insert))
(cond
((stringp target)
(let ((redir (assoc target eshell-virtual-targets)))
(if redir
(if (nth 2 redir)
(funcall (nth 1 redir) mode)
(nth 1 redir))
(let* ((exists (get-file-buffer target))
(buf (find-file-noselect target t)))
(with-current-buffer buf
(if buffer-file-read-only
(error "Cannot write to read-only file `%s'" target))
(setq buffer-read-only nil)
(setq-local eshell-output-file-buffer
(if (eq exists buf) 0 t))
(cond ((eq mode 'overwrite)
(erase-buffer))
((eq mode 'append)
(goto-char (point-max))))
(point-marker))))))
((bufferp target)
(with-current-buffer target
(cond ((eq mode 'overwrite)
(erase-buffer))
((eq mode 'append)
(goto-char (point-max))))
(point-marker)))
((functionp target) nil)
((symbolp target)
(if (eq mode 'overwrite)
(set target nil))
target)
((or (eshell-processp target)
(markerp target))
target)
(t
(error "Invalid redirection target: %s"
(eshell-stringify target)))))