-(defun clear-rectangle (start end)
- "Blank out rectangle with corners at point and mark.
-The text previously in the region is overwritten by the blanks.
-When called from a program, requires two args which specify the corners."
- (interactive "r")
- (operate-on-rectangle 'clear-rectangle-line start end t))
-
-(defun clear-rectangle-line (startpos begextra endextra)
- ;; Find end of whitespace after the rectangle.
- (skip-chars-forward " \t")
- (let ((column (+ (current-column) endextra)))
- ;; Delete the text in the rectangle, and following whitespace.
- (delete-region (point)
- (progn (goto-char startpos)
- (skip-chars-backward " \t")
- (point)))
- ;; Reindent out to same column that we were at.
- (indent-to column)))
+(defun replace-rectangle (start end string)
+ "Like `string-rectangle', but unconditionally replace the original region,
+as if `pending-delete-mode' were active."
+ (interactive "*r\nsString rectangle: ")
+ (apply-on-rectangle 'string-rectangle-line start end string t))
+
+
+(defun clear-rectangle-line (startcol endcol fill)
+ (let ((pt (point-at-eol))
+ spaces)
+ (when (= (move-to-column startcol (or fill 'coerce)) startcol)
+ (if (and (not fill)
+ (<= (save-excursion (goto-char pt) (current-column)) endcol))
+ (delete-region (point) pt)
+ ;; else
+ (setq pt (point))
+ (move-to-column endcol t)
+ (setq spaces (- (point) pt))
+ (delete-region pt (point))
+ (indent-to (+ (current-column) spaces))))
+ ))
+
+;;;###autoload
+(defun clear-rectangle (start end &optional fill)
+ "Blank out the region-rectangle.
+The text previously in the region is overwritten with blanks.
+
+When called from a program, the rectangle's corners are START and END.
+With a prefix (or FILL) argument, also fill with blanks the parts of the
+rectangle which were empty."
+ (interactive "*r\nP")
+ (apply-on-rectangle 'clear-rectangle-line start end fill))
+