From cadd332662599725f9a773377034a53cf68d78fd Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 14 Sep 2023 17:51:36 -0700 Subject: [PATCH] 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. --- lisp/eshell/esh-cmd.el | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index 0bc9ce34d32..169d66bc127 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -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)) -- 2.39.5