Collapse 'if' forms in Eshell iterative evaluation

* lisp/eshell/esh-cmd.el (eshell-do-eval): After evaluating 'if'
conditional, replace the form with the THEN or ELSE body.
This commit is contained in:
Jim Porter 2023-09-14 17:51:36 -07:00
parent 7e50861ca7
commit cadd332662

View file

@ -1100,16 +1100,23 @@ have been replaced by constants."
eshell--test-body (copy-tree (car args)))))
((eq (car form) 'if)
(eshell-manipulate form "evaluating if condition"
(setcar args (eshell-do-eval (car args) synchronous-p)))
(eshell-do-eval
(cond
((eval (car args)) ; COND is non-nil
(cadr args))
((cdddr args) ; Multiple ELSE forms
`(progn ,@(cddr args)))
(t ; Zero or one ELSE forms
(caddr args)))
synchronous-p))
;; Evaluate the condition and replace our `if' form with
;; THEN or ELSE as appropriate.
(let ((new-form
(cond
((cadr (eshell-do-eval (car args) synchronous-p))
(cadr args)) ; COND is non-nil
((cdddr args)
`(progn ,@(cddr args))) ; Multiple ELSE forms
(t
(caddr args))))) ; Zero or one ELSE forms
(if (consp new-form)
(progn
(setcar form (car new-form))
(setcdr form (cdr new-form)))
(setcar form 'progn)
(setcdr form new-form))))
(eshell-do-eval form synchronous-p))
((eq (car form) 'setcar)
(setcar (cdr args) (eshell-do-eval (cadr args) synchronous-p))
(eval form))