emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master cadd3326625 2/2: Collapse 'if' forms in Eshell iterative evaluati


From: Jim Porter
Subject: master cadd3326625 2/2: Collapse 'if' forms in Eshell iterative evaluation
Date: Thu, 14 Sep 2023 20:55:47 -0400 (EDT)

branch: master
commit cadd332662599725f9a773377034a53cf68d78fd
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>

    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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]