From: Jim Porter Date: Fri, 27 Jan 2023 07:18:42 +0000 (-0800) Subject: Simplify iteration in Eshell for loops X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=67a2b320f61642d0cbbce31ac34d4e1ce77c9230;p=emacs.git 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. --- 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