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 ((body (car (last terms))))
	(setcdr (last terms 2) nil)
	`(let ((for-items
		(copy-tree
		 (append
		  ,@(mapcar
		     (lambda (elem)
		       (if (listp elem)
			   elem
			 `(list ,elem)))
		     (cdr (cddr terms))))))
	       (eshell-command-body '(nil))
               (eshell-test-body '(nil)))
	   (while (car 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)))
	     (setcar for-items (cadr for-items))
	     (setcdr for-items (cddr for-items)))
           (eshell-close-handles
            eshell-last-command-status
            (list 'quote eshell-last-command-result))))))