Function: eshell-rewrite-for-command
eshell-rewrite-for-command is a byte-compiled function defined in
esh-cmd.el.gz.
Signature
(eshell-rewrite-for-command TERMS)
Documentation
Rewrite a for command into its equivalent Eshell command form.
Because the implementation of for relies upon conditional evaluation
of its argument (i.e., use of a Lisp special form), it must be
implemented via rewriting, rather than as a function.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/esh-cmd.el.gz
(defun eshell-rewrite-for-command (terms)
"Rewrite a `for' command into its equivalent Eshell command form.
Because the implementation of `for' relies upon conditional evaluation
of its argument (i.e., use of a Lisp special form), it must be
implemented via rewriting, rather than as a function."
(if (and (equal (car terms) "for")
(equal (nth 2 terms) "in"))
(let ((for-items (make-symbol "for-items"))
(body (car (last terms))))
(setcdr (last terms 2) nil)
`(let ((,for-items
(append
,@(mapcar
(lambda (elem)
(if (listp elem)
elem
`(list ,elem)))
(nthcdr 3 terms)))))
(while ,for-items
(let ((,(intern (cadr terms)) (car ,for-items))
(eshell--local-vars (cons ',(intern (cadr terms))
eshell--local-vars)))
(eshell-protect
,(eshell-invokify-arg body t)))
(setq ,for-items (cdr ,for-items)))
(eshell-close-handles)))))