annotate lisp/prim/rect.el @ 126:1370575f1259 xemacs-20-1p1

Import from CVS: tag xemacs-20-1p1
author cvs
date Mon, 13 Aug 2007 09:27:39 +0200
parents b9518feda344
children 28f395d8dc7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; rect.el --- rectangle functions for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
25 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; This package provides the operations on rectangles that are ocumented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; in the XEmacs Reference Manual.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; XEmacs: extra-args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defun operate-on-rectangle (function start end coerce-tabs &rest extra-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "Call FUNCTION for each line of rectangle with corners at START, END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 If COERCE-TABS is non-nil, convert multi-column characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 that span the starting or ending columns on any line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 to multiple spaces before calling FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 FUNCTION is called with three arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 position of start of segment of this line within the rectangle,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 number of columns that belong to rectangle but are before that position,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 number of columns that belong to rectangle but are after point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 Point is at the end of the segment of this line within the rectangle."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (let (startcol startlinepos endcol endlinepos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (setq startcol (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq startlinepos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (setq endcol (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (setq endlinepos (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (if (< endcol startcol)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
57 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (let ((tem startcol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (setq startcol endcol endcol tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (goto-char startlinepos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (while (< (point) endlinepos)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
63 (let (startpos begextra endextra)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
64 (move-to-column startcol coerce-tabs)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
65 (setq begextra (- (current-column) startcol))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
66 (setq startpos (point))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
67 (move-to-column endcol coerce-tabs)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
68 (setq endextra (- endcol (current-column)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
69 (if (< begextra 0)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
70 (setq endextra (+ endextra begextra)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
71 begextra 0))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (apply function startpos begextra endextra extra-args))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
73 (forward-line 1)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (- endcol startcol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (defun delete-rectangle-line (startdelpos ignore ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (delete-region startdelpos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; XEmacs: added lines arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defun delete-extract-rectangle-line (startdelpos begextra endextra lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (extract-rectangle-line startdelpos begextra endextra lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (delete-region startdelpos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; XEmacs: added lines arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defun extract-rectangle-line (startdelpos begextra endextra lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (let ((line (buffer-substring startdelpos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (goto-char startdelpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (while (search-forward "\t" end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (let ((width (- (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (save-excursion (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (current-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (setq line (concat (substring line 0 (- (point) end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (spaces-string width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (substring line (+ (length line) (- (point) end)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (if (or (> begextra 0) (> endextra 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (setq line (concat (spaces-string begextra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (spaces-string endextra))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
101 (setcdr lines (cons line (cdr lines))))) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defconst spaces-strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (purecopy '["" " " " " " " " " " " " " " " " "]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defun spaces-string (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (if (<= n 8) (aref spaces-strings n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (let ((val ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (while (> n 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (setq val (concat " " val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 n (- n 8)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (concat val (aref spaces-strings n)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defun delete-rectangle (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "Delete (don't save) text in rectangle with point and mark as corners.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
117 The same range of columns is deleted in each line starting with the line
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
118 where the region begins and ending with the line where the region ends."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (operate-on-rectangle 'delete-rectangle-line start end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (defun delete-extract-rectangle (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 "Delete contents of rectangle and return it as a list of strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 Arguments START and END are the corners of the rectangle.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 The value is list of strings, one for each line of the rectangle."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (let ((lines (list nil))) ; XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (operate-on-rectangle 'delete-extract-rectangle-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 start end t lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (nreverse (cdr lines))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defun extract-rectangle (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 "Return contents of rectangle with corners at START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 Value is list of strings, one for each line of the rectangle."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (let ((lines (list nil))) ; XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (operate-on-rectangle 'extract-rectangle-line start end nil lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (nreverse (cdr lines))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (defvar killed-rectangle nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 "Rectangle for yank-rectangle to insert.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defun kill-rectangle (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "Delete rectangle with corners at point and mark; save as last killed one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 Calling from program, supply two args START and END, buffer positions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 But in programs you might prefer to use `delete-extract-rectangle'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq killed-rectangle (extract-rectangle start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (barf-if-buffer-read-only)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (setq killed-rectangle (delete-extract-rectangle start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (defun yank-rectangle ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 "Yank the last killed rectangle with upper left corner at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (insert-rectangle killed-rectangle))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (defun insert-rectangle (rectangle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 "Insert text of RECTANGLE with upper left corner at point.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
165 RECTANGLE's first line is inserted at point, its second
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
166 line is inserted at a point vertically under point, etc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 RECTANGLE should be a list of strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 After this command, the mark is at the upper left corner
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 and point is at the lower right corner."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (let ((lines rectangle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (insertcolumn (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (first t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (while lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (or first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (or (bolp) (insert ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (move-to-column insertcolumn t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (setq first nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (insert (car lines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq lines (cdr lines)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (defun open-rectangle (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 "Blank out rectangle with corners at point and mark, shifting text right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 The text previously in the region is not overwritten by the blanks,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 but instead winds up to the right of the rectangle."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (operate-on-rectangle 'open-rectangle-line start end nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (goto-char start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defun open-rectangle-line (startpos begextra endextra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; Column where rectangle ends.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (let ((endcol (+ (current-column) endextra))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 whitewidth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (goto-char startpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; Column where rectangle begins.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (let ((begcol (- (current-column) begextra)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;; Width of whitespace to be deleted and recreated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (setq whitewidth (- (current-column) begcol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; Delete the whitespace following the start column.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (delete-region startpos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; Open the desired width, plus same amount of whitespace we just deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (indent-to (+ endcol whitewidth))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (defun string-rectangle (start end string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 "Insert STRING on each line of the region-rectangle, shifting text right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 The left edge of the rectangle specifies the column for insertion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 This command does not delete or overwrite any existing text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 Called from a program, takes three args; START, END and STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (interactive "r\nsString rectangle: ")
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
216 (operate-on-rectangle 'string-rectangle-line start end t string)) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; XEmacs: add string arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (defun string-rectangle-line (startpos begextra endextra string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (let (whitespace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (goto-char startpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;; Compute horizontal width of following whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (let ((ocol (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (setq whitespace (- (current-column) ocol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; Delete the following whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (delete-region startpos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; Insert the desired string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (insert string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; Insert the same width of whitespace that we had before.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (indent-to (+ (current-column) whitespace))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defun clear-rectangle (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "Blank out rectangle with corners at point and mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 The text previously in the region is overwritten by the blanks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 When called from a program, requires two args which specify the corners."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (operate-on-rectangle 'clear-rectangle-line start end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (defun clear-rectangle-line (startpos begextra endextra)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;; Find end of whitespace after the rectangle.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (let ((column (+ (current-column) endextra)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; Delete the text in the rectangle, and following whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (delete-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (progn (goto-char startpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; Reindent out to same column that we were at.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (indent-to column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (provide 'rect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ;;; rect.el ends here