comparison lisp/rect.el @ 25379:167c69238538

Add/fix various doc strings. Add `*' to all the interactive specs.
author Dave Love <fx@gnu.org>
date Mon, 23 Aug 1999 14:28:34 +0000
parents d9fa9f9ceb21
children b5ef1f54a2ca
comparison
equal deleted inserted replaced
25378:2d5cc3c9d8dc 25379:167c69238538
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA. 23 ;; Boston, MA 02111-1307, USA.
24 24
25 ;;; Commentary: 25 ;;; Commentary:
26 26
27 ;; This package provides the operations on rectangles that are ocumented 27 ;; This package provides the operations on rectangles that are documented
28 ;; in the Emacs manual. 28 ;; in the Emacs manual.
29 29
30 ;; ### NOTE: this file has been almost completely rewritten by Didier Verna 30 ;; ### NOTE: this file has been almost completely rewritten by Didier Verna
31 ;; <verna@inf.enst.fr> in July 1999. The purpose of this rewrite is to be less 31 ;; <verna@inf.enst.fr> in July 1999. The purpose of this rewrite is to be less
32 ;; intrusive and fill lines with whitespaces only when needed. A few functions 32 ;; intrusive and fill lines with whitespaces only when needed. A few functions
109 109
110 ;; The replacement for `operate-on-rectangle' -- dv 110 ;; The replacement for `operate-on-rectangle' -- dv
111 (defun apply-on-rectangle (function start end &rest args) 111 (defun apply-on-rectangle (function start end &rest args)
112 "Call FUNCTION for each line of rectangle with corners at START, END. 112 "Call FUNCTION for each line of rectangle with corners at START, END.
113 FUNCTION is called with two arguments: the start and end columns of the 113 FUNCTION is called with two arguments: the start and end columns of the
114 rectangle, plus ARGS extra arguments. Point is at the beginning of line when 114 rectangle, plus ARGS extra arguments. Point is at the beginning of line when
115 the function is called." 115 the function is called."
116 (let (startcol startpt endcol endpt) 116 (let (startcol startpt endcol endpt)
117 (save-excursion 117 (save-excursion
118 (goto-char start) 118 (goto-char start)
119 (setq startcol (current-column)) 119 (setq startcol (current-column))
201 n (- n 8))) 201 n (- n 8)))
202 (concat val (aref spaces-strings n))))) 202 (concat val (aref spaces-strings n)))))
203 203
204 ;;;###autoload 204 ;;;###autoload
205 (defun delete-rectangle (start end &optional fill) 205 (defun delete-rectangle (start end &optional fill)
206 "Delete (don't save) text in rectangle with corners at point and mark (START 206 "Delete (don't save) text in the region-rectangle.
207 and END when called from a program). The same range of columns is deleted in 207 The same range of columns is deleted in each line starting with the
208 each line starting with the line where the region begins and ending with the 208 line where the region begins and ending with the line where the region
209 line where the region ends. 209 ends.
210 210
211 With a prefix (or a FILL) argument, also fill lines where nothing has to be 211 When called from a program the rectangle's corners are START and END.
212 deleted." 212 With a prefix (or a FILL) argument, also fill lines where nothing has
213 (interactive "r\nP") 213 to be deleted."
214 (interactive "*r\nP")
214 (apply-on-rectangle 'delete-rectangle-line start end fill)) 215 (apply-on-rectangle 'delete-rectangle-line start end fill))
215 216
216 ;;;###autoload 217 ;;;###autoload
217 (defun delete-extract-rectangle (start end &optional fill) 218 (defun delete-extract-rectangle (start end &optional fill)
218 "Delete the contents of the rectangle with corners at START and END, and 219 "Delete the contents of the region-rectangle.
219 return it as a list of strings, one for each line of the rectangle. 220 Return it as a list of strings, one for each line of the rectangle.
220 221
222 When called from a program the rectangle's corners are START and END.
221 With an optional FILL argument, also fill lines where nothing has to be 223 With an optional FILL argument, also fill lines where nothing has to be
222 deleted." 224 deleted."
223 (let ((lines (list nil))) 225 (let ((lines (list nil)))
224 (apply-on-rectangle 'delete-extract-rectangle-line start end lines fill) 226 (apply-on-rectangle 'delete-extract-rectangle-line start end lines fill)
225 (nreverse (cdr lines)))) 227 (nreverse (cdr lines))))
226 228
227 ;;;###autoload 229 ;;;###autoload
228 (defun extract-rectangle (start end) 230 (defun extract-rectangle (start end)
229 "Return the contents of the rectangle with corners at START and END, 231 "Return the contents of the rectangle with corners at START and END.
230 as a list of strings, one for each line of the rectangle." 232 Return it as a list of strings, one for each line of the rectangle."
231 (let ((lines (list nil))) 233 (let ((lines (list nil)))
232 (apply-on-rectangle 'extract-rectangle-line start end lines) 234 (apply-on-rectangle 'extract-rectangle-line start end lines)
233 (nreverse (cdr lines)))) 235 (nreverse (cdr lines))))
234 236
235 (defvar killed-rectangle nil 237 (defvar killed-rectangle nil
236 "Rectangle for yank-rectangle to insert.") 238 "Rectangle for `yank-rectangle' to insert.")
237 239
238 ;;;###autoload 240 ;;;###autoload
239 (defun kill-rectangle (start end &optional fill) 241 (defun kill-rectangle (start end &optional fill)
240 "Delete the rectangle with corners at point and mark (START and END when 242 "Delete the region-rectangle and save it as the last killed one.
241 called from a program) and save it as the last killed one. You might prefer to 243
242 use `delete-extract-rectangle' from a program. 244 When called from a program the rectangle's corners are START and END.
245 You might prefer to use `delete-extract-rectangle' from a program.
243 246
244 With a prefix (or a FILL) argument, also fill lines where nothing has to be 247 With a prefix (or a FILL) argument, also fill lines where nothing has to be
245 deleted." 248 deleted."
246 (interactive "r\nP") 249 (interactive "*r\nP")
247 (when buffer-read-only 250 (when buffer-read-only
248 (setq killed-rectangle (extract-rectangle start end)) 251 (setq killed-rectangle (extract-rectangle start end))
249 (barf-if-buffer-read-only)) 252 (barf-if-buffer-read-only))
250 (setq killed-rectangle (delete-extract-rectangle start end fill))) 253 (setq killed-rectangle (delete-extract-rectangle start end fill)))
251 254
252 ;; this one is untouched --dv 255 ;; this one is untouched --dv
253 ;;;###autoload 256 ;;;###autoload
254 (defun yank-rectangle () 257 (defun yank-rectangle ()
255 "Yank the last killed rectangle with upper left corner at point." 258 "Yank the last killed rectangle with upper left corner at point."
256 (interactive) 259 (interactive "*")
257 (insert-rectangle killed-rectangle)) 260 (insert-rectangle killed-rectangle))
258 261
259 ;; this one is untoutched --dv 262 ;; this one is untoutched --dv
260 ;;;###autoload 263 ;;;###autoload
261 (defun insert-rectangle (rectangle) 264 (defun insert-rectangle (rectangle)
279 (insert (car lines)) 282 (insert (car lines))
280 (setq lines (cdr lines))))) 283 (setq lines (cdr lines)))))
281 284
282 ;;;###autoload 285 ;;;###autoload
283 (defun open-rectangle (start end &optional fill) 286 (defun open-rectangle (start end &optional fill)
284 "Blank out rectangle with corners at point and mark (START and END when 287 "Blank out the region-rectangle, shifting text right.
285 called from a program), shifting text right. The text previously in the region 288
286 is not overwritten by the blanks, but instead winds up to the right of the 289 The text previously in the region is not overwritten by the blanks,
287 rectangle. 290 but instead winds up to the right of the rectangle.
288 291
292 When called from a program the rectangle's corners are START and END.
289 With a prefix (or a FILL) argument, fill with blanks even if there is no text 293 With a prefix (or a FILL) argument, fill with blanks even if there is no text
290 on the right side of the rectangle." 294 on the right side of the rectangle."
291 (interactive "r\nP") 295 (interactive "*r\nP")
292 (apply-on-rectangle 'open-rectangle-line start end fill) 296 (apply-on-rectangle 'open-rectangle-line start end fill)
293 (goto-char start)) 297 (goto-char start))
294 298
295 (defun open-rectangle-line (startcol endcol fill) 299 (defun open-rectangle-line (startcol endcol fill)
296 (let (spaces) 300 (let (spaces)
312 "Delete all whitespace following a specified column in each line. 316 "Delete all whitespace following a specified column in each line.
313 The left edge of the rectangle specifies the position in each line 317 The left edge of the rectangle specifies the position in each line
314 at which whitespace deletion should begin. On each line in the 318 at which whitespace deletion should begin. On each line in the
315 rectangle, all continuous whitespace starting at that column is deleted. 319 rectangle, all continuous whitespace starting at that column is deleted.
316 320
321 When called from a program the rectangle's corners are START and END.
317 With a prefix (or a FILL) argument, also fill too short lines." 322 With a prefix (or a FILL) argument, also fill too short lines."
318 (interactive "r\nP") 323 (interactive "*r\nP")
319 (apply-on-rectangle 'delete-whitespace-rectangle-line start end fill)) 324 (apply-on-rectangle 'delete-whitespace-rectangle-line start end fill))
320 325
321 ;; not used any more --dv 326 ;; not used any more --dv
322 ;; string-rectangle uses this variable to pass the string 327 ;; string-rectangle uses this variable to pass the string
323 ;; to string-rectangle-line. 328 ;; to string-rectangle-line.
324 (defvar string-rectangle-string) 329 (defvar string-rectangle-string)
325 330
326 ;;;###autoload 331 ;;;###autoload
327 (defun string-rectangle (start end string) 332 (defun string-rectangle (start end string)
328 "Insert STRING on each line of the rectangle with corners at point and mark 333 "Insert STRING on each line of the region-rectangle, shifting text right.
329 (START and END when called from a program), shifting text right. The left edge 334
330 of the rectangle specifies the column for insertion. This command does not 335 When called from a program the rectangle's corners are START and END.
331 delete or overwrite any existing text." 336 The left edge of the rectangle specifies the column for insertion.
332 (interactive "r\nsString rectangle: ") 337 This command does not delete or overwrite any existing text."
338 (interactive "*r\nsString rectangle: ")
333 (apply-on-rectangle 'string-rectangle-line start end string)) 339 (apply-on-rectangle 'string-rectangle-line start end string))
334 340
335 (defun string-rectangle-line (startcol endcol string) 341 (defun string-rectangle-line (startcol endcol string)
336 (move-to-column-force startcol) 342 (move-to-column-force startcol)
337 (insert string)) 343 (insert string))
338 344
339 ;;;###autoload 345 ;;;###autoload
340 (defun clear-rectangle (start end &optional fill) 346 (defun clear-rectangle (start end &optional fill)
341 "Blank out the rectangle with corners at point and mark (START and END when 347 "Blank out the region-rectangle.
342 called from a program). The text previously in the region is overwritten with 348 The text previously in the region is overwritten with blanks.
343 blanks. 349
344 350 When called from a program the rectangle's corners are START and END.
345 With a prefix (or a FILL) argument, also fill with blanks the parts of the 351 With a prefix (or a FILL) argument, also fill with blanks the parts of the
346 rectangle which were empty." 352 rectangle which were empty."
347 (interactive "r\nP") 353 (interactive "*r\nP")
348 (apply-on-rectangle 'clear-rectangle-line start end fill)) 354 (apply-on-rectangle 'clear-rectangle-line start end fill))
349 355
350 (defun clear-rectangle-line (startcol endcol fill) 356 (defun clear-rectangle-line (startcol endcol fill)
351 (let ((pt (point-at-eol)) 357 (let ((pt (point-at-eol))
352 spaces) 358 spaces)