emacs-diffs
[Top][All Lists]
Advanced

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

master 67a2b320f61 1/3: Simplify iteration in Eshell for loops


From: Jim Porter
Subject: master 67a2b320f61 1/3: Simplify iteration in Eshell for loops
Date: Fri, 17 Mar 2023 01:32:42 -0400 (EDT)

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

    Simplify iteration in Eshell for loops
    
    The previous code fixed an issue in Eshell's iterative evaluation
    where deferred commands caused an infinite loop (see bug#12571).
    However, with the fix to unwinding let forms in 'eshell-do-eval' (see
    bug#59469), we can just write this code as we normally would
    (bug#61954).
    
    * lisp/eshell/esh-cmd.el (eshell-rewrite-for-command): Simplify.
---
 lisp/eshell/esh-cmd.el | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index d609711402a..2dd8f5d6042 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -533,25 +533,23 @@ implemented via rewriting, rather than as a function."
           (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))
+        `(let ((for-items
+                (append
+                 ,@(mapcar
+                    (lambda (elem)
+                      (if (listp elem)
+                          elem
+                        `(list ,elem)))
+                    (nthcdr 3 terms))))
+               (eshell-command-body '(nil))
                (eshell-test-body '(nil)))
-          (while (car for-items)
-            (let ((,(intern (cadr terms)) (car for-items))
+           (while for-items
+             (let ((,(intern (cadr terms)) (car for-items))
                   (eshell--local-vars (cons ',(intern (cadr terms))
-                                           eshell--local-vars)))
+                                             eshell--local-vars)))
               (eshell-protect
                ,(eshell-invokify-arg body t)))
-            (setcar for-items (cadr for-items))
-            (setcdr for-items (cddr for-items)))
+             (setq for-items (cdr for-items)))
            (eshell-close-handles)))))
 
 (defun eshell-structure-basic-command (func names keyword test body



reply via email to

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