annotate src/insdel.c @ 5460:3bd42ee22d1f

(start-process-shell-command): Doc fix.
author Richard M. Stallman <rms@gnu.org>
date Thu, 06 Jan 1994 04:39:00 +0000
parents 378540cf056f
children 47d2f8f84309
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Buffer insertion/deletion and gap motion for GNU Emacs.
2050
3ffbf2314074 (prepare_to_modify_buffer): Set Vdeactivate_mark.
Richard M. Stallman <rms@gnu.org>
parents: 2019
diff changeset
2 Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc.
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 the Free Software Foundation; either version 1, or (at your option)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 4078
diff changeset
21 #include <config.h>
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 #include "lisp.h"
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
23 #include "intervals.h"
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "buffer.h"
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 #include "window.h"
2480
6f4b9c548425 Include blockinput.h.
Richard M. Stallman <rms@gnu.org>
parents: 2439
diff changeset
26 #include "blockinput.h"
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 /* Move gap to position `pos'.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 Note that this can quit! */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 move_gap (pos)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 int pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 if (pos < GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 gap_left (pos, 0);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 else if (pos > GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 gap_right (pos);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 /* Move the gap to POS, which is less than the current GPT.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 If NEWGAP is nonzero, then don't update beg_unchanged and end_unchanged. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 gap_left (pos, newgap)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 register int pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 int newgap;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 register unsigned char *to, *from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 register int i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 int new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 pos--;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 if (!newgap)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 if (unchanged_modified == MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 beg_unchanged = pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 end_unchanged = Z - pos - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 if (Z - GPT < end_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 end_unchanged = Z - GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 if (pos < beg_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 beg_unchanged = pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 i = GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 to = GAP_END_ADDR;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 from = GPT_ADDR;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 new_s1 = GPT - BEG;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 /* Now copy the characters. To move the gap down,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 copy characters up. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 while (1)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 /* I gets number of characters left to copy. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 i = new_s1 - pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 if (i == 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 break;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 /* If a quit is requested, stop copying now.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 Change POS to be where we have actually moved the gap to. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 if (QUITP)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 pos = new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 break;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 /* Move at most 32000 chars before checking again for a quit. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 if (i > 32000)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 i = 32000;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 #ifdef GAP_USE_BCOPY
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 if (i >= 128
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 /* bcopy is safe if the two areas of memory do not overlap
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 or on systems where bcopy is always safe for moving upward. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 && (BCOPY_UPWARD_SAFE
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 || to - from >= 128))
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 /* If overlap is not safe, avoid it by not moving too many
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 characters at once. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 if (!BCOPY_UPWARD_SAFE && i > to - from)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 i = to - from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 new_s1 -= i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 from -= i, to -= i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 bcopy (from, to, i);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 #endif
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 new_s1 -= i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 while (--i >= 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 *--to = *--from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 /* Adjust markers, and buffer data structure, to put the gap at POS.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 POS is where the loop above stopped, which may be what was specified
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 or may be where a quit was detected. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 adjust_markers (pos + 1, GPT, GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 GPT = pos + 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 QUIT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 gap_right (pos)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 register int pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 register unsigned char *to, *from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 register int i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 int new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 pos--;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 if (unchanged_modified == MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 beg_unchanged = pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 end_unchanged = Z - pos - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 if (Z - pos - 1 < end_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 end_unchanged = Z - pos - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 if (GPT - BEG < beg_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 beg_unchanged = GPT - BEG;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 i = GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 from = GAP_END_ADDR;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 to = GPT_ADDR;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 new_s1 = GPT - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 /* Now copy the characters. To move the gap up,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 copy characters down. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 while (1)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 /* I gets number of characters left to copy. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 i = pos - new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 if (i == 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 break;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 /* If a quit is requested, stop copying now.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 Change POS to be where we have actually moved the gap to. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 if (QUITP)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 pos = new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 break;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 /* Move at most 32000 chars before checking again for a quit. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 if (i > 32000)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 i = 32000;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 #ifdef GAP_USE_BCOPY
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 if (i >= 128
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 /* bcopy is safe if the two areas of memory do not overlap
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 or on systems where bcopy is always safe for moving downward. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 && (BCOPY_DOWNWARD_SAFE
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 || from - to >= 128))
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 /* If overlap is not safe, avoid it by not moving too many
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 characters at once. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 if (!BCOPY_DOWNWARD_SAFE && i > from - to)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 i = from - to;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 new_s1 += i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 bcopy (from, to, i);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 from += i, to += i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 #endif
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 new_s1 += i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 while (--i >= 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 *to++ = *from++;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 adjust_markers (GPT + GAP_SIZE, pos + 1 + GAP_SIZE, - GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 GPT = pos + 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 QUIT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 /* Add `amount' to the position of every marker in the current buffer
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 whose current position is between `from' (exclusive) and `to' (inclusive).
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 Also, any markers past the outside of that interval, in the direction
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 of adjustment, are first moved back to the near end of the interval
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 and then adjusted by `amount'. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 adjust_markers (from, to, amount)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 register int from, to, amount;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 Lisp_Object marker;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 register struct Lisp_Marker *m;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 register int mpos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 marker = current_buffer->markers;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
215 while (!NILP (marker))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 m = XMARKER (marker);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 mpos = m->bufpos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 if (amount > 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 if (mpos > to && mpos < to + amount)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 mpos = to + amount;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 if (mpos > from + amount && mpos <= from)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 mpos = from + amount;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 if (mpos > from && mpos <= to)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 mpos += amount;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 m->bufpos = mpos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 marker = m->chain;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 /* Make the gap INCREMENT characters longer. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 make_gap (increment)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 int increment;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 unsigned char *result;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 Lisp_Object tem;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 int real_gap_loc;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 int old_gap_size;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 /* If we have to get more space, get enough to last a while. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 increment += 2000;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248
2439
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 2050
diff changeset
249 BLOCK_INPUT;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 result = BUFFER_REALLOC (BEG_ADDR, (Z - BEG + GAP_SIZE + increment));
2439
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 2050
diff changeset
251 UNBLOCK_INPUT;
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 2050
diff changeset
252
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 if (result == 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 memory_full ();
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 BEG_ADDR = result;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 /* Prevent quitting in move_gap. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 tem = Vinhibit_quit;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 Vinhibit_quit = Qt;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 real_gap_loc = GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 old_gap_size = GAP_SIZE;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 /* Call the newly allocated space a gap at the end of the whole space. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 GPT = Z + GAP_SIZE;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 GAP_SIZE = increment;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 /* Move the new gap down to be consecutive with the end of the old one.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 This adjusts the markers properly too. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 gap_left (real_gap_loc + old_gap_size, 1);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 /* Now combine the two into one large gap. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 GAP_SIZE += old_gap_size;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 GPT = real_gap_loc;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 Vinhibit_quit = tem;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 /* Insert a string of specified length before point.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 DO NOT use this for the contents of a Lisp string!
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 prepare_to_modify_buffer could relocate the string. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 insert (string, length)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 register unsigned char *string;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 register length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 register Lisp_Object temp;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 if (length < 1)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 return;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 /* Make sure point-max won't overflow after this insertion. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 XSET (temp, Lisp_Int, length + Z);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 if (length + Z != XINT (temp))
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 error ("maximum buffer size exceeded");
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 prepare_to_modify_buffer (point, point);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 if (point != GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 move_gap (point);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 if (GAP_SIZE < length)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 make_gap (length - GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 record_insert (point, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 MODIFF++;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 bcopy (string, GPT_ADDR, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
309 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
310 offset_intervals (current_buffer, point, length);
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
311
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 GAP_SIZE -= length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 GPT += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 ZV += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 Z += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 SET_PT (point + length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 signal_after_change (point-length, 0, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
321 /* Insert the part of the text of STRING, a Lisp object assumed to be
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
322 of type string, consisting of the LENGTH characters starting at
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
323 position POS. If the text of STRING has properties, they are absorbed
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
324 into the buffer.
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
325
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
326 It does not work to use `insert' for this, because a GC could happen
251
28d91bb8ac74 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 157
diff changeset
327 before we bcopy the stuff into the buffer, and relocate the string
28d91bb8ac74 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 157
diff changeset
328 without insert noticing. */
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
329
4712
367dc6ff392c (insert_from_string): Pass extra arg to graft_intervals_into_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
330 insert_from_string (string, pos, length, inherit)
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 Lisp_Object string;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 register int pos, length;
4712
367dc6ff392c (insert_from_string): Pass extra arg to graft_intervals_into_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
333 int inherit;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 register Lisp_Object temp;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 struct gcpro gcpro1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 if (length < 1)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 return;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 /* Make sure point-max won't overflow after this insertion. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 XSET (temp, Lisp_Int, length + Z);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 if (length + Z != XINT (temp))
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 error ("maximum buffer size exceeded");
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 GCPRO1 (string);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 prepare_to_modify_buffer (point, point);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 if (point != GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 move_gap (point);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 if (GAP_SIZE < length)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 make_gap (length - GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 record_insert (point, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 MODIFF++;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 UNGCPRO;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 bcopy (XSTRING (string)->data, GPT_ADDR, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
360 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
361 offset_intervals (current_buffer, point, length);
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
362
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 GAP_SIZE -= length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 GPT += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 ZV += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 Z += length;
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
367
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
368 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
5168
b30763a185e9 (insert_from_string): Pass new arg to graft_intervals_into_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 4712
diff changeset
369 graft_intervals_into_buffer (XSTRING (string)->intervals, point, length,
4712
367dc6ff392c (insert_from_string): Pass extra arg to graft_intervals_into_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
370 current_buffer, inherit);
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
371
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
372 SET_PT (point + length);
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 signal_after_change (point-length, 0, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 /* Insert the character C before point */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 void
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 insert_char (c)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 unsigned char c;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 insert (&c, 1);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 /* Insert the null-terminated string S before point */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 void
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 insert_string (s)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 char *s;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 insert (s, strlen (s));
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 /* Like `insert' except that all markers pointing at the place where
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 the insertion happens are adjusted to point after it.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 Don't use this function to insert part of a Lisp string,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 since gc could happen and relocate it. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 insert_before_markers (string, length)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 unsigned char *string;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 register int length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 register int opoint = point;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 insert (string, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 adjust_markers (opoint - 1, opoint, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 /* Insert part of a Lisp string, relocating markers after. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410
4712
367dc6ff392c (insert_from_string): Pass extra arg to graft_intervals_into_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
411 insert_from_string_before_markers (string, pos, length, inherit)
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 Lisp_Object string;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 register int pos, length;
4712
367dc6ff392c (insert_from_string): Pass extra arg to graft_intervals_into_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
414 int inherit;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 register int opoint = point;
4712
367dc6ff392c (insert_from_string): Pass extra arg to graft_intervals_into_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
417 insert_from_string (string, pos, length, inherit);
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 adjust_markers (opoint - 1, opoint, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 /* Delete characters in current buffer
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 from FROM up to (but not including) TO. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 del_range (from, to)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 register int from, to;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 register int numdel;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 /* Make args be valid */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 if (from < BEGV)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 from = BEGV;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 if (to > ZV)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 to = ZV;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 if ((numdel = to - from) <= 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 return;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 /* Make sure the gap is somewhere in or next to what we are deleting. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 if (from > GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 gap_right (from);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 if (to < GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 gap_left (to, 0);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 prepare_to_modify_buffer (from, to);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445
1247
8dce1588f37f (del_range): Call record_delete before updating point.
Richard M. Stallman <rms@gnu.org>
parents: 484
diff changeset
446 record_delete (from, numdel);
8dce1588f37f (del_range): Call record_delete before updating point.
Richard M. Stallman <rms@gnu.org>
parents: 484
diff changeset
447 MODIFF++;
8dce1588f37f (del_range): Call record_delete before updating point.
Richard M. Stallman <rms@gnu.org>
parents: 484
diff changeset
448
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 /* Relocate point as if it were a marker. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 if (from < point)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 if (point < to)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 SET_PT (from);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 SET_PT (point - numdel);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457
1963
05dd60327cc4 (del_range): Update point before offset_intervals.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
458 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
5237
378540cf056f (del_range): Second argument in call to
Richard M. Stallman <rms@gnu.org>
parents: 5168
diff changeset
459 offset_intervals (current_buffer, from, - numdel);
1963
05dd60327cc4 (del_range): Update point before offset_intervals.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
460
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 /* Relocate all markers pointing into the new, larger gap
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 to point at the end of the text before the gap. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 adjust_markers (to + GAP_SIZE, to + GAP_SIZE, - numdel - GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 GAP_SIZE += numdel;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 ZV -= numdel;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 Z -= numdel;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 GPT = from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 if (GPT - BEG < beg_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 beg_unchanged = GPT - BEG;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 if (Z - GPT < end_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 end_unchanged = Z - GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 signal_after_change (from, numdel, 0);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477
2783
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
478 /* Call this if you're about to change the region of BUFFER from START
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
479 to END. This checks the read-only properties of the region, calls
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
480 the necessary modification hooks, and warns the next redisplay that
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
481 it should pay attention to that area. */
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
482 modify_region (buffer, start, end)
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
483 struct buffer *buffer;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 int start, end;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 {
2783
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
486 struct buffer *old_buffer = current_buffer;
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
487
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
488 if (buffer != old_buffer)
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
489 set_buffer_internal (buffer);
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
490
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 prepare_to_modify_buffer (start, end);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 if (start - 1 < beg_unchanged || unchanged_modified == MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 beg_unchanged = start - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 if (Z - end < end_unchanged
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 || unchanged_modified == MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 end_unchanged = Z - end;
5237
378540cf056f (del_range): Second argument in call to
Richard M. Stallman <rms@gnu.org>
parents: 5168
diff changeset
498
378540cf056f (del_range): Second argument in call to
Richard M. Stallman <rms@gnu.org>
parents: 5168
diff changeset
499 if (MODIFF <= current_buffer->save_modified)
378540cf056f (del_range): Second argument in call to
Richard M. Stallman <rms@gnu.org>
parents: 5168
diff changeset
500 record_first_change ();
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 MODIFF++;
2783
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
502
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
503 if (buffer != old_buffer)
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
504 set_buffer_internal (old_buffer);
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 /* Check that it is okay to modify the buffer between START and END.
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
508 Run the before-change-function, if any. If intervals are in use,
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
509 verify that the text to be modified is not read-only, and call
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
510 any modification properties the text may have. */
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 prepare_to_modify_buffer (start, end)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 Lisp_Object start, end;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 {
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
515 if (!NILP (current_buffer->read_only))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 Fbarf_if_buffer_read_only ();
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
518 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
519 verify_interval_modification (current_buffer, start, end);
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520
4078
7d7b899db77d (prepare_to_modify_buffer): Call verify_overlay_modification.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
521 verify_overlay_modification (start, end);
7d7b899db77d (prepare_to_modify_buffer): Call verify_overlay_modification.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
522
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 #ifdef CLASH_DETECTION
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
524 if (!NILP (current_buffer->filename)
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 && current_buffer->save_modified >= MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 lock_file (current_buffer->filename);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 #else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 /* At least warn if this file has changed on disk since it was visited. */
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
529 if (!NILP (current_buffer->filename)
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 && current_buffer->save_modified >= MODIFF
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
531 && NILP (Fverify_visited_file_modtime (Fcurrent_buffer ()))
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
532 && !NILP (Ffile_exists_p (current_buffer->filename)))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 call1 (intern ("ask-user-about-supersession-threat"),
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 current_buffer->filename);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 #endif /* not CLASH_DETECTION */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 signal_before_change (start, end);
2050
3ffbf2314074 (prepare_to_modify_buffer): Set Vdeactivate_mark.
Richard M. Stallman <rms@gnu.org>
parents: 2019
diff changeset
538
3ffbf2314074 (prepare_to_modify_buffer): Set Vdeactivate_mark.
Richard M. Stallman <rms@gnu.org>
parents: 2019
diff changeset
539 Vdeactivate_mark = Qt;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 static Lisp_Object
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 before_change_function_restore (value)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 Lisp_Object value;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 Vbefore_change_function = value;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 static Lisp_Object
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 after_change_function_restore (value)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 Lisp_Object value;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 Vafter_change_function = value;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
556 /* Signal a change to the buffer immediately before it happens.
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 START and END are the bounds of the text to be changed,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 as Lisp objects. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 signal_before_change (start, end)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 Lisp_Object start, end;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 /* If buffer is unmodified, run a special hook for that case. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 if (current_buffer->save_modified >= MODIFF
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1289
diff changeset
565 && !NILP (Vfirst_change_hook)
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1289
diff changeset
566 && !NILP (Vrun_hooks))
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1289
diff changeset
567 call1 (Vrun_hooks, Qfirst_change_hook);
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1289
diff changeset
568
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 /* Now in any case run the before-change-function if any. */
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
570 if (!NILP (Vbefore_change_function))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 int count = specpdl_ptr - specpdl;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 Lisp_Object function;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 function = Vbefore_change_function;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 record_unwind_protect (after_change_function_restore,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 Vafter_change_function);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 record_unwind_protect (before_change_function_restore,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 Vbefore_change_function);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 Vafter_change_function = Qnil;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 Vbefore_change_function = Qnil;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 call2 (function, start, end);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 unbind_to (count, Qnil);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
588 /* Signal a change immediately after it happens.
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 POS is the address of the start of the changed text.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 LENDEL is the number of characters of the text before the change.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 (Not the whole buffer; just the part that was changed.)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 LENINS is the number of characters in the changed text. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 signal_after_change (pos, lendel, lenins)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 int pos, lendel, lenins;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 {
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
597 if (!NILP (Vafter_change_function))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 int count = specpdl_ptr - specpdl;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 Lisp_Object function;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601 function = Vafter_change_function;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 record_unwind_protect (after_change_function_restore,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604 Vafter_change_function);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 record_unwind_protect (before_change_function_restore,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 Vbefore_change_function);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 Vafter_change_function = Qnil;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608 Vbefore_change_function = Qnil;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 call3 (function, make_number (pos), make_number (pos + lenins),
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 make_number (lendel));
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 unbind_to (count, Qnil);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614 }