annotate lisp/prim/rect.el @ 0:376386a54a3c r19-14

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