annotate lisp/rect.el @ 5905:85fd1ab80057

Fix a bug in #'parse-integer with negative bignums and non-nil JUNK-ALLOWED src/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * data.c (parse_integer): Fix a bug here with the interaction of negative bignums and a non-zero JUNK-ALLOWED argument. tests/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Check for a bug just fixed with the interaction of negative bignums and :junk-allowed non-nil.
author Aidan Kehoe <kehoea@parhasard.net>
date Fri, 08 May 2015 16:24:57 +0100
parents 308d34e9f07d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; rect.el --- rectangle functions for XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3 ;; Copyright (C) 1985-2000 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5 ;; Maintainer: Didier Verna <didier@xemacs.org>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Keywords: internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 686
diff changeset
10 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 686
diff changeset
11 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 686
diff changeset
12 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 686
diff changeset
13 ;; option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 686
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 686
diff changeset
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 686
diff changeset
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 686
diff changeset
18 ;; for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 686
diff changeset
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;;; Synched up with: to be incorporated in a forthcoming GNU Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;; This package provides the operations on rectangles that are documented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;; in the XEmacs Reference Manual.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
30 ;; #### NOTE: this file has been almost completely rewritten by Didier Verna
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
31 ;; <didier@xemacs.org>, Jul 99. The purpose of this rewrite is to be less
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; intrusive and fill lines with whitespaces only when needed. A few functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; are untouched though, as noted above their definition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
38 ;; #### NOTE: this function is untouched, but not used anymore.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; `apply-on-rectangle' is used instead. It's still there because it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;; documented so people might use it in their code, so I've decided not to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;; touch it. --dv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 ;; XEmacs: extra-args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 (defun operate-on-rectangle (function start end coerce-tabs &rest extra-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 "Call FUNCTION for each line of rectangle with corners at START, END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 If COERCE-TABS is non-nil, convert multi-column characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 that span the starting or ending columns on any line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 to multiple spaces before calling FUNCTION.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 FUNCTION is called with three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 position of start of segment of this line within the rectangle,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 number of columns that belong to rectangle but are before that position,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 number of columns that belong to rectangle but are after point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 Point is at the end of the segment of this line within the rectangle."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 (let (startcol startlinepos endcol endlinepos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 (setq startcol (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 (setq startlinepos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 (setq endcol (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (setq endlinepos (point-marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 (if (< endcol startcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 (let ((tem startcol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 (setq startcol endcol endcol tem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (goto-char startlinepos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (while (< (point) endlinepos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 (let (startpos begextra endextra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (move-to-column startcol coerce-tabs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 (setq begextra (- (current-column) startcol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (setq startpos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (move-to-column endcol coerce-tabs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 (setq endextra (- endcol (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (if (< begextra 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (setq endextra (+ endextra begextra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 begextra 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 (if (< endextra 0) (setq endextra 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (apply function startpos begextra endextra extra-args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (forward-line 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (- endcol startcol)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 ;; The replacement for `operate-on-rectangle' -- dv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (defun apply-on-rectangle (function start end &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 "Call FUNCTION for each line of rectangle with corners at START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 FUNCTION is called with two arguments: the start and end columns of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 rectangle, plus ARGS extra arguments. Point is at the beginning of line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 when the function is called."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 (let (startcol startpt endcol endpt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (setq startcol (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 (setq startpt (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 (setq endcol (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 (setq endpt (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 ;; ensure the start column is the left one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 (if (< endcol startcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 (let ((col startcol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (setq startcol endcol endcol col)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ;; start looping over lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (goto-char startpt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 (while (< (point) endpt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 (apply function startcol endcol args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 (forward-line 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
113 (defun delete-rectangle-line (startcol endcol fill)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
114 (let ((pt (point-at-eol)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
115 (when (= (move-to-column startcol (or fill 'coerce)) startcol)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
116 (if (and (not fill) (<= pt endcol))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
117 (delete-region (point) pt)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
118 ;; else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
119 (setq pt (point))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
120 (move-to-column endcol t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
121 (delete-region pt (point))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
122 ))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (defun delete-rectangle (start end &optional fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 "Delete the text in the region-rectangle without saving it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 The same range of columns is deleted in each line starting with the line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 where the region begins and ending with the line where the region ends.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 When called from a program, the rectangle's corners are START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 With a prefix (or FILL) argument, also fill lines where nothing has to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 deleted."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (interactive "*r\nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (apply-on-rectangle 'delete-rectangle-line start end fill))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
137 ;; I love ascii art ;-)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
138 (defconst spaces-strings '[""
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
139 " "
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
140 " "
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
141 " "
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
142 " "
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
143 " "
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
144 " "
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
145 " "
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
146 " "])
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
148 ;; This function is untouched --dv
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
149 (defun spaces-string (n)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
150 (if (<= n 8) (aref spaces-strings n)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
151 (let ((val ""))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
152 (while (> n 8)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
153 (setq val (concat " " val)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
154 n (- n 8)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
155 (concat val (aref spaces-strings n)))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
156
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (defun delete-extract-rectangle-line (startcol endcol lines fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (let ((pt (point-at-eol)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (if (< (move-to-column startcol (or fill 'coerce)) startcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (setcdr lines (cons (spaces-string (- endcol startcol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (cdr lines)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 ;; else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (setq pt (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (move-to-column endcol t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (setcdr lines (cons (buffer-substring pt (point)) (cdr lines)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 (delete-region pt (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 ;;;###autoload
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
171 (defun delete-extract-rectangle (start end &optional fill)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
172 "Delete the contents of the rectangle with corners at START and END, and
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
173 return it as a list of strings, one for each line of the rectangle.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
174
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
175 With an optional FILL argument, also fill lines where nothing has to be
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
176 deleted."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (let ((lines (list nil)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
178 (apply-on-rectangle 'delete-extract-rectangle-line start end lines fill)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (nreverse (cdr lines))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
181
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
182 ;; #### NOTE: this is actually the only function that needs to do complicated
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 ;; stuff like what's happening in `operate-on-rectangle', because the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 ;; might be read-only. --dv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 (defun extract-rectangle-line (startcol endcol lines)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (let (start end begextra endextra line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (move-to-column startcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (setq start (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 begextra (- (current-column) startcol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (move-to-column endcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (setq end (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 endextra (- endcol (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 (setq line (buffer-substring start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (if (< begextra 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (setq endextra (+ endextra begextra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 begextra 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 (if (< endextra 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (setq endextra 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (while (search-forward "\t" end t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (let ((width (- (current-column)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
202 (save-excursion (backward-char 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (current-column)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (setq line (concat (substring line 0 (- (point) end 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (spaces-string width)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (substring line (+ (length line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (- (point) end)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (if (or (> begextra 0) (> endextra 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (setq line (concat (spaces-string begextra)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (spaces-string endextra))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (setcdr lines (cons line (cdr lines)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
214 ;;;###autoload
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
215 (defun extract-rectangle (start end)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
216 "Return the contents of the rectangle with corners at START and END,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
217 as a list of strings, one for each line of the rectangle."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
218 (let ((lines (list nil)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
219 (apply-on-rectangle 'extract-rectangle-line start end lines)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
220 (nreverse (cdr lines))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
221
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
222
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
223 ;;;###autoload
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
224 (defvar killed-rectangle nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
225 "Rectangle for `yank-rectangle' to insert.")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
226
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
227 ;;;###autoload
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
228 (defun kill-rectangle (start end &optional fill)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
229 "Delete the region-rectangle and save it as the last killed one.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
230 You might prefer to use `delete-extract-rectangle' from a program.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
231
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
232 When called from a program, the rectangle's corners are START and END.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
233 With a prefix (or FILL) argument, also fill lines where nothing has to be
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
234 deleted."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
235 (interactive "*r\nP")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
236 (when buffer-read-only
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
237 (setq killed-rectangle (extract-rectangle start end))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
238 (barf-if-buffer-read-only))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
239 (setq killed-rectangle (delete-extract-rectangle start end fill)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
240
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 ;; This function is untouched --dv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (defun yank-rectangle ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 "Yank the last killed rectangle with upper left corner at point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (insert-rectangle killed-rectangle))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
248
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 ;; This function is untouched --dv
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (defun insert-rectangle (rectangle)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 "Insert text of RECTANGLE with upper left corner at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 RECTANGLE's first line is inserted at point, its second
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 line is inserted at a point vertically under point, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 RECTANGLE should be a list of strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 After this command, the mark is at the upper left corner
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 and point is at the lower right corner."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (let ((lines rectangle)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (insertcolumn (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (first t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (push-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (while lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (or first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (or (bolp) (insert ?\n))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (move-to-column insertcolumn t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (setq first nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (insert (car lines))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (setq lines (cdr lines)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
272
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
273 (defun open-rectangle-line (startcol endcol fill)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
274 (when (= (move-to-column startcol (or fill 'coerce)) startcol)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
275 (unless (and (not fill)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
276 (= (point) (point-at-eol)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
277 (indent-to endcol))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
278
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (defun open-rectangle (start end &optional fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 "Blank out the region-rectangle, shifting text right.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 When called from a program, the rectangle's corners are START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 With a prefix (or FILL) argument, fill with blanks even if there is no text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 on the right side of the rectangle."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (interactive "*r\nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (apply-on-rectangle 'open-rectangle-line start end fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (goto-char start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
290
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
291 (defun string-rectangle-line (startcol endcol string delete)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
292 (move-to-column startcol t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
293 (if delete
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
294 (delete-rectangle-line startcol endcol nil))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
295 (insert string))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (defun string-rectangle (start end string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 "Insert STRING on each line of the region-rectangle, shifting text right.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
300 The left edge of the rectangle specifies the column for insertion.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
301
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
302 If `pending-delete-mode' is active the string replace the region.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
303 Otherwise this command does not delete or overwrite any existing text.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 When called from a program, the rectangle's corners are START and END."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (interactive "*r\nsString rectangle: ")
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
307 (defvar pending-delete-mode)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
308 (apply-on-rectangle 'string-rectangle-line start end string
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
309 (and (boundp 'pending-delete-mode) pending-delete-mode)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
686
c82f9db998d7 [xemacs-hg @ 2001-12-03 18:02:47 by didierv]
didierv
parents: 446
diff changeset
311 ;;;###autoload
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
312 (defun replace-rectangle (start end string)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
313 "Like `string-rectangle', but unconditionally replace the original region,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
314 as if `pending-delete-mode' were active."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
315 (interactive "*r\nsString rectangle: ")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
316 (apply-on-rectangle 'string-rectangle-line start end string t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (defun clear-rectangle-line (startcol endcol fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (let ((pt (point-at-eol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 spaces)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 (when (= (move-to-column startcol (or fill 'coerce)) startcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (if (and (not fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (<= (save-excursion (goto-char pt) (current-column)) endcol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (delete-region (point) pt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 ;; else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (setq pt (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (move-to-column endcol t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (setq spaces (- (point) pt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (delete-region pt (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (indent-to (+ (current-column) spaces))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
334 ;;;###autoload
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
335 (defun clear-rectangle (start end &optional fill)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
336 "Blank out the region-rectangle.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
337 The text previously in the region is overwritten with blanks.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
338
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
339 When called from a program, the rectangle's corners are START and END.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
340 With a prefix (or FILL) argument, also fill with blanks the parts of the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
341 rectangle which were empty."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
342 (interactive "*r\nP")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
343 (apply-on-rectangle 'clear-rectangle-line start end fill))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
344
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
345
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (provide 'rect)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 ;;; rect.el ends here