2001-07-16 12:23:00 +00:00
|
|
|
;;; rect.el --- rectangle functions for GNU Emacs
|
1992-05-30 22:12:04 +00:00
|
|
|
|
2001-04-24 10:57:05 +00:00
|
|
|
;; Copyright (C) 1985, 1999, 2000, 2001 Free Software Foundation, Inc.
|
1992-07-22 04:22:30 +00:00
|
|
|
|
2001-10-03 10:52:47 +00:00
|
|
|
;; Maintainer: Didier Verna <didier@xemacs.org>
|
1992-07-17 20:24:00 +00:00
|
|
|
;; Keywords: internal
|
1992-07-15 23:29:10 +00:00
|
|
|
|
1989-10-31 16:00:07 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
1992-07-16 21:47:34 +00:00
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
1989-10-31 16:00:07 +00:00
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
1996-01-14 07:34:30 +00:00
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
;; Boston, MA 02111-1307, USA.
|
1989-10-31 16:00:07 +00:00
|
|
|
|
1993-03-22 05:42:35 +00:00
|
|
|
;;; Commentary:
|
|
|
|
|
1999-08-23 14:28:34 +00:00
|
|
|
;; This package provides the operations on rectangles that are documented
|
1993-03-22 05:42:35 +00:00
|
|
|
;; in the Emacs manual.
|
|
|
|
|
1999-08-03 18:36:16 +00:00
|
|
|
;; ### NOTE: this file has been almost completely rewritten by Didier Verna
|
2001-10-03 10:52:47 +00:00
|
|
|
;; <didier@xemacs.org> in July 1999. The purpose of this rewrite is to be less
|
1999-08-03 18:36:16 +00:00
|
|
|
;; intrusive and fill lines with whitespaces only when needed. A few functions
|
|
|
|
;; are untouched though, as noted above their definition.
|
|
|
|
|
|
|
|
|
1992-07-15 23:29:10 +00:00
|
|
|
;;; Code:
|
1989-10-31 16:00:07 +00:00
|
|
|
|
1998-11-24 03:52:08 +00:00
|
|
|
;;;###autoload
|
1999-08-03 18:36:16 +00:00
|
|
|
(defun move-to-column-force (column &optional flag)
|
2002-06-27 16:09:51 +00:00
|
|
|
"If COLUMN is within a multi-column character, replace it by spaces and tab.
|
1999-08-03 18:36:16 +00:00
|
|
|
As for `move-to-column', passing anything but nil or t in FLAG will move to
|
|
|
|
the desired column only if the line is long enough."
|
2001-11-17 00:47:42 +00:00
|
|
|
(move-to-column column (or flag t)))
|
2002-07-18 06:14:35 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
2002-06-27 16:09:51 +00:00
|
|
|
(make-obsolete 'move-to-column-force 'move-to-column "21.2")
|
1998-11-24 03:52:08 +00:00
|
|
|
|
1999-08-03 18:36:16 +00:00
|
|
|
;; not used any more --dv
|
1998-05-24 17:04:55 +00:00
|
|
|
;; extract-rectangle-line stores lines into this list
|
|
|
|
;; to accumulate them for extract-rectangle and delete-extract-rectangle.
|
|
|
|
(defvar operate-on-rectangle-lines)
|
|
|
|
|
2000-07-18 12:50:38 +00:00
|
|
|
;; ### NOTE: this function is untouched, but not used anymore apart from
|
1999-08-03 18:36:16 +00:00
|
|
|
;; `delete-whitespace-rectangle'. `apply-on-rectangle' is used instead. --dv
|
1989-10-31 16:00:07 +00:00
|
|
|
(defun operate-on-rectangle (function start end coerce-tabs)
|
|
|
|
"Call FUNCTION for each line of rectangle with corners at START, END.
|
|
|
|
If COERCE-TABS is non-nil, convert multi-column characters
|
|
|
|
that span the starting or ending columns on any line
|
|
|
|
to multiple spaces before calling FUNCTION.
|
|
|
|
FUNCTION is called with three arguments:
|
|
|
|
position of start of segment of this line within the rectangle,
|
|
|
|
number of columns that belong to rectangle but are before that position,
|
|
|
|
number of columns that belong to rectangle but are after point.
|
|
|
|
Point is at the end of the segment of this line within the rectangle."
|
|
|
|
(let (startcol startlinepos endcol endlinepos)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char start)
|
|
|
|
(setq startcol (current-column))
|
|
|
|
(beginning-of-line)
|
|
|
|
(setq startlinepos (point)))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char end)
|
|
|
|
(setq endcol (current-column))
|
|
|
|
(forward-line 1)
|
|
|
|
(setq endlinepos (point-marker)))
|
|
|
|
(if (< endcol startcol)
|
1992-11-16 01:40:15 +00:00
|
|
|
(setq startcol (prog1 endcol (setq endcol startcol))))
|
1994-02-05 02:19:28 +00:00
|
|
|
(save-excursion
|
|
|
|
(goto-char startlinepos)
|
|
|
|
(while (< (point) endlinepos)
|
|
|
|
(let (startpos begextra endextra)
|
1998-11-24 03:52:08 +00:00
|
|
|
(if coerce-tabs
|
2001-11-17 00:47:42 +00:00
|
|
|
(move-to-column startcol t)
|
1998-11-24 03:52:08 +00:00
|
|
|
(move-to-column startcol))
|
1994-02-05 02:19:28 +00:00
|
|
|
(setq begextra (- (current-column) startcol))
|
|
|
|
(setq startpos (point))
|
1998-11-24 03:52:08 +00:00
|
|
|
(if coerce-tabs
|
2001-11-17 00:47:42 +00:00
|
|
|
(move-to-column endcol t)
|
1998-11-24 03:52:08 +00:00
|
|
|
(move-to-column endcol))
|
1997-09-03 21:09:39 +00:00
|
|
|
;; If we overshot, move back one character
|
|
|
|
;; so that endextra will be positive.
|
|
|
|
(if (and (not coerce-tabs) (> (current-column) endcol))
|
|
|
|
(backward-char 1))
|
1994-02-05 02:19:28 +00:00
|
|
|
(setq endextra (- endcol (current-column)))
|
|
|
|
(if (< begextra 0)
|
|
|
|
(setq endextra (+ endextra begextra)
|
|
|
|
begextra 0))
|
|
|
|
(funcall function startpos begextra endextra))
|
|
|
|
(forward-line 1)))
|
1989-10-31 16:00:07 +00:00
|
|
|
(- endcol startcol)))
|
|
|
|
|
1999-08-03 18:36:16 +00:00
|
|
|
;; The replacement for `operate-on-rectangle' -- dv
|
|
|
|
(defun apply-on-rectangle (function start end &rest args)
|
|
|
|
"Call FUNCTION for each line of rectangle with corners at START, END.
|
|
|
|
FUNCTION is called with two arguments: the start and end columns of the
|
1999-08-23 14:28:34 +00:00
|
|
|
rectangle, plus ARGS extra arguments. Point is at the beginning of line when
|
1999-08-03 18:36:16 +00:00
|
|
|
the function is called."
|
|
|
|
(let (startcol startpt endcol endpt)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char start)
|
|
|
|
(setq startcol (current-column))
|
|
|
|
(beginning-of-line)
|
|
|
|
(setq startpt (point))
|
|
|
|
(goto-char end)
|
|
|
|
(setq endcol (current-column))
|
|
|
|
(forward-line 1)
|
|
|
|
(setq endpt (point-marker))
|
|
|
|
;; ensure the start column is the left one.
|
|
|
|
(if (< endcol startcol)
|
|
|
|
(let ((col startcol))
|
|
|
|
(setq startcol endcol endcol col)))
|
|
|
|
;; start looping over lines
|
|
|
|
(goto-char startpt)
|
|
|
|
(while (< (point) endpt)
|
|
|
|
(apply function startcol endcol args)
|
|
|
|
(forward-line 1)))
|
|
|
|
))
|
|
|
|
|
|
|
|
(defun delete-rectangle-line (startcol endcol fill)
|
2001-11-17 00:47:42 +00:00
|
|
|
(when (= (move-to-column startcol (or fill 'coerce)) startcol)
|
|
|
|
(delete-region (point)
|
|
|
|
(progn (move-to-column endcol 'coerce)
|
|
|
|
(point)))))
|
1999-08-03 18:36:16 +00:00
|
|
|
|
|
|
|
(defun delete-extract-rectangle-line (startcol endcol lines fill)
|
|
|
|
(let ((pt (point-at-eol)))
|
2001-11-17 00:47:42 +00:00
|
|
|
(if (< (move-to-column startcol (or fill 'coerce)) startcol)
|
1999-08-03 18:36:16 +00:00
|
|
|
(setcdr lines (cons (spaces-string (- endcol startcol))
|
|
|
|
(cdr lines)))
|
|
|
|
;; else
|
|
|
|
(setq pt (point))
|
2001-11-17 00:47:42 +00:00
|
|
|
(move-to-column endcol t)
|
1999-08-03 18:36:16 +00:00
|
|
|
(setcdr lines (cons (buffer-substring pt (point)) (cdr lines)))
|
|
|
|
(delete-region pt (point)))
|
|
|
|
))
|
|
|
|
|
|
|
|
;; ### NOTE: this is actually the only function that needs to do complicated
|
|
|
|
;; stuff like what's happening in `operate-on-rectangle', because the buffer
|
|
|
|
;; might be read-only. --dv
|
|
|
|
(defun extract-rectangle-line (startcol endcol lines)
|
|
|
|
(let (start end begextra endextra line)
|
|
|
|
(move-to-column startcol)
|
|
|
|
(setq start (point)
|
|
|
|
begextra (- (current-column) startcol))
|
|
|
|
(move-to-column endcol)
|
|
|
|
(setq end (point)
|
|
|
|
endextra (- endcol (current-column)))
|
|
|
|
(setq line (buffer-substring start (point)))
|
|
|
|
(if (< begextra 0)
|
|
|
|
(setq endextra (+ endextra begextra)
|
|
|
|
begextra 0))
|
|
|
|
(if (< endextra 0)
|
|
|
|
(setq endextra 0))
|
|
|
|
(goto-char start)
|
1989-10-31 16:00:07 +00:00
|
|
|
(while (search-forward "\t" end t)
|
|
|
|
(let ((width (- (current-column)
|
|
|
|
(save-excursion (forward-char -1)
|
|
|
|
(current-column)))))
|
|
|
|
(setq line (concat (substring line 0 (- (point) end 1))
|
|
|
|
(spaces-string width)
|
1999-08-03 18:36:16 +00:00
|
|
|
(substring line (+ (length line)
|
|
|
|
(- (point) end)))))))
|
1989-10-31 16:00:07 +00:00
|
|
|
(if (or (> begextra 0) (> endextra 0))
|
|
|
|
(setq line (concat (spaces-string begextra)
|
|
|
|
line
|
|
|
|
(spaces-string endextra))))
|
1999-08-03 18:36:16 +00:00
|
|
|
(setcdr lines (cons line (cdr lines)))))
|
1989-10-31 16:00:07 +00:00
|
|
|
|
|
|
|
(defconst spaces-strings
|
|
|
|
'["" " " " " " " " " " " " " " " " "])
|
|
|
|
|
1999-08-03 18:36:16 +00:00
|
|
|
;; this one is untouched --dv
|
1989-10-31 16:00:07 +00:00
|
|
|
(defun spaces-string (n)
|
|
|
|
(if (<= n 8) (aref spaces-strings n)
|
|
|
|
(let ((val ""))
|
|
|
|
(while (> n 8)
|
|
|
|
(setq val (concat " " val)
|
|
|
|
n (- n 8)))
|
|
|
|
(concat val (aref spaces-strings n)))))
|
|
|
|
|
1991-05-09 21:50:55 +00:00
|
|
|
;;;###autoload
|
1999-08-03 18:36:16 +00:00
|
|
|
(defun delete-rectangle (start end &optional fill)
|
1999-08-23 14:28:34 +00:00
|
|
|
"Delete (don't save) text in the region-rectangle.
|
|
|
|
The same range of columns is deleted in each line starting with the
|
|
|
|
line where the region begins and ending with the line where the region
|
|
|
|
ends.
|
|
|
|
|
|
|
|
When called from a program the rectangle's corners are START and END.
|
|
|
|
With a prefix (or a FILL) argument, also fill lines where nothing has
|
|
|
|
to be deleted."
|
|
|
|
(interactive "*r\nP")
|
1999-08-03 18:36:16 +00:00
|
|
|
(apply-on-rectangle 'delete-rectangle-line start end fill))
|
1989-10-31 16:00:07 +00:00
|
|
|
|
1991-05-09 21:50:55 +00:00
|
|
|
;;;###autoload
|
1999-08-03 18:36:16 +00:00
|
|
|
(defun delete-extract-rectangle (start end &optional fill)
|
1999-08-23 16:14:59 +00:00
|
|
|
"Delete the contents of the rectangle with corners at START and END.
|
1999-08-23 14:28:34 +00:00
|
|
|
Return it as a list of strings, one for each line of the rectangle.
|
1999-08-03 18:36:16 +00:00
|
|
|
|
1999-08-23 14:28:34 +00:00
|
|
|
When called from a program the rectangle's corners are START and END.
|
1999-08-03 18:36:16 +00:00
|
|
|
With an optional FILL argument, also fill lines where nothing has to be
|
|
|
|
deleted."
|
|
|
|
(let ((lines (list nil)))
|
|
|
|
(apply-on-rectangle 'delete-extract-rectangle-line start end lines fill)
|
|
|
|
(nreverse (cdr lines))))
|
1989-10-31 16:00:07 +00:00
|
|
|
|
1991-05-09 21:50:55 +00:00
|
|
|
;;;###autoload
|
1989-10-31 16:00:07 +00:00
|
|
|
(defun extract-rectangle (start end)
|
1999-08-23 14:28:34 +00:00
|
|
|
"Return 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."
|
1999-08-03 18:36:16 +00:00
|
|
|
(let ((lines (list nil)))
|
|
|
|
(apply-on-rectangle 'extract-rectangle-line start end lines)
|
|
|
|
(nreverse (cdr lines))))
|
1989-10-31 16:00:07 +00:00
|
|
|
|
|
|
|
(defvar killed-rectangle nil
|
1999-08-23 14:28:34 +00:00
|
|
|
"Rectangle for `yank-rectangle' to insert.")
|
1989-10-31 16:00:07 +00:00
|
|
|
|
1991-05-09 21:50:55 +00:00
|
|
|
;;;###autoload
|
1999-08-03 18:36:16 +00:00
|
|
|
(defun kill-rectangle (start end &optional fill)
|
1999-08-23 14:28:34 +00:00
|
|
|
"Delete the region-rectangle and save it as the last killed one.
|
|
|
|
|
|
|
|
When called from a program the rectangle's corners are START and END.
|
|
|
|
You might prefer to use `delete-extract-rectangle' from a program.
|
1999-08-03 18:36:16 +00:00
|
|
|
|
|
|
|
With a prefix (or a FILL) argument, also fill lines where nothing has to be
|
|
|
|
deleted."
|
1999-08-23 14:28:34 +00:00
|
|
|
(interactive "*r\nP")
|
1999-08-03 18:36:16 +00:00
|
|
|
(when buffer-read-only
|
|
|
|
(setq killed-rectangle (extract-rectangle start end))
|
|
|
|
(barf-if-buffer-read-only))
|
|
|
|
(setq killed-rectangle (delete-extract-rectangle start end fill)))
|
|
|
|
|
|
|
|
;; this one is untouched --dv
|
1991-05-09 21:50:55 +00:00
|
|
|
;;;###autoload
|
1989-10-31 16:00:07 +00:00
|
|
|
(defun yank-rectangle ()
|
|
|
|
"Yank the last killed rectangle with upper left corner at point."
|
1999-08-23 14:28:34 +00:00
|
|
|
(interactive "*")
|
1989-10-31 16:00:07 +00:00
|
|
|
(insert-rectangle killed-rectangle))
|
|
|
|
|
1999-08-03 18:36:16 +00:00
|
|
|
;; this one is untoutched --dv
|
1991-05-09 21:50:55 +00:00
|
|
|
;;;###autoload
|
1989-10-31 16:00:07 +00:00
|
|
|
(defun insert-rectangle (rectangle)
|
|
|
|
"Insert text of RECTANGLE with upper left corner at point.
|
1991-04-12 20:15:51 +00:00
|
|
|
RECTANGLE's first line is inserted at point, its second
|
|
|
|
line is inserted at a point vertically under point, etc.
|
1992-11-03 22:25:28 +00:00
|
|
|
RECTANGLE should be a list of strings.
|
|
|
|
After this command, the mark is at the upper left corner
|
|
|
|
and point is at the lower right corner."
|
1989-10-31 16:00:07 +00:00
|
|
|
(let ((lines rectangle)
|
|
|
|
(insertcolumn (current-column))
|
|
|
|
(first t))
|
1992-11-03 22:25:28 +00:00
|
|
|
(push-mark)
|
1989-10-31 16:00:07 +00:00
|
|
|
(while lines
|
|
|
|
(or first
|
|
|
|
(progn
|
|
|
|
(forward-line 1)
|
|
|
|
(or (bolp) (insert ?\n))
|
2001-11-17 00:47:42 +00:00
|
|
|
(move-to-column insertcolumn t)))
|
1989-10-31 16:00:07 +00:00
|
|
|
(setq first nil)
|
2002-04-19 00:23:08 +00:00
|
|
|
(insert-for-yank (car lines))
|
1989-10-31 16:00:07 +00:00
|
|
|
(setq lines (cdr lines)))))
|
|
|
|
|
1991-05-09 21:50:55 +00:00
|
|
|
;;;###autoload
|
1999-08-03 18:36:16 +00:00
|
|
|
(defun open-rectangle (start end &optional fill)
|
1999-08-23 14:28:34 +00:00
|
|
|
"Blank out the region-rectangle, shifting text right.
|
|
|
|
|
|
|
|
The text previously in the region is not overwritten by the blanks,
|
|
|
|
but instead winds up to the right of the rectangle.
|
1999-08-03 18:36:16 +00:00
|
|
|
|
1999-08-23 14:28:34 +00:00
|
|
|
When called from a program the rectangle's corners are START and END.
|
1999-08-03 18:36:16 +00:00
|
|
|
With a prefix (or a FILL) argument, fill with blanks even if there is no text
|
|
|
|
on the right side of the rectangle."
|
1999-08-23 14:28:34 +00:00
|
|
|
(interactive "*r\nP")
|
1999-08-03 18:36:16 +00:00
|
|
|
(apply-on-rectangle 'open-rectangle-line start end fill)
|
1992-11-16 01:40:15 +00:00
|
|
|
(goto-char start))
|
1989-10-31 16:00:07 +00:00
|
|
|
|
1999-08-03 18:36:16 +00:00
|
|
|
(defun open-rectangle-line (startcol endcol fill)
|
2001-11-17 00:47:42 +00:00
|
|
|
(when (= (move-to-column startcol (or fill 'coerce)) startcol)
|
2000-07-18 12:50:38 +00:00
|
|
|
(unless (and (not fill)
|
|
|
|
(= (point) (point-at-eol)))
|
|
|
|
(indent-to endcol))))
|
1999-08-03 18:36:16 +00:00
|
|
|
|
|
|
|
(defun delete-whitespace-rectangle-line (startcol endcol fill)
|
2001-11-17 00:47:42 +00:00
|
|
|
(when (= (move-to-column startcol (or fill 'coerce)) startcol)
|
1999-08-03 18:36:16 +00:00
|
|
|
(unless (= (point) (point-at-eol))
|
2001-04-24 10:57:05 +00:00
|
|
|
(delete-region (point) (progn (skip-syntax-forward " ") (point))))))
|
1989-10-31 16:00:07 +00:00
|
|
|
|
2002-05-07 19:30:21 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defalias 'close-rectangle 'delete-whitespace-rectangle) ;; Old name
|
|
|
|
|
1998-05-24 00:52:38 +00:00
|
|
|
;;;###autoload
|
1999-08-03 18:36:16 +00:00
|
|
|
(defun delete-whitespace-rectangle (start end &optional fill)
|
1998-05-24 00:52:38 +00:00
|
|
|
"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
|
1999-08-03 18:36:16 +00:00
|
|
|
rectangle, all continuous whitespace starting at that column is deleted.
|
1998-05-24 00:52:38 +00:00
|
|
|
|
1999-08-23 14:28:34 +00:00
|
|
|
When called from a program the rectangle's corners are START and END.
|
1999-08-03 18:36:16 +00:00
|
|
|
With a prefix (or a FILL) argument, also fill too short lines."
|
1999-08-23 14:28:34 +00:00
|
|
|
(interactive "*r\nP")
|
1999-08-03 18:36:16 +00:00
|
|
|
(apply-on-rectangle 'delete-whitespace-rectangle-line start end fill))
|
|
|
|
|
|
|
|
;; not used any more --dv
|
1998-05-24 17:04:55 +00:00
|
|
|
;; string-rectangle uses this variable to pass the string
|
|
|
|
;; to string-rectangle-line.
|
|
|
|
(defvar string-rectangle-string)
|
2001-11-17 00:47:42 +00:00
|
|
|
(defvar string-rectangle-history nil)
|
2000-11-22 17:33:21 +00:00
|
|
|
(defun string-rectangle-line (startcol endcol string delete)
|
2001-11-17 00:47:42 +00:00
|
|
|
(move-to-column startcol t)
|
2000-11-22 17:33:21 +00:00
|
|
|
(if delete
|
|
|
|
(delete-rectangle-line startcol endcol nil))
|
1999-08-03 18:36:16 +00:00
|
|
|
(insert string))
|
1993-03-27 01:58:26 +00:00
|
|
|
|
2000-03-09 22:50:30 +00:00
|
|
|
;;;###autoload
|
2001-04-24 10:57:05 +00:00
|
|
|
(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."
|
2001-11-17 00:47:42 +00:00
|
|
|
(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)))))
|
2000-11-22 17:33:21 +00:00
|
|
|
(apply-on-rectangle 'string-rectangle-line start end string t))
|
2000-03-09 22:50:30 +00:00
|
|
|
|
2002-03-28 18:26:36 +00:00
|
|
|
;;;###autoload
|
2001-04-24 10:57:05 +00:00
|
|
|
(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."
|
2001-11-17 00:47:42 +00:00
|
|
|
(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)))))
|
2001-04-24 10:57:05 +00:00
|
|
|
(apply-on-rectangle 'string-rectangle-line start end string nil))
|
|
|
|
|
1991-05-09 21:50:55 +00:00
|
|
|
;;;###autoload
|
1999-08-03 18:36:16 +00:00
|
|
|
(defun clear-rectangle (start end &optional fill)
|
1999-08-23 14:28:34 +00:00
|
|
|
"Blank out the region-rectangle.
|
|
|
|
The text previously in the region is overwritten with blanks.
|
1999-08-03 18:36:16 +00:00
|
|
|
|
1999-08-23 14:28:34 +00:00
|
|
|
When called from a program the rectangle's corners are START and END.
|
1999-08-03 18:36:16 +00:00
|
|
|
With a prefix (or a FILL) argument, also fill with blanks the parts of the
|
|
|
|
rectangle which were empty."
|
1999-08-23 14:28:34 +00:00
|
|
|
(interactive "*r\nP")
|
1999-08-03 18:36:16 +00:00
|
|
|
(apply-on-rectangle 'clear-rectangle-line start end fill))
|
|
|
|
|
|
|
|
(defun clear-rectangle-line (startcol endcol fill)
|
2002-02-26 16:05:48 +00:00
|
|
|
(let ((pt (point-at-eol)))
|
2001-11-17 00:47:42 +00:00
|
|
|
(when (= (move-to-column startcol (or fill 'coerce)) startcol)
|
1999-08-03 18:36:16 +00:00
|
|
|
(if (and (not fill)
|
|
|
|
(<= (save-excursion (goto-char pt) (current-column)) endcol))
|
|
|
|
(delete-region (point) pt)
|
|
|
|
;; else
|
|
|
|
(setq pt (point))
|
2001-11-17 00:47:42 +00:00
|
|
|
(move-to-column endcol t)
|
2002-02-26 16:05:48 +00:00
|
|
|
(setq endcol (current-column))
|
1999-08-03 18:36:16 +00:00
|
|
|
(delete-region pt (point))
|
2002-02-26 16:05:48 +00:00
|
|
|
(indent-to endcol)))))
|
1989-10-31 16:00:07 +00:00
|
|
|
|
1992-11-16 01:40:15 +00:00
|
|
|
(provide 'rect)
|
1992-05-30 22:12:04 +00:00
|
|
|
|
|
|
|
;;; rect.el ends here
|