diff options
| author | Karl Heuer | 1994-04-26 02:22:52 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-04-26 02:22:52 +0000 |
| commit | a27a38d8a7b704402065457fd324540ce9d1f4b8 (patch) | |
| tree | 82a4dcb1d44853f3cdf006b0a245fc47d7e208fe /src | |
| parent | 2bcaed71dff6c506ed7549c9eaa77ef589737223 (diff) | |
| download | emacs-a27a38d8a7b704402065457fd324540ce9d1f4b8.tar.gz emacs-a27a38d8a7b704402065457fd324540ce9d1f4b8.zip | |
(adjust_point): New function.
(insert_1, insert_from_string_1, del_range_1): Use it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/insdel.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/insdel.c b/src/insdel.c index 2d84ae1de62..5ddf391b863 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -30,6 +30,7 @@ static void insert_from_string_1 (); | |||
| 30 | static void gap_left (); | 30 | static void gap_left (); |
| 31 | static void gap_right (); | 31 | static void gap_right (); |
| 32 | static void adjust_markers (); | 32 | static void adjust_markers (); |
| 33 | static void adjust_point (); | ||
| 33 | 34 | ||
| 34 | /* Move gap to position `pos'. | 35 | /* Move gap to position `pos'. |
| 35 | Note that this can quit! */ | 36 | Note that this can quit! */ |
| @@ -241,6 +242,19 @@ adjust_markers (from, to, amount) | |||
| 241 | marker = m->chain; | 242 | marker = m->chain; |
| 242 | } | 243 | } |
| 243 | } | 244 | } |
| 245 | |||
| 246 | /* Add the specified amount to point. This is used only when the value | ||
| 247 | of point changes due to an insert or delete; it does not represent | ||
| 248 | a conceptual change in point as a marker. In particular, point is | ||
| 249 | not crossing any interval boundaries, so there's no need to use the | ||
| 250 | usual SET_PT macro. In fact it would be incorrect to do so, because | ||
| 251 | either the old or the new value of point is out of synch with the | ||
| 252 | current set of intervals. */ | ||
| 253 | static void | ||
| 254 | adjust_point (amount) | ||
| 255 | { | ||
| 256 | current_buffer->text.pt += amount; | ||
| 257 | } | ||
| 244 | 258 | ||
| 245 | /* Make the gap INCREMENT characters longer. */ | 259 | /* Make the gap INCREMENT characters longer. */ |
| 246 | 260 | ||
| @@ -331,7 +345,7 @@ insert_1 (string, length) | |||
| 331 | GPT += length; | 345 | GPT += length; |
| 332 | ZV += length; | 346 | ZV += length; |
| 333 | Z += length; | 347 | Z += length; |
| 334 | SET_PT (PT + length); | 348 | adjust_point (length); |
| 335 | } | 349 | } |
| 336 | 350 | ||
| 337 | /* Insert the part of the text of STRING, a Lisp object assumed to be | 351 | /* Insert the part of the text of STRING, a Lisp object assumed to be |
| @@ -395,7 +409,7 @@ insert_from_string_1 (string, pos, length, inherit) | |||
| 395 | graft_intervals_into_buffer (XSTRING (string)->intervals, PT, length, | 409 | graft_intervals_into_buffer (XSTRING (string)->intervals, PT, length, |
| 396 | current_buffer, inherit); | 410 | current_buffer, inherit); |
| 397 | 411 | ||
| 398 | SET_PT (PT + length); | 412 | adjust_point (length); |
| 399 | } | 413 | } |
| 400 | 414 | ||
| 401 | /* Insert the character C before point */ | 415 | /* Insert the character C before point */ |
| @@ -489,12 +503,7 @@ del_range_1 (from, to, prepare) | |||
| 489 | 503 | ||
| 490 | /* Relocate point as if it were a marker. */ | 504 | /* Relocate point as if it were a marker. */ |
| 491 | if (from < PT) | 505 | if (from < PT) |
| 492 | { | 506 | adjust_point (from - (PT < to ? PT : to)); |
| 493 | if (PT < to) | ||
| 494 | SET_PT (from); | ||
| 495 | else | ||
| 496 | SET_PT (PT - numdel); | ||
| 497 | } | ||
| 498 | 507 | ||
| 499 | /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ | 508 | /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ |
| 500 | offset_intervals (current_buffer, from, - numdel); | 509 | offset_intervals (current_buffer, from, - numdel); |