]> code.delx.au - gnu-emacs/blobdiff - lisp/rect.el
*** empty log message ***
[gnu-emacs] / lisp / rect.el
index 1e1a9baa851b7ca1c15fc3727efeeceb9100ee7b..302621776c356dd4c77123de31705d4be5197360 100644 (file)
@@ -58,7 +58,7 @@ the desired column only if the line is long enough."
 ;; to accumulate them for extract-rectangle and delete-extract-rectangle.
 (defvar operate-on-rectangle-lines)
 
-;; ### NOTE: this function is untouched, but not used anymore appart in
+;; ### NOTE: this function is untouched, but not used anymore apart from
 ;; `delete-whitespace-rectangle'. `apply-on-rectangle' is used instead. --dv
 (defun operate-on-rectangle (function start end coerce-tabs)
   "Call FUNCTION for each line of rectangle with corners at START, END.
@@ -216,7 +216,7 @@ to be deleted."
 
 ;;;###autoload
 (defun delete-extract-rectangle (start end &optional fill)
-  "Delete the contents of the region-rectangle.
+  "Delete the contents of the rectangle with corners at START and END.
 Return it as a list of strings, one for each line of the rectangle.
 
 When called from a program the rectangle's corners are START and END.
@@ -297,12 +297,10 @@ on the right side of the rectangle."
   (goto-char start))
 
 (defun open-rectangle-line (startcol endcol fill)
-  (let (spaces)
-    (when (= (move-to-column-force startcol (or fill 'coerce)) startcol)
-      (unless (and (not fill)
-                  (= (point) (point-at-eol)))
-       (indent-to endcol)))
-    ))
+  (when (= (move-to-column-force startcol (or fill 'coerce)) startcol)
+    (unless (and (not fill)
+                (= (point) (point-at-eol)))
+      (indent-to endcol))))
 
 (defun delete-whitespace-rectangle-line (startcol endcol fill)
   (when (= (move-to-column-force startcol (or fill 'coerce)) startcol)
@@ -336,12 +334,26 @@ 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 "*r\nsString rectangle: ")
-  (apply-on-rectangle 'string-rectangle-line start end string))
-
-(defun string-rectangle-line (startcol endcol string)
+  ;; XEmacs tests `pending-delete-mode' here, and replaces the
+  ;; rectangle if that's on.  Using `delete-selection-mode' here would
+  ;; only be useful if `mark-even-if-inactive' is on since otherwise
+  ;; we need the mark to be active, given the interactive spec, and
+  ;; then we'd always delete.  Maybe revisit this and consider testing
+  ;; `mark-even-if-inactive' too?
+  (apply-on-rectangle 'string-rectangle-line start end string nil))
+
+(defun string-rectangle-line (startcol endcol string delete)
   (move-to-column-force startcol)
+  (if delete
+      (delete-rectangle-line startcol endcol nil))
   (insert string))
 
+;;;###autoload
+(defun replace-rectangle (start end string)
+  "Like `string-rectangle', but replace the original region."
+  (interactive "*r\nsString rectangle: ")
+  (apply-on-rectangle 'string-rectangle-line start end string t))
+
 ;;;###autoload
 (defun clear-rectangle (start end &optional fill)
   "Blank out the region-rectangle.