-(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)
- (skip-chars-forward " \t")
- (let ((column (+ (current-column) endextra)))
- (delete-region (point)
- (progn (goto-char startpos)
- (skip-chars-backward " \t")
- (point)))
- (indent-to column)))
+(defalias 'close-rectangle 'delete-whitespace-rectangle) ;; Old name
+
+;;;###autoload
+(defun delete-whitespace-rectangle (start end &optional fill)
+ "Delete all whitespace following a specified column in each line.
+The left edge of the rectangle specifies the position in each line
+at which whitespace deletion should begin. On each line in the
+rectangle, all continuous whitespace starting at that column is deleted.
+
+When called from a program the rectangle's corners are START and END.
+With a prefix (or a FILL) argument, also fill too short lines."
+ (interactive "*r\nP")
+ (apply-on-rectangle 'delete-whitespace-rectangle-line start end fill))
+
+;; not used any more --dv
+;; string-rectangle uses this variable to pass the string
+;; to string-rectangle-line.
+(defvar string-rectangle-string)
+(defvar string-rectangle-history nil)
+(defun string-rectangle-line (startcol endcol string delete)
+ (move-to-column startcol t)
+ (if delete
+ (delete-rectangle-line startcol endcol nil))
+ (insert string))
+
+;;;###autoload
+(defun string-rectangle (start end string)
+ "Replace rectangle contents with STRING on each line.
+The length of STRING need not be the same as the rectangle width.
+
+Called from a program, takes three args; START, END and STRING."
+ (interactive
+ (progn (barf-if-buffer-read-only)
+ (list
+ (region-beginning)
+ (region-end)
+ (read-string (format "String rectangle (default %s): "
+ (or (car string-rectangle-history) ""))
+ nil 'string-rectangle-history
+ (car string-rectangle-history)))))
+ (apply-on-rectangle 'string-rectangle-line start end string t))
+
+;;;###autoload
+(defalias 'replace-rectangle 'string-rectangle)
+
+;;;###autoload
+(defun string-insert-rectangle (start end string)
+ "Insert STRING on each line of region-rectangle, shifting text right.
+
+When called from a program, the rectangle's corners are START and END.
+The left edge of the rectangle specifies the column for insertion.
+This command does not delete or overwrite any existing text."
+ (interactive
+ (progn (barf-if-buffer-read-only)
+ (list
+ (region-beginning)
+ (region-end)
+ (read-string (format "String insert rectangle (default %s): "
+ (or (car string-rectangle-history) ""))
+ nil 'string-rectangle-history
+ (car string-rectangle-history)))))
+ (apply-on-rectangle 'string-rectangle-line start end string nil))
+
+;;;###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 a 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))
+
+(defun clear-rectangle-line (startcol endcol fill)
+ (let ((pt (point-at-eol)))
+ (when (= (move-to-column startcol (if fill t '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 endcol (current-column))
+ (delete-region pt (point))
+ (indent-to endcol)))))