From 767839a0b3c03f910387c834f1320d4f9d465201 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 26 Jan 2023 23:18:42 -0800 Subject: [PATCH 1/3] 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. * 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 @@ eshell-rewrite-for-command (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 -- 2.25.1