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