annotate lisp/rect.el @ 267:966663fcf606 r20-5b32

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