]> git.eshelyaron.com Git - emacs.git/commitdiff
Simplify iteration in Eshell for loops
authorJim Porter <jporterbugs@gmail.com>
Fri, 27 Jan 2023 07:18:42 +0000 (23:18 -0800)
committerJim Porter <jporterbugs@gmail.com>
Fri, 17 Mar 2023 05:16:37 +0000 (22:16 -0700)
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

index d609711402a0ad848296874fdba70419bf3a4d0f..2dd8f5d60421bc5dfecd2a784bc2dcc482f5db38 100644 (file)
@@ -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