Function: evil-apply-on-block

evil-apply-on-block is a byte-compiled function defined in evil-common.el.

Signature

(evil-apply-on-block FUNC BEG END PASS-COLUMNS &rest ARGS)

Documentation

Call FUNC for each line of a block selection.

The selection is specified by the region BEG and END. FUNC must take at least two arguments, the beginning and end of each line. If PASS-COLUMNS is non-nil, these values are the columns, otherwise they are buffer positions. Extra arguments to FUNC may be passed via ARGS.

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-common.el
(defun evil-apply-on-block (func beg end pass-columns &rest args)
  "Call FUNC for each line of a block selection.
The selection is specified by the region BEG and END.  FUNC must
take at least two arguments, the beginning and end of each
line.  If PASS-COLUMNS is non-nil, these values are the columns,
otherwise they are buffer positions.  Extra arguments to FUNC may
be passed via ARGS."
  (let (startcol startpt endcol endpt)
    (save-excursion
      (goto-char beg)
      (setq startcol (current-column)
            startpt (line-beginning-position))
      (goto-char end)
      (setq endcol (current-column))
      (forward-line 1)
      (setq endpt (point-marker))
      ;; ensure the start column is the left one.
      (evil-sort startcol endcol)
      ;; maybe extend up to EOL
      (when (and (memq last-command '(next-line previous-line evil-use-register))
                 (eq temporary-goal-column most-positive-fixnum))
        (goto-char startpt)
        (while (< (point) endpt)
          (setq endcol (max endcol (evil-column (line-end-position))))
          (forward-line 1)))
      ;; start looping over lines
      (goto-char startpt)
      (while (< (point) endpt)
        (if pass-columns
            (apply func startcol endcol args)
          (apply func
                 (save-excursion (evil-move-to-column startcol))
                 (save-excursion (evil-move-to-column endcol t))
                 args))
        (forward-line 1)))))