Function: evil-motion-loop
evil-motion-loop is a macro defined in evil-common.el.
Signature
(evil-motion-loop (VAR COUNT [RESULT]) BODY...)
Documentation
Loop a certain number of times.
Evaluate BODY repeatedly COUNT times with VAR bound to 1 or -1, depending on the sign of COUNT. Set RESULT, if specified, to the number of unsuccessful iterations, which is 0 if the loop completes successfully. This is also the return value.
Each iteration must move point; if point does not change, the loop immediately quits.
Source Code
;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-common.el
;;; Motions
(defmacro evil-motion-loop (spec &rest body)
"Loop a certain number of times.
Evaluate BODY repeatedly COUNT times with VAR bound to 1 or -1,
depending on the sign of COUNT. Set RESULT, if specified, to the
number of unsuccessful iterations, which is 0 if the loop completes
successfully. This is also the return value.
Each iteration must move point; if point does not change, the loop
immediately quits.
\(fn (VAR COUNT [RESULT]) BODY...)"
(declare (indent defun)
(debug ((symbolp form &optional symbolp) body)))
(let* ((var (or (pop spec) (make-symbol "unitvar")))
(count (or (pop spec) 0))
(result (or (pop spec) var))
(i (make-symbol "loopvar")))
`(let* ((,i ,count)
(,var (if (< ,i 0) -1 1)))
(while (and (/= ,i 0)
(/= (point) (progn ,@body (point))))
(setq ,i (if (< ,i 0) (1+ ,i) (1- ,i))))
(setq ,result ,i))))