Function: eshell-with-handles

eshell-with-handles is a macro defined in esh-cmd.el.gz.

Signature

(eshell-with-handles HANDLE-ARGS &rest BODY)

Documentation

Create a new set of I/O handles and evaluate BODY.

HANDLE-ARGS is a list of arguments to pass to eshell-create-handles. After evaluating BODY, automatically release the handles, allowing them to close.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-cmd.el.gz
;;_* Command evaluation macros
;;
;; The structure of the following macros is very important to
;; `eshell-do-eval' [Iterative evaluation]:
;;
;; @ Don't use special forms that conditionally evaluate their
;;   arguments, such as `let*', unless Eshell explicitly supports them.
;;   Eshell supports the following special forms: `and', `catch',
;;   `condition-case', `if', `let', `or', `prog1', `progn', `quote',
;;   `setq', `unwind-protect', and `while'.
;;
;; @ The two "special" variables are `eshell-current-handles' and
;;   `eshell-current-subjob-p'.  Bind them locally with a `let' if you
;;   need to change them.  Change them directly only if your intention
;;   is to change the calling environment.
;;
;; These rules likewise apply to any other code that generates forms
;; that `eshell-do-eval' will evaluated, such as command rewriting
;; hooks (see `eshell-rewrite-command-hook' and friends).

(defmacro eshell-with-handles (handle-args &rest body)
  "Create a new set of I/O handles and evaluate BODY.
HANDLE-ARGS is a list of arguments to pass to `eshell-create-handles'.
After evaluating BODY, automatically release the handles, allowing them
to close."
  (declare (indent 1))
  `(let ((eshell-current-handles (eshell-create-handles ,@handle-args)))
     (unwind-protect
         ,(if (length= body 1) (car body) `(progn ,@body))
       (eshell-close-handles))))