;;; Code:
+;;;###autoload
+(defun move-to-column-force (column)
+ "Move point to column COLUMN rigidly in the current line.
+If COLUMN is within a multi-column character, replace it by
+spaces and tab."
+ (let ((col (move-to-column column t)))
+ (if (> col column)
+ (let (pos)
+ (delete-char -1)
+ (insert-char ? (- column (current-column)))
+ (setq pos (point))
+ (indent-to col)
+ (goto-char pos)))
+ column))
+
;; extract-rectangle-line stores lines into this list
;; to accumulate them for extract-rectangle and delete-extract-rectangle.
(defvar operate-on-rectangle-lines)
(goto-char startlinepos)
(while (< (point) endlinepos)
(let (startpos begextra endextra)
- (move-to-column startcol coerce-tabs)
+ (if coerce-tabs
+ (move-to-column-force startcol)
+ (move-to-column startcol))
(setq begextra (- (current-column) startcol))
(setq startpos (point))
- (move-to-column endcol coerce-tabs)
+ (if coerce-tabs
+ (move-to-column-force endcol)
+ (move-to-column endcol))
;; If we overshot, move back one character
;; so that endextra will be positive.
(if (and (not coerce-tabs) (> (current-column) endcol))
(progn
(forward-line 1)
(or (bolp) (insert ?\n))
- (move-to-column insertcolumn t)))
+ (move-to-column-force insertcolumn)))
(setq first nil)
(insert (car lines))
(setq lines (cdr lines)))))
(goto-char startpos)
;; 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)))
;; 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 close-rectangle (start end)
+(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
;;;###autoload
(defun string-rectangle (start end string)
- "Insert STRING on each line of the region-rectangle, shifting text right.
-The left edge of the rectangle specifies the column for insertion.
-This command does not delete or overwrite any existing text.
+ "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: ")
(defun string-rectangle-line (startpos begextra endextra)
(let (whitespace)
- (goto-char startpos)
+ ;; Delete the width of the rectangle.
+ (delete-region startpos (point))
;; Compute horizontal width of following whitespace.
(let ((ocol (current-column)))
(skip-chars-forward " \t")