Mercurial > emacs
annotate lisp/rect.el @ 67565:72450e5d47ba
(isearch-query-replace): Check for isearch-other-end.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Wed, 14 Dec 2005 07:49:42 +0000 |
parents | ed770a0a7846 |
children | 3bd95f4f2941 ee12d75eb214 |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37444
diff
changeset
|
1 ;;; rect.el --- rectangle functions for GNU Emacs |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
3 ;; Copyright (C) 1985, 1999, 2000, 2001, 2002, 2003, 2004 |
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
4 ;; 2005 Free Software Foundation, Inc. |
845 | 5 |
39537
133fc59b5c6a
Update maintainer's email address.
Eli Zaretskii <eliz@gnu.org>
parents:
38436
diff
changeset
|
6 ;; Maintainer: Didier Verna <didier@xemacs.org> |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
7 ;; Keywords: internal |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
8 |
36 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
789
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
36 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64091 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
36 | 25 |
2308
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1619
diff
changeset
|
26 ;;; Commentary: |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1619
diff
changeset
|
27 |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
28 ;; This package provides the operations on rectangles that are documented |
2308
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1619
diff
changeset
|
29 ;; in the Emacs manual. |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1619
diff
changeset
|
30 |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
31 ;; ### NOTE: this file has been almost completely rewritten by Didier Verna |
39537
133fc59b5c6a
Update maintainer's email address.
Eli Zaretskii <eliz@gnu.org>
parents:
38436
diff
changeset
|
32 ;; <didier@xemacs.org> in July 1999. The purpose of this rewrite is to be less |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
33 ;; intrusive and fill lines with whitespaces only when needed. A few functions |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
34 ;; are untouched though, as noted above their definition. |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
35 |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
36 |
789
71d052f72ac1
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
659
diff
changeset
|
37 ;;; Code: |
36 | 38 |
23757
717a33da04a1
(move-to-column-force): New function.
Kenichi Handa <handa@m17n.org>
parents:
23641
diff
changeset
|
39 ;;;###autoload |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
40 (defun move-to-column-force (column &optional flag) |
46054
06ea4b707bb2
(move-to-column-force): Likewise.
Juanma Barranquero <lekktu@gmail.com>
parents:
45168
diff
changeset
|
41 "If COLUMN is within a multi-column character, replace it by spaces and tab. |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
42 As for `move-to-column', passing anything but nil or t in FLAG will move to |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
43 the desired column only if the line is long enough." |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
44 (move-to-column column (or flag t))) |
46512
8e08ec435afd
(move-to-column-force): Add autoload cookie to obsolescence declaration.
Juanma Barranquero <lekktu@gmail.com>
parents:
46054
diff
changeset
|
45 |
8e08ec435afd
(move-to-column-force): Add autoload cookie to obsolescence declaration.
Juanma Barranquero <lekktu@gmail.com>
parents:
46054
diff
changeset
|
46 ;;;###autoload |
46054
06ea4b707bb2
(move-to-column-force): Likewise.
Juanma Barranquero <lekktu@gmail.com>
parents:
45168
diff
changeset
|
47 (make-obsolete 'move-to-column-force 'move-to-column "21.2") |
23757
717a33da04a1
(move-to-column-force): New function.
Kenichi Handa <handa@m17n.org>
parents:
23641
diff
changeset
|
48 |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
49 ;; not used any more --dv |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
50 ;; extract-rectangle-line stores lines into this list |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
51 ;; to accumulate them for extract-rectangle and delete-extract-rectangle. |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
52 (defvar operate-on-rectangle-lines) |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
53 |
30283
70a7936c29c5
(open-rectangle-line): Remove unused let.
Dave Love <fx@gnu.org>
parents:
28078
diff
changeset
|
54 ;; ### NOTE: this function is untouched, but not used anymore apart from |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
55 ;; `delete-whitespace-rectangle'. `apply-on-rectangle' is used instead. --dv |
36 | 56 (defun operate-on-rectangle (function start end coerce-tabs) |
57 "Call FUNCTION for each line of rectangle with corners at START, END. | |
58 If COERCE-TABS is non-nil, convert multi-column characters | |
59 that span the starting or ending columns on any line | |
60 to multiple spaces before calling FUNCTION. | |
61 FUNCTION is called with three arguments: | |
62 position of start of segment of this line within the rectangle, | |
63 number of columns that belong to rectangle but are before that position, | |
64 number of columns that belong to rectangle but are after point. | |
65 Point is at the end of the segment of this line within the rectangle." | |
66 (let (startcol startlinepos endcol endlinepos) | |
67 (save-excursion | |
68 (goto-char start) | |
69 (setq startcol (current-column)) | |
70 (beginning-of-line) | |
71 (setq startlinepos (point))) | |
72 (save-excursion | |
73 (goto-char end) | |
74 (setq endcol (current-column)) | |
75 (forward-line 1) | |
76 (setq endlinepos (point-marker))) | |
77 (if (< endcol startcol) | |
1619
6147d2164331
* rect.el (operate-on-rectangle): Use move-to-column's FORCE
Jim Blandy <jimb@redhat.com>
parents:
1542
diff
changeset
|
78 (setq startcol (prog1 endcol (setq endcol startcol)))) |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
79 (save-excursion |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
80 (goto-char startlinepos) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
81 (while (< (point) endlinepos) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
82 (let (startpos begextra endextra) |
23757
717a33da04a1
(move-to-column-force): New function.
Kenichi Handa <handa@m17n.org>
parents:
23641
diff
changeset
|
83 (if coerce-tabs |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
84 (move-to-column startcol t) |
23757
717a33da04a1
(move-to-column-force): New function.
Kenichi Handa <handa@m17n.org>
parents:
23641
diff
changeset
|
85 (move-to-column startcol)) |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
86 (setq begextra (- (current-column) startcol)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
87 (setq startpos (point)) |
23757
717a33da04a1
(move-to-column-force): New function.
Kenichi Handa <handa@m17n.org>
parents:
23641
diff
changeset
|
88 (if coerce-tabs |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
89 (move-to-column endcol t) |
23757
717a33da04a1
(move-to-column-force): New function.
Kenichi Handa <handa@m17n.org>
parents:
23641
diff
changeset
|
90 (move-to-column endcol)) |
19732
d8478556c7f0
(operate-on-rectangle): If we overshoot when looking for endcol, back up.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
91 ;; If we overshot, move back one character |
d8478556c7f0
(operate-on-rectangle): If we overshoot when looking for endcol, back up.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
92 ;; so that endextra will be positive. |
d8478556c7f0
(operate-on-rectangle): If we overshoot when looking for endcol, back up.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
93 (if (and (not coerce-tabs) (> (current-column) endcol)) |
d8478556c7f0
(operate-on-rectangle): If we overshoot when looking for endcol, back up.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
94 (backward-char 1)) |
5787
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
95 (setq endextra (- endcol (current-column))) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
96 (if (< begextra 0) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
97 (setq endextra (+ endextra begextra) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
98 begextra 0)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
99 (funcall function startpos begextra endextra)) |
bef3a67ac893
(string-rectangle): Make operate-on-rectangle convert tabs.
Richard M. Stallman <rms@gnu.org>
parents:
2637
diff
changeset
|
100 (forward-line 1))) |
36 | 101 (- endcol startcol))) |
102 | |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
103 ;; The replacement for `operate-on-rectangle' -- dv |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
104 (defun apply-on-rectangle (function start end &rest args) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
105 "Call FUNCTION for each line of rectangle with corners at START, END. |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
106 FUNCTION is called with two arguments: the start and end columns of the |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
107 rectangle, plus ARGS extra arguments. Point is at the beginning of line when |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
108 the function is called." |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
109 (let (startcol startpt endcol endpt) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
110 (save-excursion |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
111 (goto-char start) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
112 (setq startcol (current-column)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
113 (beginning-of-line) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
114 (setq startpt (point)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
115 (goto-char end) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
116 (setq endcol (current-column)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
117 (forward-line 1) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
118 (setq endpt (point-marker)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
119 ;; ensure the start column is the left one. |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
120 (if (< endcol startcol) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
121 (let ((col startcol)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
122 (setq startcol endcol endcol col))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
123 ;; start looping over lines |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
124 (goto-char startpt) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
125 (while (< (point) endpt) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
126 (apply function startcol endcol args) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
127 (forward-line 1))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
128 )) |
36 | 129 |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
130 (defun delete-rectangle-line (startcol endcol fill) |
59783
b2ab001718c6
(delete-rectangle-line, delete-extract-rectangle-line)
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
131 (when (= (move-to-column startcol (if fill t 'coerce)) startcol) |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
132 (delete-region (point) |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
133 (progn (move-to-column endcol 'coerce) |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
134 (point))))) |
36 | 135 |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
136 (defun delete-extract-rectangle-line (startcol endcol lines fill) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
137 (let ((pt (point-at-eol))) |
59783
b2ab001718c6
(delete-rectangle-line, delete-extract-rectangle-line)
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
138 (if (< (move-to-column startcol (if fill t 'coerce)) startcol) |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
139 (setcdr lines (cons (spaces-string (- endcol startcol)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
140 (cdr lines))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
141 ;; else |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
142 (setq pt (point)) |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
143 (move-to-column endcol t) |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
144 (setcdr lines (cons (buffer-substring pt (point)) (cdr lines))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
145 (delete-region pt (point))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
146 )) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
147 |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
148 ;; ### NOTE: this is actually the only function that needs to do complicated |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
149 ;; stuff like what's happening in `operate-on-rectangle', because the buffer |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
150 ;; might be read-only. --dv |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
151 (defun extract-rectangle-line (startcol endcol lines) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
152 (let (start end begextra endextra line) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
153 (move-to-column startcol) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
154 (setq start (point) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
155 begextra (- (current-column) startcol)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
156 (move-to-column endcol) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
157 (setq end (point) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
158 endextra (- endcol (current-column))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
159 (setq line (buffer-substring start (point))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
160 (if (< begextra 0) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
161 (setq endextra (+ endextra begextra) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
162 begextra 0)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
163 (if (< endextra 0) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
164 (setq endextra 0)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
165 (goto-char start) |
36 | 166 (while (search-forward "\t" end t) |
167 (let ((width (- (current-column) | |
168 (save-excursion (forward-char -1) | |
169 (current-column))))) | |
170 (setq line (concat (substring line 0 (- (point) end 1)) | |
171 (spaces-string width) | |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
172 (substring line (+ (length line) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
173 (- (point) end))))))) |
36 | 174 (if (or (> begextra 0) (> endextra 0)) |
175 (setq line (concat (spaces-string begextra) | |
176 line | |
177 (spaces-string endextra)))) | |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
178 (setcdr lines (cons line (cdr lines))))) |
36 | 179 |
180 (defconst spaces-strings | |
181 '["" " " " " " " " " " " " " " " " "]) | |
182 | |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
183 ;; this one is untouched --dv |
36 | 184 (defun spaces-string (n) |
185 (if (<= n 8) (aref spaces-strings n) | |
186 (let ((val "")) | |
187 (while (> n 8) | |
188 (setq val (concat " " val) | |
189 n (- n 8))) | |
190 (concat val (aref spaces-strings n))))) | |
49597
e88404e8f2cf
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
46512
diff
changeset
|
191 |
258 | 192 ;;;###autoload |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
193 (defun delete-rectangle (start end &optional fill) |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
194 "Delete (don't save) text in the region-rectangle. |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
195 The same range of columns is deleted in each line starting with the |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
196 line where the region begins and ending with the line where the region |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
197 ends. |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
198 |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
199 When called from a program the rectangle's corners are START and END. |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
200 With a prefix (or a FILL) argument, also fill lines where nothing has |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
201 to be deleted." |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
202 (interactive "*r\nP") |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
203 (apply-on-rectangle 'delete-rectangle-line start end fill)) |
36 | 204 |
258 | 205 ;;;###autoload |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
206 (defun delete-extract-rectangle (start end &optional fill) |
25380
b5ef1f54a2ca
(delete-extract-rectangle): Doc fix from verna.
Dave Love <fx@gnu.org>
parents:
25379
diff
changeset
|
207 "Delete the contents of the rectangle with corners at START and END. |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
208 Return it as a list of strings, one for each line of the rectangle. |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
209 |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
210 When called from a program the rectangle's corners are START and END. |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
211 With an optional FILL argument, also fill lines where nothing has to be |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
212 deleted." |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
213 (let ((lines (list nil))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
214 (apply-on-rectangle 'delete-extract-rectangle-line start end lines fill) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
215 (nreverse (cdr lines)))) |
36 | 216 |
258 | 217 ;;;###autoload |
36 | 218 (defun extract-rectangle (start end) |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
219 "Return the contents of the rectangle with corners at START and END. |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
220 Return it as a list of strings, one for each line of the rectangle." |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
221 (let ((lines (list nil))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
222 (apply-on-rectangle 'extract-rectangle-line start end lines) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
223 (nreverse (cdr lines)))) |
36 | 224 |
225 (defvar killed-rectangle nil | |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
226 "Rectangle for `yank-rectangle' to insert.") |
36 | 227 |
258 | 228 ;;;###autoload |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
229 (defun kill-rectangle (start end &optional fill) |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
230 "Delete the region-rectangle and save it as the last killed one. |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
231 |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
232 When called from a program the rectangle's corners are START and END. |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
233 You might prefer to use `delete-extract-rectangle' from a program. |
36 | 234 |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
235 With a prefix (or a FILL) argument, also fill lines where nothing has to be |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
236 deleted." |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
237 (interactive "*r\nP") |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
238 (when buffer-read-only |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
239 (setq killed-rectangle (extract-rectangle start end)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
240 (barf-if-buffer-read-only)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
241 (setq killed-rectangle (delete-extract-rectangle start end fill))) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
242 |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
243 ;; this one is untouched --dv |
258 | 244 ;;;###autoload |
36 | 245 (defun yank-rectangle () |
246 "Yank the last killed rectangle with upper left corner at point." | |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
247 (interactive "*") |
36 | 248 (insert-rectangle killed-rectangle)) |
249 | |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
250 ;; this one is untoutched --dv |
258 | 251 ;;;###autoload |
36 | 252 (defun insert-rectangle (rectangle) |
253 "Insert text of RECTANGLE with upper left corner at point. | |
242 | 254 RECTANGLE's first line is inserted at point, its second |
255 line is inserted at a point vertically under point, etc. | |
1542
724b443e445d
(insert-rectangle): Put mark at upper left corner.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
256 RECTANGLE should be a list of strings. |
724b443e445d
(insert-rectangle): Put mark at upper left corner.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
257 After this command, the mark is at the upper left corner |
724b443e445d
(insert-rectangle): Put mark at upper left corner.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
258 and point is at the lower right corner." |
36 | 259 (let ((lines rectangle) |
260 (insertcolumn (current-column)) | |
261 (first t)) | |
1542
724b443e445d
(insert-rectangle): Put mark at upper left corner.
Richard M. Stallman <rms@gnu.org>
parents:
845
diff
changeset
|
262 (push-mark) |
36 | 263 (while lines |
264 (or first | |
265 (progn | |
266 (forward-line 1) | |
267 (or (bolp) (insert ?\n)) | |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
268 (move-to-column insertcolumn t))) |
36 | 269 (setq first nil) |
44676
37fdab0b94fa
(insert-rectangle): Use insert-for-yank.
Richard M. Stallman <rms@gnu.org>
parents:
44207
diff
changeset
|
270 (insert-for-yank (car lines)) |
36 | 271 (setq lines (cdr lines))))) |
272 | |
258 | 273 ;;;###autoload |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
274 (defun open-rectangle (start end &optional fill) |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
275 "Blank out the region-rectangle, shifting text right. |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
276 |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
277 The text previously in the region is not overwritten by the blanks, |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
278 but instead winds up to the right of the rectangle. |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
279 |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
280 When called from a program the rectangle's corners are START and END. |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
281 With a prefix (or a FILL) argument, fill with blanks even if there is no text |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
282 on the right side of the rectangle." |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
283 (interactive "*r\nP") |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
284 (apply-on-rectangle 'open-rectangle-line start end fill) |
1619
6147d2164331
* rect.el (operate-on-rectangle): Use move-to-column's FORCE
Jim Blandy <jimb@redhat.com>
parents:
1542
diff
changeset
|
285 (goto-char start)) |
36 | 286 |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
287 (defun open-rectangle-line (startcol endcol fill) |
59783
b2ab001718c6
(delete-rectangle-line, delete-extract-rectangle-line)
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
288 (when (= (move-to-column startcol (if fill t 'coerce)) startcol) |
30283
70a7936c29c5
(open-rectangle-line): Remove unused let.
Dave Love <fx@gnu.org>
parents:
28078
diff
changeset
|
289 (unless (and (not fill) |
70a7936c29c5
(open-rectangle-line): Remove unused let.
Dave Love <fx@gnu.org>
parents:
28078
diff
changeset
|
290 (= (point) (point-at-eol))) |
70a7936c29c5
(open-rectangle-line): Remove unused let.
Dave Love <fx@gnu.org>
parents:
28078
diff
changeset
|
291 (indent-to endcol)))) |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
292 |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
293 (defun delete-whitespace-rectangle-line (startcol endcol fill) |
59783
b2ab001718c6
(delete-rectangle-line, delete-extract-rectangle-line)
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
294 (when (= (move-to-column startcol (if fill t 'coerce)) startcol) |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
295 (unless (= (point) (point-at-eol)) |
37444
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
296 (delete-region (point) (progn (skip-syntax-forward " ") (point)))))) |
36 | 297 |
45168
4f3c96288c84
(close-rectangle): Don't hide it behind the autoload-cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44676
diff
changeset
|
298 ;;;###autoload |
4f3c96288c84
(close-rectangle): Don't hide it behind the autoload-cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44676
diff
changeset
|
299 (defalias 'close-rectangle 'delete-whitespace-rectangle) ;; Old name |
4f3c96288c84
(close-rectangle): Don't hide it behind the autoload-cookie.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
44676
diff
changeset
|
300 |
258 | 301 ;;;###autoload |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
302 (defun delete-whitespace-rectangle (start end &optional fill) |
22205
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
303 "Delete all whitespace following a specified column in each line. |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
304 The left edge of the rectangle specifies the position in each line |
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
305 at which whitespace deletion should begin. On each line in the |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
306 rectangle, all continuous whitespace starting at that column is deleted. |
22205
8576d32229fc
(close-rectangle): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19732
diff
changeset
|
307 |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
308 When called from a program the rectangle's corners are START and END. |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
309 With a prefix (or a FILL) argument, also fill too short lines." |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
310 (interactive "*r\nP") |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
311 (apply-on-rectangle 'delete-whitespace-rectangle-line start end fill)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
312 |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
313 ;; not used any more --dv |
22213
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
314 ;; string-rectangle uses this variable to pass the string |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
315 ;; to string-rectangle-line. |
84c3c863f0bd
(string-rectangle-string): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22205
diff
changeset
|
316 (defvar string-rectangle-string) |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
317 (defvar string-rectangle-history nil) |
33772
4787f33fe54f
(string-rectangle): Revert last change.
Dave Love <fx@gnu.org>
parents:
33750
diff
changeset
|
318 (defun string-rectangle-line (startcol endcol string delete) |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
319 (move-to-column startcol t) |
33772
4787f33fe54f
(string-rectangle): Revert last change.
Dave Love <fx@gnu.org>
parents:
33750
diff
changeset
|
320 (if delete |
4787f33fe54f
(string-rectangle): Revert last change.
Dave Love <fx@gnu.org>
parents:
33750
diff
changeset
|
321 (delete-rectangle-line startcol endcol nil)) |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
322 (insert string)) |
2380
e67f6d2679e3
(fill-rectangle) Added. Inspired by Lynn Slater's insert-box package in LCD,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2308
diff
changeset
|
323 |
e67f6d2679e3
(fill-rectangle) Added. Inspired by Lynn Slater's insert-box package in LCD,
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2308
diff
changeset
|
324 ;;;###autoload |
37444
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
325 (defun string-rectangle (start end string) |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
326 "Replace rectangle contents with STRING on each line. |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
327 The length of STRING need not be the same as the rectangle width. |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
328 |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
329 Called from a program, takes three args; START, END and STRING." |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
330 (interactive |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
331 (progn (barf-if-buffer-read-only) |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
332 (list |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
333 (region-beginning) |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
334 (region-end) |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
64762
diff
changeset
|
335 (read-string (format "String rectangle (default %s): " |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
336 (or (car string-rectangle-history) "")) |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
337 nil 'string-rectangle-history |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
338 (car string-rectangle-history))))) |
33772
4787f33fe54f
(string-rectangle): Revert last change.
Dave Love <fx@gnu.org>
parents:
33750
diff
changeset
|
339 (apply-on-rectangle 'string-rectangle-line start end string t)) |
28078
99865d22cc31
2000-09-01 Didier Verna <didier@xemacs.org>
Dave Love <fx@gnu.org>
parents:
25380
diff
changeset
|
340 |
44207
6c55bf040a71
(replace-rectangle): Add autoload.
Richard M. Stallman <rms@gnu.org>
parents:
43555
diff
changeset
|
341 ;;;###autoload |
37444
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
342 (defalias 'replace-rectangle 'string-rectangle) |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
343 |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
344 ;;;###autoload |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
345 (defun string-insert-rectangle (start end string) |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
346 "Insert STRING on each line of region-rectangle, shifting text right. |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
347 |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
348 When called from a program, the rectangle's corners are START and END. |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
349 The left edge of the rectangle specifies the column for insertion. |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
350 This command does not delete or overwrite any existing text." |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
351 (interactive |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
352 (progn (barf-if-buffer-read-only) |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
353 (list |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
354 (region-beginning) |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
355 (region-end) |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
64762
diff
changeset
|
356 (read-string (format "String insert rectangle (default %s): " |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
357 (or (car string-rectangle-history) "")) |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
358 nil 'string-rectangle-history |
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
359 (car string-rectangle-history))))) |
37444
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
360 (apply-on-rectangle 'string-rectangle-line start end string nil)) |
d5ed9aa37aa2
(string-rectangle): Revert to 20.x behaviour.
Gerd Moellmann <gerd@gnu.org>
parents:
33807
diff
changeset
|
361 |
28078
99865d22cc31
2000-09-01 Didier Verna <didier@xemacs.org>
Dave Love <fx@gnu.org>
parents:
25380
diff
changeset
|
362 ;;;###autoload |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
363 (defun clear-rectangle (start end &optional fill) |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
364 "Blank out the region-rectangle. |
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
365 The text previously in the region is overwritten with blanks. |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
366 |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
367 When called from a program the rectangle's corners are START and END. |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
368 With a prefix (or a FILL) argument, also fill with blanks the parts of the |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
369 rectangle which were empty." |
25379
167c69238538
Add/fix various doc strings. Add `*' to all the interactive specs.
Dave Love <fx@gnu.org>
parents:
25291
diff
changeset
|
370 (interactive "*r\nP") |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
371 (apply-on-rectangle 'clear-rectangle-line start end fill)) |
36 | 372 |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
373 (defun clear-rectangle-line (startcol endcol fill) |
43555
c33c91ae60fc
(clear-rectangle-line): Reindent to the same column
Richard M. Stallman <rms@gnu.org>
parents:
41173
diff
changeset
|
374 (let ((pt (point-at-eol))) |
59783
b2ab001718c6
(delete-rectangle-line, delete-extract-rectangle-line)
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
375 (when (= (move-to-column startcol (if fill t 'coerce)) startcol) |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
376 (if (and (not fill) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
377 (<= (save-excursion (goto-char pt) (current-column)) endcol)) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
378 (delete-region (point) pt) |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
379 ;; else |
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
380 (setq pt (point)) |
41173
e1285c5daeaf
(move-to-column-force): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
39537
diff
changeset
|
381 (move-to-column endcol t) |
43555
c33c91ae60fc
(clear-rectangle-line): Reindent to the same column
Richard M. Stallman <rms@gnu.org>
parents:
41173
diff
changeset
|
382 (setq endcol (current-column)) |
25168
0fbd51325497
All functions rewritten, except when noted above
Richard M. Stallman <rms@gnu.org>
parents:
23812
diff
changeset
|
383 (delete-region pt (point)) |
43555
c33c91ae60fc
(clear-rectangle-line): Reindent to the same column
Richard M. Stallman <rms@gnu.org>
parents:
41173
diff
changeset
|
384 (indent-to endcol))))) |
36 | 385 |
1619
6147d2164331
* rect.el (operate-on-rectangle): Use move-to-column's FORCE
Jim Blandy <jimb@redhat.com>
parents:
1542
diff
changeset
|
386 (provide 'rect) |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
387 |
52401 | 388 ;;; arch-tag: 178847b3-1f50-4b03-83de-a6e911cc1d16 |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
389 ;;; rect.el ends here |