Function: evil-loop

evil-loop is a macro defined in evil-common.el.

This macro is obsolete since 1.15.0.

Signature

(evil-loop (VAR COUNT [RESULT]) BODY...)

Documentation

Loop with countdown variable.

Evaluate BODY with VAR counting down from COUNT to 0. COUNT can be negative, in which case VAR counts up instead. The return value is the value of VAR when the loop terminates, which is 0 if the loop completes successfully. RESULT specifies a variable for storing this value.

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-common.el
(defmacro evil-loop (spec &rest body)
  "Loop with countdown variable.
Evaluate BODY with VAR counting down from COUNT to 0.
COUNT can be negative, in which case VAR counts up instead.
The return value is the value of VAR when the loop
terminates, which is 0 if the loop completes successfully.
RESULT specifies a variable for storing this value.

\(fn (VAR COUNT [RESULT]) BODY...)"
  (declare (indent defun) (debug dolist) (obsolete nil "1.15.0"))
  (let* ((i (make-symbol "loopvar"))
         (var (pop spec))
         (count (pop spec))
         (result (pop spec)))
    (setq var (or (unless (eq var result) var) i)
          result (or result var))
    `(let ((,var ,count))
       (setq ,result ,var)
       (while (/= ,var 0)
         ,@body
         (if (> ,var 0)
             (setq ,var (1- ,var))
           (setq ,var (1+ ,var)))
         (setq ,result ,var))
       ,var)))