Function: eshell-with-temp-command
eshell-with-temp-command is a macro defined in esh-util.el.gz.
Signature
(eshell-with-temp-command COMMAND &rest BODY)
Documentation
Temporarily insert COMMAND into the buffer and execute the forms in BODY.
COMMAND can be a string to insert, a cons cell (START . END) specifying a region in the current buffer, or (:file . FILENAME) to temporarily insert the contents of FILENAME.
Before executing BODY, narrow the buffer to the text for COMMAND and set point 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-util.el.gz
(defmacro eshell-with-temp-command (command &rest body)
"Temporarily insert COMMAND into the buffer and execute the forms in BODY.
COMMAND can be a string to insert, a cons cell (START . END)
specifying a region in the current buffer, or (:file . FILENAME)
to temporarily insert the contents of FILENAME.
Before executing BODY, narrow the buffer to the text for COMMAND
and set point to the beginning of the narrowed region.
The value returned is the last form in BODY."
(declare (indent 1))
(let ((command-sym (make-symbol "command"))
(begin-sym (make-symbol "begin"))
(end-sym (make-symbol "end")))
`(let ((,command-sym ,command))
(if (eshell--region-p ,command-sym)
(save-restriction
(narrow-to-region (car ,command-sym) (cdr ,command-sym))
(goto-char (car ,command-sym))
,@body)
;; 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-sym (point)) ,end-sym)
(with-silent-modifications
(if (stringp ,command-sym)
(insert ,command-sym)
(forward-char (cadr (insert-file-contents (cdr ,command-sym)))))
(setq ,end-sym (point))
(unwind-protect
(save-restriction
(narrow-to-region ,begin-sym ,end-sym)
(goto-char ,begin-sym)
,@body)
(delete-region ,begin-sym ,end-sym))))))))