Mercurial > emacs
annotate lisp/rect.el @ 22258:30576834668c
(loaddefs.el): Load it earlier, and GC before and after
and a few more times later on.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 26 May 1998 20:56:22 +0000 |
parents | 84c3c863f0bd |
children | 6c4756ecd4a2 |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1 ;;; rect.el --- rectangle functions for GNU Emacs. |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 |
7298 | 3 ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc. |
845 | 4 |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
5 ;; Maintainer: FSF |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: internal |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
7 |
36 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
789
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
36 | 24 |
2308
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1619
diff
changeset
|
25 ;;; Commentary: |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1619
diff
changeset
|
26 |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1619
diff
changeset
|
27 ;; This package provides the operations on rectangles that are ocumented |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1619
diff
changeset
|
28 ;; in the Emacs manual. |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1619
diff
changeset
|
29 |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
30 ;;; Code: |
36 | 31 |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
32 ;; extract-rectangle-line stores lines into this list |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
33 ;; to accumulate them for extract-rectangle and delete-extract-rectangle. |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
34 (defvar operate-on-rectangle-lines) |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
35 |
36 | 36 (defun operate-on-rectangle (function start end coerce-tabs) |
37 "Call FUNCTION for each line of rectangle with corners at START, END. | |
38 If COERCE-TABS is non-nil, convert multi-column characters | |
39 that span the starting or ending columns on any line | |
40 to multiple spaces before calling FUNCTION. | |
41 FUNCTION is called with three arguments: | |
42 position of start of segment of this line within the rectangle, | |
43 number of columns that belong to rectangle but are before that position, | |
44 number of columns that belong to rectangle but are after point. | |
45 Point is at the end of the segment of this line within the rectangle." | |
46 (let (startcol startlinepos endcol endlinepos) | |
47 (save-excursion | |
48 (goto-char start) | |
49 (setq startcol (current-column)) | |
50 (beginning-of-line) | |
51 (setq startlinepos (point))) | |
52 (save-excursion | |
53 (goto-char end) | |
54 (setq endcol (current-column)) | |
55 (forward-line 1) | |
56 (setq endlinepos (point-marker))) | |
57 (if (< endcol startcol) | |
1619
6147d2164331
* rect.el (operate-on-rectangle): Use move-to-column's FORCE
Jim Blandy <jimb@redhat.com>
parents:
1542
diff
changeset
|
58 (setq startcol (prog1 endcol (setq endcol startcol)))) |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
59 (save-excursion |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
60 (goto-char startlinepos) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
61 (while (< (point) endlinepos) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
62 (let (startpos begextra endextra) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
63 (move-to-column startcol coerce-tabs) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
64 (setq begextra (- (current-column) startcol)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
65 (setq startpos (point)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
66 (move-to-column endcol coerce-tabs) |
19732
d8478556c7f0
(operate-on-rectangle): If we overshoot when looking for endcol, back up.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
67 ;; If we overshot, move back one character |
d8478556c7f0
(operate-on-rectangle): If we overshoot when looking for endcol, back up.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
68 ;; so that endextra will be positive. |
d8478556c7f0
(operate-on-rectangle): If we overshoot when looking for endcol, back up.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
69 (if (and (not coerce-tabs) (> (current-column) endcol)) |
d8478556c7f0
(operate-on-rectangle): If we overshoot when looking for endcol, back up.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
70 (backward-char 1)) |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
71 (setq endextra (- endcol (current-column))) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
72 (if (< begextra 0) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
73 (setq endextra (+ endextra begextra) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
74 begextra 0)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
75 (funcall function startpos begextra endextra)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
76 (forward-line 1))) |
36 | 77 (- endcol startcol))) |
78 | |
79 (defun delete-rectangle-line (startdelpos ignore ignore) | |
80 (delete-region startdelpos (point))) | |
81 | |
82 (defun delete-extract-rectangle-line (startdelpos begextra endextra) | |
83 (save-excursion | |
84 (extract-rectangle-line startdelpos begextra endextra)) | |
85 (delete-region startdelpos (point))) | |
86 | |
87 (defun extract-rectangle-line (startdelpos begextra endextra) | |
88 (let ((line (buffer-substring startdelpos (point))) | |
89 (end (point))) | |
90 (goto-char startdelpos) | |
91 (while (search-forward "\t" end t) | |
92 (let ((width (- (current-column) | |
93 (save-excursion (forward-char -1) | |
94 (current-column))))) | |
95 (setq line (concat (substring line 0 (- (point) end 1)) | |
96 (spaces-string width) | |
97 (substring line (+ (length line) (- (point) end))))))) | |
98 (if (or (> begextra 0) (> endextra 0)) | |
99 (setq line (concat (spaces-string begextra) | |
100 line | |
101 (spaces-string endextra)))) | |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
102 (setq operate-on-rectangle-lines (cons line operate-on-rectangle-lines)))) |
36 | 103 |
104 (defconst spaces-strings | |
105 '["" " " " " " " " " " " " " " " " "]) | |
106 | |
107 (defun spaces-string (n) | |
108 (if (<= n 8) (aref spaces-strings n) | |
109 (let ((val "")) | |
110 (while (> n 8) | |
111 (setq val (concat " " val) | |
112 n (- n 8))) | |
113 (concat val (aref spaces-strings n))))) | |
114 | |
258 | 115 ;;;###autoload |
36 | 116 (defun delete-rectangle (start end) |
117 "Delete (don't save) text in rectangle with point and mark as corners. | |
242 | 118 The same range of columns is deleted in each line starting with the line |
119 where the region begins and ending with the line where the region ends." | |
36 | 120 (interactive "r") |
121 (operate-on-rectangle 'delete-rectangle-line start end t)) | |
122 | |
258 | 123 ;;;###autoload |
36 | 124 (defun delete-extract-rectangle (start end) |
125 "Delete contents of rectangle and return it as a list of strings. | |
126 Arguments START and END are the corners of the rectangle. | |
127 The value is list of strings, one for each line of the rectangle." | |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
128 (let (operate-on-rectangle-lines) |
36 | 129 (operate-on-rectangle 'delete-extract-rectangle-line |
130 start end t) | |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
131 (nreverse operate-on-rectangle-lines))) |
36 | 132 |
258 | 133 ;;;###autoload |
36 | 134 (defun extract-rectangle (start end) |
135 "Return contents of rectangle with corners at START and END. | |
136 Value is list of strings, one for each line of the rectangle." | |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
137 (let (operate-on-rectangle-lines) |
36 | 138 (operate-on-rectangle 'extract-rectangle-line start end nil) |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
139 (nreverse operate-on-rectangle-lines))) |
36 | 140 |
141 (defvar killed-rectangle nil | |
142 "Rectangle for yank-rectangle to insert.") | |
143 | |
258 | 144 ;;;###autoload |
36 | 145 (defun kill-rectangle (start end) |
146 "Delete rectangle with corners at point and mark; save as last killed one. | |
147 Calling from program, supply two args START and END, buffer positions. | |
242 | 148 But in programs you might prefer to use `delete-extract-rectangle'." |
36 | 149 (interactive "r") |
9242
493c74aab5a0
(kill-rectangle): In read-only buffer, do record
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
150 (if buffer-read-only |
493c74aab5a0
(kill-rectangle): In read-only buffer, do record
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
151 (progn |
493c74aab5a0
(kill-rectangle): In read-only buffer, do record
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
152 (setq killed-rectangle (extract-rectangle start end)) |
493c74aab5a0
(kill-rectangle): In read-only buffer, do record
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
153 (barf-if-buffer-read-only))) |
36 | 154 (setq killed-rectangle (delete-extract-rectangle start end))) |
155 | |
258 | 156 ;;;###autoload |
36 | 157 (defun yank-rectangle () |
158 "Yank the last killed rectangle with upper left corner at point." | |
159 (interactive) | |
160 (insert-rectangle killed-rectangle)) | |
161 | |
258 | 162 ;;;###autoload |
36 | 163 (defun insert-rectangle (rectangle) |
164 "Insert text of RECTANGLE with upper left corner at point. | |
242 | 165 RECTANGLE's first line is inserted at point, its second |
166 line is inserted at a point vertically under point, etc. | |
1542
724b443e445d
(insert-rectangle): Put mark at upper left corner.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
167 RECTANGLE should be a list of strings. |
724b443e445d
(insert-rectangle): Put mark at upper left corner.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
168 After this command, the mark is at the upper left corner |
724b443e445d
(insert-rectangle): Put mark at upper left corner.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
169 and point is at the lower right corner." |
36 | 170 (let ((lines rectangle) |
171 (insertcolumn (current-column)) | |
172 (first t)) | |
1542
724b443e445d
(insert-rectangle): Put mark at upper left corner.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
173 (push-mark) |
36 | 174 (while lines |
175 (or first | |
176 (progn | |
177 (forward-line 1) | |
178 (or (bolp) (insert ?\n)) | |
1619
6147d2164331
* rect.el (operate-on-rectangle): Use move-to-column's FORCE
Jim Blandy <jimb@redhat.com>
parents:
1542
diff
changeset
|
179 (move-to-column insertcolumn t))) |
36 | 180 (setq first nil) |
181 (insert (car lines)) | |
182 (setq lines (cdr lines))))) | |
183 | |
258 | 184 ;;;###autoload |
36 | 185 (defun open-rectangle (start end) |
186 "Blank out rectangle with corners at point and mark, shifting text right. | |
187 The text previously in the region is not overwritten by the blanks, | |
1619
6147d2164331
* rect.el (operate-on-rectangle): Use move-to-column's FORCE
Jim Blandy <jimb@redhat.com>
parents:
1542
diff
changeset
|
188 but instead winds up to the right of the rectangle." |
36 | 189 (interactive "r") |
1619
6147d2164331
* rect.el (operate-on-rectangle): Use move-to-column's FORCE
Jim Blandy <jimb@redhat.com>
parents:
1542
diff
changeset
|
190 (operate-on-rectangle 'open-rectangle-line start end nil) |
6147d2164331
* rect.el (operate-on-rectangle): Use move-to-column's FORCE
Jim Blandy <jimb@redhat.com>
parents:
1542
diff
changeset
|
191 (goto-char start)) |
36 | 192 |
193 (defun open-rectangle-line (startpos begextra endextra) | |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
194 ;; Column where rectangle ends. |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
195 (let ((endcol (+ (current-column) endextra)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
196 whitewidth) |
36 | 197 (goto-char startpos) |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
198 ;; Column where rectangle begins. |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
199 (let ((begcol (- (current-column) begextra))) |
36 | 200 (skip-chars-forward " \t") |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
201 ;; Width of whitespace to be deleted and recreated. |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
202 (setq whitewidth (- (current-column) begcol))) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
203 ;; Delete the whitespace following the start column. |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
204 (delete-region startpos (point)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
205 ;; Open the desired width, plus same amount of whitespace we just deleted. |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
206 (indent-to (+ endcol whitewidth)))) |
36 | 207 |
258 | 208 ;;;###autoload |
22205
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
209 (defun close-rectangle (start end) |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
210 "Delete all whitespace following a specified column in each line. |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
211 The left edge of the rectangle specifies the position in each line |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
212 at which whitespace deletion should begin. On each line in the |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
213 rectangle, all continuous whitespace starting at that column is deleted." |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
214 (interactive "r") |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
215 (operate-on-rectangle '(lambda (startpos begextra endextra) |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
216 (save-excursion |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
217 (goto-char startpos) |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
218 (delete-region (point) |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
219 (progn |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
220 (skip-syntax-forward " ") |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
221 (point))))) |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
222 start end t)) |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
223 |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
224 ;; string-rectangle uses this variable to pass the string |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
225 ;; to string-rectangle-line. |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
226 (defvar string-rectangle-string) |
22205
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
227 |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
228 ;;;###autoload |
2637
45ecb9b4a6da
(string-rectangle): Renamed from fill-rectangle.
Richard M. Stallman <rms@gnu.org>
parents:
2380
diff
changeset
|
229 (defun string-rectangle (start end string) |
45ecb9b4a6da
(string-rectangle): Renamed from fill-rectangle.
Richard M. Stallman <rms@gnu.org>
parents:
2380
diff
changeset
|
230 "Insert STRING on each line of the region-rectangle, shifting text right. |
45ecb9b4a6da
(string-rectangle): Renamed from fill-rectangle.
Richard M. Stallman <rms@gnu.org>
parents:
2380
diff
changeset
|
231 The left edge of the rectangle specifies the column for insertion. |
45ecb9b4a6da
(string-rectangle): Renamed from fill-rectangle.
Richard M. Stallman <rms@gnu.org>
parents:
2380
diff
changeset
|
232 This command does not delete or overwrite any existing text. |
45ecb9b4a6da
(string-rectangle): Renamed from fill-rectangle.
Richard M. Stallman <rms@gnu.org>
parents:
2380
diff
changeset
|
233 |
45ecb9b4a6da
(string-rectangle): Renamed from fill-rectangle.
Richard M. Stallman <rms@gnu.org>
parents:
2380
diff
changeset
|
234 Called from a program, takes three args; START, END and STRING." |
45ecb9b4a6da
(string-rectangle): Renamed from fill-rectangle.
Richard M. Stallman <rms@gnu.org>
parents:
2380
diff
changeset
|
235 (interactive "r\nsString rectangle: ") |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
236 (let ((string-rectangle-string string)) |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
237 (operate-on-rectangle 'string-rectangle-line start end t))) |
2380
e67f6d2679e3
(fill-rectangle) Added. Inspired by Lynn Slater's insert-box package in LCD,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2308
diff
changeset
|
238 |
2637
45ecb9b4a6da
(string-rectangle): Renamed from fill-rectangle.
Richard M. Stallman <rms@gnu.org>
parents:
2380
diff
changeset
|
239 (defun string-rectangle-line (startpos begextra endextra) |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
240 (let (whitespace) |
2380
e67f6d2679e3
(fill-rectangle) Added. Inspired by Lynn Slater's insert-box package in LCD,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2308
diff
changeset
|
241 (goto-char startpos) |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
242 ;; Compute horizontal width of following whitespace. |
2380
e67f6d2679e3
(fill-rectangle) Added. Inspired by Lynn Slater's insert-box package in LCD,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2308
diff
changeset
|
243 (let ((ocol (current-column))) |
e67f6d2679e3
(fill-rectangle) Added. Inspired by Lynn Slater's insert-box package in LCD,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2308
diff
changeset
|
244 (skip-chars-forward " \t") |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
245 (setq whitespace (- (current-column) ocol))) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
246 ;; Delete the following whitespace. |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
247 (delete-region startpos (point)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
248 ;; Insert the desired string. |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
249 (insert string-rectangle-string) |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
250 ;; Insert the same width of whitespace that we had before. |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
251 (indent-to (+ (current-column) whitespace)))) |
2380
e67f6d2679e3
(fill-rectangle) Added. Inspired by Lynn Slater's insert-box package in LCD,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2308
diff
changeset
|
252 |
e67f6d2679e3
(fill-rectangle) Added. Inspired by Lynn Slater's insert-box package in LCD,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2308
diff
changeset
|
253 ;;;###autoload |
36 | 254 (defun clear-rectangle (start end) |
255 "Blank out rectangle with corners at point and mark. | |
256 The text previously in the region is overwritten by the blanks. | |
257 When called from a program, requires two args which specify the corners." | |
258 (interactive "r") | |
259 (operate-on-rectangle 'clear-rectangle-line start end t)) | |
260 | |
261 (defun clear-rectangle-line (startpos begextra endextra) | |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
262 ;; Find end of whitespace after the rectangle. |
36 | 263 (skip-chars-forward " \t") |
264 (let ((column (+ (current-column) endextra))) | |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
265 ;; Delete the text in the rectangle, and following whitespace. |
36 | 266 (delete-region (point) |
267 (progn (goto-char startpos) | |
268 (skip-chars-backward " \t") | |
269 (point))) | |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
270 ;; Reindent out to same column that we were at. |
36 | 271 (indent-to column))) |
272 | |
1619
6147d2164331
* rect.el (operate-on-rectangle): Use move-to-column's FORCE
Jim Blandy <jimb@redhat.com>
parents:
1542
diff
changeset
|
273 (provide 'rect) |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
274 |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
275 ;;; rect.el ends here |