Function: apply-on-rectangle

apply-on-rectangle is a byte-compiled function defined in rect.el.gz.

Signature

(apply-on-rectangle FUNCTION START END &rest ARGS)

Documentation

Call FUNCTION for each line of rectangle with corners at START, END.

FUNCTION is called with two arguments: the start and end columns of the rectangle, plus ARGS extra arguments. Point is at the beginning of line when the function is called. The final point after the last operation will be returned.

Source Code

;; Defined in /usr/src/emacs/lisp/rect.el.gz
;;; Rectangle operations.

(defun apply-on-rectangle (function start end &rest args)
  "Call FUNCTION for each line of rectangle with corners at START, END.
FUNCTION is called with two arguments: the start and end columns of the
rectangle, plus ARGS extra arguments.  Point is at the beginning of line when
the function is called.
The final point after the last operation will be returned."
  (save-excursion
    (let* ((cols (rectangle--pos-cols start end))
           (startcol (car cols))
           (endcol (cdr cols))
           (startpt (progn (goto-char start) (line-beginning-position)))
           (endpt (progn (goto-char end)
                         (copy-marker (line-end-position))))
           final-point)
      ;; Ensure the start column is the left one.
      (if (< endcol startcol)
	  (let ((col startcol))
	    (setq startcol endcol endcol col)))
      ;; Start looping over lines.
      (goto-char startpt)
      (while
          (progn
            (apply function startcol endcol args)
            (setq final-point (point))
            (and (zerop (forward-line 1)) (bolp)
                 (<= (point) endpt))))
      final-point)))