+ ;; Column where rectangle begins.
+ (let ((begcol (- (current-column) begextra)))
+ (if (> begextra 0)
+ (move-to-column-force begcol))
+ (skip-chars-forward " \t")
+ ;; Width of whitespace to be deleted and recreated.
+ (setq whitewidth (- (current-column) begcol)))
+ ;; Delete the whitespace following the start column.
+ (delete-region startpos (point))
+ ;; Open the desired width, plus same amount of whitespace we just deleted.
+ (indent-to (+ endcol whitewidth))))
+
+;;;###autoload (defalias 'close-rectangle 'delete-whitespace-rectangle) ;; Old name
+;;;###autoload
+(defun delete-whitespace-rectangle (start end)
+ "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."
+ (interactive "r")
+ (operate-on-rectangle '(lambda (startpos begextra endextra)
+ (save-excursion
+ (goto-char startpos)
+ (delete-region (point)
+ (progn
+ (skip-syntax-forward " ")
+ (point)))))
+ start end t))
+
+;; string-rectangle uses this variable to pass the string
+;; to string-rectangle-line.
+(defvar string-rectangle-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 "r\nsString rectangle: ")
+ (let ((string-rectangle-string string))
+ (operate-on-rectangle 'string-rectangle-line start end t)))
+
+(defun string-rectangle-line (startpos begextra endextra)
+ (let (whitespace)
+ ;; Delete the width of the rectangle.
+ (delete-region startpos (point))
+ ;; Compute horizontal width of following whitespace.