annotate src/insdel.c @ 6836:64e20f3960e8

(next): Fix typo in m68k-next-ns3 alternative.
author Richard M. Stallman <rms@gnu.org>
date Tue, 12 Apr 1994 20:13:58 +0000
parents 4fcd24cee757
children 6e6410985d76
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.
6787
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
2 Copyright (C) 1985, 1986, 1993, 1994 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
6739
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
28 static void insert_1 ();
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
29 static void insert_from_string_1 ();
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
30
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 /* Move gap to position `pos'.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 Note that this can quit! */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 move_gap (pos)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 int pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 if (pos < GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 gap_left (pos, 0);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 else if (pos > GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 gap_right (pos);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 /* Move the gap to POS, which is less than the current GPT.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 If NEWGAP is nonzero, then don't update beg_unchanged and end_unchanged. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 gap_left (pos, newgap)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 register int pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 int newgap;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 register unsigned char *to, *from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 register int i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 int new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 pos--;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 if (!newgap)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 if (unchanged_modified == MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 beg_unchanged = pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 end_unchanged = Z - pos - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 if (Z - GPT < end_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 end_unchanged = Z - GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 if (pos < beg_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 beg_unchanged = pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 i = GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 to = GAP_END_ADDR;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 from = GPT_ADDR;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 new_s1 = GPT - BEG;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 /* Now copy the characters. To move the gap down,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 copy characters up. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 while (1)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 /* I gets number of characters left to copy. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 i = new_s1 - pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 if (i == 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 break;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 /* If a quit is requested, stop copying now.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 Change POS to be where we have actually moved the gap to. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 if (QUITP)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 pos = new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 break;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 /* Move at most 32000 chars before checking again for a quit. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 if (i > 32000)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 i = 32000;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 #ifdef GAP_USE_BCOPY
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 if (i >= 128
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 /* bcopy is safe if the two areas of memory do not overlap
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 or on systems where bcopy is always safe for moving upward. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 && (BCOPY_UPWARD_SAFE
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 || to - from >= 128))
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 /* If overlap is not safe, avoid it by not moving too many
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 characters at once. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 if (!BCOPY_UPWARD_SAFE && i > to - from)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 i = to - from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 new_s1 -= i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 from -= i, to -= i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 bcopy (from, to, i);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 #endif
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 new_s1 -= i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 while (--i >= 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 *--to = *--from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 /* Adjust markers, and buffer data structure, to put the gap at POS.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 POS is where the loop above stopped, which may be what was specified
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 or may be where a quit was detected. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 adjust_markers (pos + 1, GPT, GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 GPT = pos + 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 QUIT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 gap_right (pos)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 register int pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 register unsigned char *to, *from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 register int i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 int new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 pos--;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 if (unchanged_modified == MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 beg_unchanged = pos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 end_unchanged = Z - pos - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 if (Z - pos - 1 < end_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 end_unchanged = Z - pos - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 if (GPT - BEG < beg_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 beg_unchanged = GPT - BEG;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 i = GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 from = GAP_END_ADDR;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 to = GPT_ADDR;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 new_s1 = GPT - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 /* Now copy the characters. To move the gap up,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 copy characters down. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 while (1)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 /* I gets number of characters left to copy. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 i = pos - new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 if (i == 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 break;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 /* If a quit is requested, stop copying now.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 Change POS to be where we have actually moved the gap to. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 if (QUITP)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 pos = new_s1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 break;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 /* Move at most 32000 chars before checking again for a quit. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 if (i > 32000)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 i = 32000;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 #ifdef GAP_USE_BCOPY
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 if (i >= 128
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 /* bcopy is safe if the two areas of memory do not overlap
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 or on systems where bcopy is always safe for moving downward. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 && (BCOPY_DOWNWARD_SAFE
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 || from - to >= 128))
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 /* If overlap is not safe, avoid it by not moving too many
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 characters at once. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 if (!BCOPY_DOWNWARD_SAFE && i > from - to)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 i = from - to;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 new_s1 += i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 bcopy (from, to, i);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 from += i, to += i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 #endif
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 new_s1 += i;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 while (--i >= 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 *to++ = *from++;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 adjust_markers (GPT + GAP_SIZE, pos + 1 + GAP_SIZE, - GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 GPT = pos + 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 QUIT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 /* Add `amount' to the position of every marker in the current buffer
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 whose current position is between `from' (exclusive) and `to' (inclusive).
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 Also, any markers past the outside of that interval, in the direction
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 of adjustment, are first moved back to the near end of the interval
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 and then adjusted by `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 adjust_markers (from, to, amount)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 register int from, to, amount;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 Lisp_Object marker;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 register struct Lisp_Marker *m;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 register int mpos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 marker = current_buffer->markers;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
218 while (!NILP (marker))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 m = XMARKER (marker);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 mpos = m->bufpos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 if (amount > 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 if (mpos > to && mpos < to + amount)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 mpos = to + amount;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 else
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 + amount && mpos <= from)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 mpos = from + amount;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 if (mpos > from && mpos <= to)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 mpos += amount;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 m->bufpos = mpos;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 marker = m->chain;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 /* Make the gap INCREMENT characters longer. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 make_gap (increment)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 int increment;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 unsigned char *result;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 Lisp_Object tem;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 int real_gap_loc;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 int old_gap_size;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 /* If we have to get more space, get enough to last a while. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 increment += 2000;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251
2439
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 2050
diff changeset
252 BLOCK_INPUT;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 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
254 UNBLOCK_INPUT;
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 2050
diff changeset
255
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 if (result == 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 memory_full ();
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 BEG_ADDR = result;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 /* Prevent quitting in move_gap. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 tem = Vinhibit_quit;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 Vinhibit_quit = Qt;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 real_gap_loc = GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 old_gap_size = GAP_SIZE;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 /* 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
268 GPT = Z + GAP_SIZE;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 GAP_SIZE = increment;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 /* 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
272 This adjusts the markers properly too. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 gap_left (real_gap_loc + old_gap_size, 1);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 /* Now combine the two into one large gap. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 GAP_SIZE += old_gap_size;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 GPT = real_gap_loc;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 Vinhibit_quit = tem;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 /* Insert a string of specified length before point.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 DO NOT use this for the contents of a Lisp string!
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 prepare_to_modify_buffer could relocate the string. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 insert (string, length)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 register unsigned char *string;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 register length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 {
6739
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
290 if (length > 0)
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
291 {
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
292 insert_1 (string, length);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
293 signal_after_change (point-length, 0, length);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
294 }
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
295 }
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296
6739
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
297 static void
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
298 insert_1 (string, length)
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
299 register unsigned char *string;
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
300 register length;
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
301 {
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
302 register Lisp_Object temp;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 /* Make sure point-max won't overflow after this insertion. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 XSET (temp, Lisp_Int, length + Z);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 if (length + Z != XINT (temp))
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 error ("maximum buffer size exceeded");
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 prepare_to_modify_buffer (point, point);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 if (point != GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 move_gap (point);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 if (GAP_SIZE < length)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 make_gap (length - GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 record_insert (point, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 MODIFF++;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 bcopy (string, GPT_ADDR, length);
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 /* 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
322 offset_intervals (current_buffer, point, length);
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
323
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 GAP_SIZE -= length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 GPT += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 ZV += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 Z += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 SET_PT (point + length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
331 /* 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
332 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
333 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
334 into the buffer.
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
335
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
336 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
337 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
338 without insert noticing. */
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
339
4712
367dc6ff392c (insert_from_string): Pass extra arg to graft_intervals_into_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
340 insert_from_string (string, pos, length, inherit)
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 Lisp_Object string;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 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
343 int inherit;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 {
6739
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
345 if (length > 0)
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
346 {
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
347 insert_from_string_1 (string, pos, length, inherit);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
348 signal_after_change (point-length, 0, length);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
349 }
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
350 }
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
351
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
352 static void
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
353 insert_from_string_1 (string, pos, length, inherit)
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
354 Lisp_Object string;
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
355 register int pos, length;
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
356 int inherit;
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
357 {
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 register Lisp_Object temp;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 struct gcpro gcpro1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 /* Make sure point-max won't overflow after this insertion. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 XSET (temp, Lisp_Int, length + Z);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 if (length + Z != XINT (temp))
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 error ("maximum buffer size exceeded");
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 GCPRO1 (string);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 prepare_to_modify_buffer (point, point);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 if (point != GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 move_gap (point);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 if (GAP_SIZE < length)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 make_gap (length - GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 record_insert (point, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 MODIFF++;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 UNGCPRO;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 bcopy (XSTRING (string)->data, GPT_ADDR, length);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
380 /* 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
381 offset_intervals (current_buffer, point, length);
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
382
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 GAP_SIZE -= length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 GPT += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 ZV += length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 Z += length;
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
387
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
388 /* 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
389 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
390 current_buffer, inherit);
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
391
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
392 SET_PT (point + length);
157
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 /* Insert the character C before point */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 void
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 insert_char (c)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 unsigned char c;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 insert (&c, 1);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 /* Insert the null-terminated string S before point */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 void
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 insert_string (s)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 char *s;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 insert (s, strlen (s));
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 /* Like `insert' except that all markers pointing at the place where
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 the insertion happens are adjusted to point after it.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 Don't use this function to insert part of a Lisp string,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 since gc could happen and relocate it. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 insert_before_markers (string, length)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 unsigned char *string;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 register int length;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 {
6739
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
422 if (length > 0)
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
423 {
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
424 register int opoint = point;
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
425 insert_1 (string, length);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
426 adjust_markers (opoint - 1, opoint, length);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
427 signal_after_change (point-length, 0, length);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
428 }
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 /* Insert part of a Lisp string, relocating markers after. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432
4712
367dc6ff392c (insert_from_string): Pass extra arg to graft_intervals_into_buffer.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
433 insert_from_string_before_markers (string, pos, length, inherit)
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 Lisp_Object string;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 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
436 int inherit;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 {
6739
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
438 if (length > 0)
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
439 {
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
440 register int opoint = point;
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
441 insert_from_string_1 (string, pos, length, inherit);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
442 adjust_markers (opoint - 1, opoint, length);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
443 signal_after_change (point-length, 0, length);
6b0dd4aeca67 (insert_1): New function, extracted from insert.
Karl Heuer <kwzh@gnu.org>
parents: 6126
diff changeset
444 }
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 /* Delete characters in current buffer
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 from FROM up to (but not including) TO. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 del_range (from, to)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 register int from, to;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 {
6126
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
453 return del_range_1 (from, to, 1);
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
454 }
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
455
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
456 /* Like del_range; PREPARE says whether to call prepare_to_modify_buffer. */
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
457
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
458 del_range_1 (from, to, prepare)
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
459 register int from, to, prepare;
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
460 {
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 register int numdel;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 /* Make args be valid */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 if (from < BEGV)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 from = BEGV;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 if (to > ZV)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 to = ZV;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 if ((numdel = to - from) <= 0)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 return;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 /* 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
473 if (from > GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 gap_right (from);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 if (to < GPT)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 gap_left (to, 0);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477
6126
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
478 if (prepare)
47d2f8f84309 (del_range_1): New function.
Richard M. Stallman <rms@gnu.org>
parents: 5237
diff changeset
479 prepare_to_modify_buffer (from, to);
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480
1247
8dce1588f37f (del_range): Call record_delete before updating point.
Richard M. Stallman <rms@gnu.org>
parents: 484
diff changeset
481 record_delete (from, numdel);
8dce1588f37f (del_range): Call record_delete before updating point.
Richard M. Stallman <rms@gnu.org>
parents: 484
diff changeset
482 MODIFF++;
8dce1588f37f (del_range): Call record_delete before updating point.
Richard M. Stallman <rms@gnu.org>
parents: 484
diff changeset
483
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 /* Relocate point as if it were a marker. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 if (from < point)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 if (point < to)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 SET_PT (from);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 SET_PT (point - numdel);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492
1963
05dd60327cc4 (del_range): Update point before offset_intervals.
Richard M. Stallman <rms@gnu.org>
parents: 1821
diff changeset
493 /* 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
494 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
495
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 /* Relocate all markers pointing into the new, larger gap
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 to point at the end of the text before the gap. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 adjust_markers (to + GAP_SIZE, to + GAP_SIZE, - numdel - GAP_SIZE);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 GAP_SIZE += numdel;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 ZV -= numdel;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 Z -= numdel;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 GPT = from;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 if (GPT - BEG < beg_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 beg_unchanged = GPT - BEG;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 if (Z - GPT < end_unchanged)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 end_unchanged = Z - GPT;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 signal_after_change (from, numdel, 0);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512
2783
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
513 /* 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
514 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
515 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
516 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
517 modify_region (buffer, start, end)
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
518 struct buffer *buffer;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 int start, end;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 {
2783
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
521 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
522
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
523 if (buffer != old_buffer)
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
524 set_buffer_internal (buffer);
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
525
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 prepare_to_modify_buffer (start, end);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 if (start - 1 < beg_unchanged || unchanged_modified == MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 beg_unchanged = start - 1;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 if (Z - end < end_unchanged
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 || unchanged_modified == MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 end_unchanged = Z - end;
5237
378540cf056f (del_range): Second argument in call to
Richard M. Stallman <rms@gnu.org>
parents: 5168
diff changeset
533
378540cf056f (del_range): Second argument in call to
Richard M. Stallman <rms@gnu.org>
parents: 5168
diff changeset
534 if (MODIFF <= current_buffer->save_modified)
378540cf056f (del_range): Second argument in call to
Richard M. Stallman <rms@gnu.org>
parents: 5168
diff changeset
535 record_first_change ();
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 MODIFF++;
2783
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
537
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
538 if (buffer != old_buffer)
789c11177579 The text property routines can now modify buffers other
Jim Blandy <jimb@redhat.com>
parents: 2480
diff changeset
539 set_buffer_internal (old_buffer);
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 /* 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
543 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
544 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
545 any modification properties the text may have. */
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 prepare_to_modify_buffer (start, end)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 Lisp_Object start, end;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 {
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
550 if (!NILP (current_buffer->read_only))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 Fbarf_if_buffer_read_only ();
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552
1289
74b26ab86df4 * insdel.c: #include "intervals.h"
Joseph Arceneaux <jla@gnu.org>
parents: 1247
diff changeset
553 /* 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
554 verify_interval_modification (current_buffer, start, end);
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555
4078
7d7b899db77d (prepare_to_modify_buffer): Call verify_overlay_modification.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
556 verify_overlay_modification (start, end);
7d7b899db77d (prepare_to_modify_buffer): Call verify_overlay_modification.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
557
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 #ifdef CLASH_DETECTION
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
559 if (!NILP (current_buffer->filename)
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 && current_buffer->save_modified >= MODIFF)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 lock_file (current_buffer->filename);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 #else
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 /* 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
564 if (!NILP (current_buffer->filename)
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 && current_buffer->save_modified >= MODIFF
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
566 && NILP (Fverify_visited_file_modtime (Fcurrent_buffer ()))
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
567 && !NILP (Ffile_exists_p (current_buffer->filename)))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 call1 (intern ("ask-user-about-supersession-threat"),
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 current_buffer->filename);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 #endif /* not CLASH_DETECTION */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 signal_before_change (start, end);
2050
3ffbf2314074 (prepare_to_modify_buffer): Set Vdeactivate_mark.
Richard M. Stallman <rms@gnu.org>
parents: 2019
diff changeset
573
3ffbf2314074 (prepare_to_modify_buffer): Set Vdeactivate_mark.
Richard M. Stallman <rms@gnu.org>
parents: 2019
diff changeset
574 Vdeactivate_mark = Qt;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 static Lisp_Object
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 before_change_function_restore (value)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 Lisp_Object value;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 Vbefore_change_function = value;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 static Lisp_Object
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 after_change_function_restore (value)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 Lisp_Object value;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 Vafter_change_function = value;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590
6787
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
591 static Lisp_Object
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
592 before_change_functions_restore (value)
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
593 Lisp_Object value;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
594 {
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
595 Vbefore_change_functions = value;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
596 }
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
597
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
598 static Lisp_Object
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
599 after_change_functions_restore (value)
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
600 Lisp_Object value;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
601 {
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
602 Vafter_change_functions = value;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
603 }
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
604
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
605 /* Signal a change to the buffer immediately before it happens.
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 START and END are the bounds of the text to be changed,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 as Lisp objects. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 signal_before_change (start, end)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 Lisp_Object start, end;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 /* If buffer is unmodified, run a special hook for that case. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613 if (current_buffer->save_modified >= MODIFF
1821
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1289
diff changeset
614 && !NILP (Vfirst_change_hook)
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1289
diff changeset
615 && !NILP (Vrun_hooks))
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1289
diff changeset
616 call1 (Vrun_hooks, Qfirst_change_hook);
04fb1d3d6992 JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents: 1289
diff changeset
617
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
618 /* 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
619 if (!NILP (Vbefore_change_function))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 int count = specpdl_ptr - specpdl;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 Lisp_Object function;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
624 function = Vbefore_change_function;
6787
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
625
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
626 record_unwind_protect (after_change_function_restore,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
627 Vafter_change_function);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
628 record_unwind_protect (before_change_function_restore,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
629 Vbefore_change_function);
6787
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
630 record_unwind_protect (after_change_functions_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
631 Vafter_change_functions);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
632 record_unwind_protect (before_change_functions_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
633 Vbefore_change_functions);
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
634 Vafter_change_function = Qnil;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
635 Vbefore_change_function = Qnil;
6787
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
636 Vafter_change_functions = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
637 Vbefore_change_functions = Qnil;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639 call2 (function, start, end);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
640 unbind_to (count, Qnil);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
641 }
6787
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
642
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
643 /* Now in any case run the before-change-function if any. */
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
644 if (!NILP (Vbefore_change_functions))
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
645 {
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
646 int count = specpdl_ptr - specpdl;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
647 Lisp_Object functions;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
648
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
649 functions = Vbefore_change_functions;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
650
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
651 record_unwind_protect (after_change_function_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
652 Vafter_change_function);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
653 record_unwind_protect (before_change_function_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
654 Vbefore_change_function);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
655 record_unwind_protect (after_change_functions_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
656 Vafter_change_functions);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
657 record_unwind_protect (before_change_functions_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
658 Vbefore_change_functions);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
659 Vafter_change_function = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
660 Vbefore_change_function = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
661 Vafter_change_functions = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
662 Vbefore_change_functions = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
663
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
664 while (CONSP (functions))
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
665 {
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
666 call2 (XCONS (functions)->car, start, end);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
667 functions = XCONS (functions)->cdr;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
668 }
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
669 unbind_to (count, Qnil);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
670 }
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 }
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2783
diff changeset
673 /* Signal a change immediately after it happens.
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
674 POS is the address of the start of the changed text.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675 LENDEL is the number of characters of the text before the change.
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
676 (Not the whole buffer; just the part that was changed.)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677 LENINS is the number of characters in the changed text. */
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
679 signal_after_change (pos, lendel, lenins)
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
680 int pos, lendel, lenins;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
681 {
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 251
diff changeset
682 if (!NILP (Vafter_change_function))
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 {
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 int count = specpdl_ptr - specpdl;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 Lisp_Object function;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686 function = Vafter_change_function;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 record_unwind_protect (after_change_function_restore,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 Vafter_change_function);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690 record_unwind_protect (before_change_function_restore,
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691 Vbefore_change_function);
6787
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
692 record_unwind_protect (after_change_functions_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
693 Vafter_change_functions);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
694 record_unwind_protect (before_change_functions_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
695 Vbefore_change_functions);
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
696 Vafter_change_function = Qnil;
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
697 Vbefore_change_function = Qnil;
6787
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
698 Vafter_change_functions = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
699 Vbefore_change_functions = Qnil;
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
700
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
701 call3 (function, make_number (pos), make_number (pos + lenins),
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
702 make_number (lendel));
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
703 unbind_to (count, Qnil);
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
704 }
6787
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
705 if (!NILP (Vafter_change_functions))
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
706 {
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
707 int count = specpdl_ptr - specpdl;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
708 Lisp_Object functions;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
709 functions = Vafter_change_functions;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
710
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
711 record_unwind_protect (after_change_function_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
712 Vafter_change_function);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
713 record_unwind_protect (before_change_function_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
714 Vbefore_change_function);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
715 record_unwind_protect (after_change_functions_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
716 Vafter_change_functions);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
717 record_unwind_protect (before_change_functions_restore,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
718 Vbefore_change_functions);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
719 Vafter_change_function = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
720 Vbefore_change_function = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
721 Vafter_change_functions = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
722 Vbefore_change_functions = Qnil;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
723
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
724 while (CONSP (functions))
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
725 {
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
726 call3 (XCONS (functions)->car,
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
727 make_number (pos), make_number (pos + lenins),
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
728 make_number (lendel));
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
729 functions = XCONS (functions)->cdr;
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
730 }
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
731 unbind_to (count, Qnil);
4fcd24cee757 (before_change_functions_restore):
Richard M. Stallman <rms@gnu.org>
parents: 6739
diff changeset
732 }
157
01ad7ec29c98 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733 }