Function: operate-on-rectangle

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

Signature

(operate-on-rectangle FUNCTION START END COERCE-TABS)

Documentation

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

If COERCE-TABS is non-nil, convert multi-column characters that span the starting or ending columns on any line to multiple spaces before calling FUNCTION. FUNCTION is called with three arguments:
 position of start of segment of this line within the rectangle,
 number of columns that belong to rectangle but are before that position,
 number of columns that belong to rectangle but are after point.
Point is at the end of the segment of this line within the rectangle.

Source Code

;; Defined in /usr/src/emacs/lisp/rect.el.gz
;; FIXME: this function should be replaced by `apply-on-rectangle'
(defun operate-on-rectangle (function start end coerce-tabs)
  "Call FUNCTION for each line of rectangle with corners at START, END.
If COERCE-TABS is non-nil, convert multi-column characters
that span the starting or ending columns on any line
to multiple spaces before calling FUNCTION.
FUNCTION is called with three arguments:
 position of start of segment of this line within the rectangle,
 number of columns that belong to rectangle but are before that position,
 number of columns that belong to rectangle but are after point.
Point is at the end of the segment of this line within the rectangle."
  (apply-on-rectangle
   (lambda (startcol endcol)
     (let (startpos begextra endextra)
       (move-to-column startcol coerce-tabs)
       (setq begextra (- (current-column) startcol))
       (setq startpos (point))
       (move-to-column endcol coerce-tabs)
       ;; If we overshot, move back one character
       ;; so that endextra will be positive.
       (if (and (not coerce-tabs) (> (current-column) endcol))
           (backward-char 1))
       (setq endextra (- endcol (current-column)))
       (if (< begextra 0)
           (setq endextra (+ endextra begextra)
                 begextra 0))
       (funcall function startpos begextra endextra)))
   start end))