Function: eshell-with-temp-command

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

Signature

(eshell-with-temp-command REGION &rest BODY)

Documentation

Narrow the buffer to REGION and execute the forms in BODY.

REGION is a cons cell (START . END) that specifies the region to which to narrow the buffer. REGION can also be a string, in which case the macro temporarily inserts it into the buffer at point, and narrows the buffer to the inserted string. Before executing BODY, point is set to the beginning of the narrowed REGION.

The value returned is the last form in BODY.

Source Code

;; Defined in /usr/src/emacs/lisp/eshell/esh-cmd.el.gz
(defmacro eshell-with-temp-command (region &rest body)
  "Narrow the buffer to REGION and execute the forms in BODY.

REGION is a cons cell (START . END) that specifies the region to
which to narrow the buffer.  REGION can also be a string, in
which case the macro temporarily inserts it into the buffer at
point, and narrows the buffer to the inserted string.  Before
executing BODY, point is set to the beginning of the narrowed
REGION.

The value returned is the last form in BODY."
  (declare (indent 1))
  `(let ((reg ,region))
     (if (stringp reg)
         ;; Since parsing relies partly on buffer-local state
         ;; (e.g. that of `eshell-parse-argument-hook'), we need to
         ;; perform the parsing in the Eshell buffer.
         (let ((begin (point)) end)
           (with-silent-modifications
             (insert reg)
             (setq end (point))
             (unwind-protect
                 (save-restriction
                   (narrow-to-region begin end)
                   (goto-char begin)
                   ,@body)
               (delete-region begin end))))
       (save-restriction
         (narrow-to-region (car reg) (cdr reg))
         (goto-char (car reg))
         ,@body))))