Mercurial > emacs
comparison src/insdel.c @ 21136:be04baf3d970
(adjust_markers_for_insert): Don't leave a marker within
the combined_after_bytes. Use DEC than INC when leaving
a marker before the insertion.
(count_combining_before): Return number of bytes from start
of insertion that will combine.
(insert_1_both): Compensate for change in count_combining_before.
Delete intervals for the combined_after_bytes.
Compensate for that when updating other intervals.
(insert_from_buffer_1, replace_range): Likewise.
(adjust_after_replace): Likewise.
(insert_from_string_1): Likewise. Also handle intervals
for inserting just part of string.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 11 Mar 1998 00:47:48 +0000 |
parents | 42badfae3618 |
children | f4df45f5a0e2 |
comparison
equal
deleted
inserted
replaced
21135:42badfae3618 | 21136:be04baf3d970 |
---|---|
392 | 392 |
393 /* Adjust markers for an insertion that stretches from FROM / FROM_BYTE | 393 /* Adjust markers for an insertion that stretches from FROM / FROM_BYTE |
394 to TO / TO_BYTE. We have to relocate the charpos of every marker | 394 to TO / TO_BYTE. We have to relocate the charpos of every marker |
395 that points after the insertion (but not their bytepos). | 395 that points after the insertion (but not their bytepos). |
396 | 396 |
397 COMBINED_BEFORE_BYTES is the number of bytes before the insertion | 397 COMBINED_BEFORE_BYTES is the number of bytes at the start of the insertion |
398 that combines into one character with the first inserted bytes. | 398 that combine into one character with the text before the insertion. |
399 COMBINED_AFTER_BYTES is the number of bytes after the insertion | 399 COMBINED_AFTER_BYTES is the number of bytes after the insertion |
400 that combines into one character with the last inserted bytes. | 400 that combine into one character with the last inserted bytes. |
401 | 401 |
402 When a marker points at the insertion point, | 402 When a marker points at the insertion point, |
403 we advance it if either its insertion-type is t | 403 we advance it if either its insertion-type is t |
404 or BEFORE_MARKERS is true. */ | 404 or BEFORE_MARKERS is true. */ |
405 | 405 |
437 { | 437 { |
438 /* This marker doesn't "need relocation", | 438 /* This marker doesn't "need relocation", |
439 but don't leave it pointing in the middle of a character. | 439 but don't leave it pointing in the middle of a character. |
440 Point the marker after the combined character, | 440 Point the marker after the combined character, |
441 so that undoing the insertion puts it back where it was. */ | 441 so that undoing the insertion puts it back where it was. */ |
442 m->bytepos -= combined_before_bytes; | 442 |
443 m->charpos -= 1; | 443 /* Here we depend on the fact that the gap is after |
444 all of the combining bytes that we are going to skip over. */ | |
445 DEC_BOTH (m->charpos, m->bytepos); | |
444 INC_BOTH (m->charpos, m->bytepos); | 446 INC_BOTH (m->charpos, m->bytepos); |
445 } | 447 } |
448 } | |
449 /* If a marker was pointing into the combining bytes | |
450 after the insertion, don't leave it there | |
451 in the middle of a character. */ | |
452 else if (combined_after_bytes && m->bytepos >= from_byte | |
453 && m->bytepos < from_byte + combined_after_bytes) | |
454 { | |
455 /* Put it after the combining bytes. */ | |
456 m->bytepos = to_byte + combined_after_bytes; | |
457 m->charpos = to + 1; | |
458 /* Now move it back before the combined character, | |
459 so that undoing the insertion will put it where it was. */ | |
460 DEC_BOTH (m->charpos, m->bytepos); | |
446 } | 461 } |
447 else if (m->bytepos > from_byte) | 462 else if (m->bytepos > from_byte) |
448 { | 463 { |
449 m->bytepos += nbytes; | 464 m->bytepos += nbytes; |
450 m->charpos += nchars; | 465 m->charpos += nchars; |
760 inherit, prepare, before_markers); | 775 inherit, prepare, before_markers); |
761 } | 776 } |
762 | 777 |
763 /* See if the bytes before POS/POS_BYTE combine with bytes | 778 /* See if the bytes before POS/POS_BYTE combine with bytes |
764 at the start of STRING to form a single character. | 779 at the start of STRING to form a single character. |
765 If so, return the number of bytes before POS/POS_BYTE | 780 If so, return the number of bytes at the start of STRING |
766 which combine in this way. Otherwise, return 0. */ | 781 which combine in this way. Otherwise, return 0. */ |
767 | 782 |
768 int | 783 int |
769 count_combining_before (string, length, pos, pos_byte) | 784 count_combining_before (string, length, pos, pos_byte) |
770 unsigned char *string; | 785 unsigned char *string; |
771 int length; | 786 int length; |
772 int pos, pos_byte; | 787 int pos, pos_byte; |
773 { | 788 { |
774 int opos = pos, opos_byte = pos_byte; | 789 int opos = pos, opos_byte = pos_byte; |
775 int c; | 790 int c; |
791 unsigned char *p = string; | |
776 | 792 |
777 if (NILP (current_buffer->enable_multibyte_characters)) | 793 if (NILP (current_buffer->enable_multibyte_characters)) |
778 return 0; | 794 return 0; |
779 if (length == 0 || CHAR_HEAD_P (*string)) | 795 if (length == 0 || CHAR_HEAD_P (*string)) |
780 return 0; | 796 return 0; |
785 return 0; | 801 return 0; |
786 DEC_BOTH (pos, pos_byte); | 802 DEC_BOTH (pos, pos_byte); |
787 c = FETCH_BYTE (pos_byte); | 803 c = FETCH_BYTE (pos_byte); |
788 if (! BASE_LEADING_CODE_P (c)) | 804 if (! BASE_LEADING_CODE_P (c)) |
789 return 0; | 805 return 0; |
790 return opos_byte - pos_byte; | 806 |
807 /* We have a combination situation. | |
808 Count the bytes at STRING that will combine. */ | |
809 while (!CHAR_HEAD_P (*p) && p < string + length) | |
810 p++; | |
811 | |
812 return p - string; | |
791 } | 813 } |
792 | 814 |
793 /* See if the bytes after POS/POS_BYTE combine with bytes | 815 /* See if the bytes after POS/POS_BYTE combine with bytes |
794 at the end of STRING to form a single character. | 816 at the end of STRING to form a single character. |
795 If so, return the number of bytes after POS/POS_BYTE | 817 If so, return the number of bytes after POS/POS_BYTE |
857 | 879 |
858 combined_before_bytes = count_combining_before (string, nbytes, PT, PT_BYTE); | 880 combined_before_bytes = count_combining_before (string, nbytes, PT, PT_BYTE); |
859 combined_after_bytes = count_combining_after (string, nbytes, PT, PT_BYTE); | 881 combined_after_bytes = count_combining_after (string, nbytes, PT, PT_BYTE); |
860 | 882 |
861 /* This is the net amount that Z will increase from this insertion. */ | 883 /* This is the net amount that Z will increase from this insertion. */ |
862 /* The combined bytes before all count as one character, because | 884 |
863 they start with a leading code, but the combined bytes after | 885 adjusted_nchars = nchars - combined_before_bytes - combined_after_bytes; |
864 count as separate characters, because they are all trailing codes. */ | |
865 | |
866 adjusted_nchars = nchars - !!combined_before_bytes - combined_after_bytes; | |
867 | 886 |
868 if (prepare) | 887 if (prepare) |
869 prepare_to_modify_buffer (PT - !!combined_before_bytes, | 888 prepare_to_modify_buffer (PT - !!combined_before_bytes, |
870 PT + combined_after_bytes, | 889 PT + combined_after_bytes, |
871 NULL); | 890 NULL); |
893 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES. */ | 912 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES. */ |
894 offset_intervals (current_buffer, PT, adjusted_nchars); | 913 offset_intervals (current_buffer, PT, adjusted_nchars); |
895 #endif | 914 #endif |
896 | 915 |
897 GAP_SIZE -= nbytes; | 916 GAP_SIZE -= nbytes; |
898 GPT += nchars - !! combined_before_bytes - !!combined_after_bytes; | 917 /* When we have combining at the end of the insertion, |
918 this is the character position before the combined character. */ | |
919 GPT += nchars - combined_before_bytes - !!combined_after_bytes; | |
899 ZV += adjusted_nchars; | 920 ZV += adjusted_nchars; |
900 Z += adjusted_nchars; | 921 Z += adjusted_nchars; |
901 GPT_BYTE += nbytes; | 922 GPT_BYTE += nbytes; |
902 ZV_BYTE += nbytes; | 923 ZV_BYTE += nbytes; |
903 Z_BYTE += nbytes; | 924 Z_BYTE += nbytes; |
905 adjust_overlays_for_insert (PT, adjusted_nchars); | 926 adjust_overlays_for_insert (PT, adjusted_nchars); |
906 adjust_markers_for_insert (PT, PT_BYTE, | 927 adjust_markers_for_insert (PT, PT_BYTE, |
907 PT + adjusted_nchars, PT_BYTE + nbytes, | 928 PT + adjusted_nchars, PT_BYTE + nbytes, |
908 combined_before_bytes, combined_after_bytes, | 929 combined_before_bytes, combined_after_bytes, |
909 before_markers); | 930 before_markers); |
931 | |
932 /* "Delete" the combined-after bytes, as far as intervals are concerned. | |
933 Note that as far as the intervals are concerned, | |
934 no insertion has yet taken place, so these bytes are right after PT. */ | |
935 if (combined_after_bytes) | |
936 offset_intervals (current_buffer, PT, - combined_after_bytes); | |
937 | |
938 #ifdef USE_TEXT_PROPERTIES | |
939 if (!inherit && BUF_INTERVALS (current_buffer) != 0) | |
940 Fset_text_properties (make_number (PT), | |
941 make_number (PT + adjusted_nchars + combined_after_bytes), | |
942 Qnil, Qnil); | |
943 #endif | |
944 | |
910 adjust_point (adjusted_nchars + combined_after_bytes, | 945 adjust_point (adjusted_nchars + combined_after_bytes, |
911 nbytes + combined_after_bytes); | 946 nbytes + combined_after_bytes); |
912 | 947 |
913 if (combined_after_bytes) | 948 if (combined_after_bytes) |
914 move_gap_both (GPT + 1, GPT_BYTE + combined_after_bytes); | 949 move_gap_both (GPT + 1, GPT_BYTE + combined_after_bytes); |
915 | 950 |
916 if (GPT_BYTE < GPT) | 951 if (GPT_BYTE < GPT) |
917 abort (); | 952 abort (); |
918 | |
919 #ifdef USE_TEXT_PROPERTIES | |
920 if (!inherit && BUF_INTERVALS (current_buffer) != 0) | |
921 Fset_text_properties (make_number (PT - adjusted_nchars), make_number (PT), | |
922 Qnil, Qnil); | |
923 #endif | |
924 } | 953 } |
925 | 954 |
926 /* Insert the part of the text of STRING, a Lisp object assumed to be | 955 /* Insert the part of the text of STRING, a Lisp object assumed to be |
927 of type string, consisting of the LENGTH characters (LENGTH_BYTE bytes) | 956 of type string, consisting of the LENGTH characters (LENGTH_BYTE bytes) |
928 starting at position POS / POS_BYTE. If the text of STRING has properties, | 957 starting at position POS / POS_BYTE. If the text of STRING has properties, |
978 register Lisp_Object temp; | 1007 register Lisp_Object temp; |
979 struct gcpro gcpro1; | 1008 struct gcpro gcpro1; |
980 int outgoing_nbytes = nbytes; | 1009 int outgoing_nbytes = nbytes; |
981 int combined_before_bytes, combined_after_bytes; | 1010 int combined_before_bytes, combined_after_bytes; |
982 int adjusted_nchars; | 1011 int adjusted_nchars; |
1012 INTERVAL intervals; | |
983 | 1013 |
984 /* Make OUTGOING_NBYTES describe the text | 1014 /* Make OUTGOING_NBYTES describe the text |
985 as it will be inserted in this buffer. */ | 1015 as it will be inserted in this buffer. */ |
986 | 1016 |
987 if (NILP (current_buffer->enable_multibyte_characters)) | 1017 if (NILP (current_buffer->enable_multibyte_characters)) |
1027 combined_after_bytes | 1057 combined_after_bytes |
1028 = count_combining_after (XSTRING (string)->data + pos_byte, nbytes, | 1058 = count_combining_after (XSTRING (string)->data + pos_byte, nbytes, |
1029 PT, PT_BYTE); | 1059 PT, PT_BYTE); |
1030 | 1060 |
1031 /* This is the net amount that Z will increase from this insertion. */ | 1061 /* This is the net amount that Z will increase from this insertion. */ |
1032 adjusted_nchars = nchars - !!combined_before_bytes - combined_after_bytes; | 1062 adjusted_nchars = nchars - combined_before_bytes - combined_after_bytes; |
1033 | 1063 |
1034 /* Record deletion of the surrounding text that combines with | 1064 /* Record deletion of the surrounding text that combines with |
1035 the insertion. This, together with recording the insertion, | 1065 the insertion. This, together with recording the insertion, |
1036 will add up to the right stuff in the undo list. | 1066 will add up to the right stuff in the undo list. |
1037 | 1067 |
1049 | 1079 |
1050 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ | 1080 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ |
1051 offset_intervals (current_buffer, PT, adjusted_nchars); | 1081 offset_intervals (current_buffer, PT, adjusted_nchars); |
1052 | 1082 |
1053 GAP_SIZE -= outgoing_nbytes; | 1083 GAP_SIZE -= outgoing_nbytes; |
1054 GPT += nchars - !!combined_before_bytes - !!combined_after_bytes; | 1084 GPT += nchars - combined_before_bytes - !!combined_after_bytes; |
1055 ZV += adjusted_nchars; | 1085 ZV += adjusted_nchars; |
1056 Z += adjusted_nchars; | 1086 Z += adjusted_nchars; |
1057 GPT_BYTE += outgoing_nbytes; | 1087 GPT_BYTE += outgoing_nbytes; |
1058 ZV_BYTE += outgoing_nbytes; | 1088 ZV_BYTE += outgoing_nbytes; |
1059 Z_BYTE += outgoing_nbytes; | 1089 Z_BYTE += outgoing_nbytes; |
1068 move_gap_both (GPT + 1, GPT_BYTE + combined_after_bytes); | 1098 move_gap_both (GPT + 1, GPT_BYTE + combined_after_bytes); |
1069 | 1099 |
1070 if (GPT_BYTE < GPT) | 1100 if (GPT_BYTE < GPT) |
1071 abort (); | 1101 abort (); |
1072 | 1102 |
1073 graft_intervals_into_buffer (XSTRING (string)->intervals, PT, nchars, | 1103 /* "Delete" the combined-after bytes, as far as intervals are concerned. |
1104 Note that as far as the intervals are concerned, | |
1105 no insertion has yet taken place, so these bytes are right after PT. */ | |
1106 if (combined_after_bytes) | |
1107 offset_intervals (current_buffer, PT, - combined_after_bytes); | |
1108 | |
1109 /* Get the intervals for the part of the string we are inserting-- | |
1110 not including the combined-before bytes. */ | |
1111 intervals = XSTRING (string)->intervals; | |
1112 if (combined_before_bytes != 0 | |
1113 || nbytes < XSTRING (string)->size_byte) | |
1114 intervals = copy_intervals (intervals, pos + combined_before_bytes, | |
1115 nchars - combined_before_bytes); | |
1116 | |
1117 /* Insert those intervals. */ | |
1118 graft_intervals_into_buffer (intervals, PT, nchars - combined_before_bytes, | |
1074 current_buffer, inherit); | 1119 current_buffer, inherit); |
1120 | |
1075 adjust_point (adjusted_nchars + combined_after_bytes, | 1121 adjust_point (adjusted_nchars + combined_after_bytes, |
1076 outgoing_nbytes + combined_after_bytes); | 1122 outgoing_nbytes + combined_after_bytes); |
1077 } | 1123 } |
1078 | 1124 |
1079 /* Insert text from BUF, NCHARS characters starting at CHARPOS, into the | 1125 /* Insert text from BUF, NCHARS characters starting at CHARPOS, into the |
1110 int to_byte = buf_charpos_to_bytepos (buf, from + nchars); | 1156 int to_byte = buf_charpos_to_bytepos (buf, from + nchars); |
1111 int incoming_nbytes = to_byte - from_byte; | 1157 int incoming_nbytes = to_byte - from_byte; |
1112 int outgoing_nbytes = incoming_nbytes; | 1158 int outgoing_nbytes = incoming_nbytes; |
1113 int combined_before_bytes, combined_after_bytes; | 1159 int combined_before_bytes, combined_after_bytes; |
1114 int adjusted_nchars; | 1160 int adjusted_nchars; |
1161 INTERVAL intervals; | |
1115 | 1162 |
1116 /* Make OUTGOING_NBYTES describe the text | 1163 /* Make OUTGOING_NBYTES describe the text |
1117 as it will be inserted in this buffer. */ | 1164 as it will be inserted in this buffer. */ |
1118 | 1165 |
1119 if (NILP (current_buffer->enable_multibyte_characters)) | 1166 if (NILP (current_buffer->enable_multibyte_characters)) |
1163 combined_after_bytes | 1210 combined_after_bytes |
1164 = count_combining_after (PT_ADDR, outgoing_nbytes, | 1211 = count_combining_after (PT_ADDR, outgoing_nbytes, |
1165 PT, PT_BYTE); | 1212 PT, PT_BYTE); |
1166 | 1213 |
1167 /* This is the net amount that Z will increase from this insertion. */ | 1214 /* This is the net amount that Z will increase from this insertion. */ |
1168 adjusted_nchars = nchars - !!combined_before_bytes - combined_after_bytes; | 1215 adjusted_nchars = nchars - combined_before_bytes - combined_after_bytes; |
1169 | 1216 |
1170 /* Record deletion of the surrounding text that combines with | 1217 /* Record deletion of the surrounding text that combines with |
1171 the insertion. This, together with recording the insertion, | 1218 the insertion. This, together with recording the insertion, |
1172 will add up to the right stuff in the undo list. | 1219 will add up to the right stuff in the undo list. |
1173 | 1220 |
1187 if (BUF_INTERVALS (current_buffer) != 0) | 1234 if (BUF_INTERVALS (current_buffer) != 0) |
1188 offset_intervals (current_buffer, PT, adjusted_nchars); | 1235 offset_intervals (current_buffer, PT, adjusted_nchars); |
1189 #endif | 1236 #endif |
1190 | 1237 |
1191 GAP_SIZE -= outgoing_nbytes; | 1238 GAP_SIZE -= outgoing_nbytes; |
1192 GPT += nchars - !!combined_before_bytes - !!combined_after_bytes; | 1239 GPT += nchars - combined_before_bytes - !!combined_after_bytes; |
1193 ZV += adjusted_nchars; | 1240 ZV += adjusted_nchars; |
1194 Z += adjusted_nchars; | 1241 Z += adjusted_nchars; |
1195 GPT_BYTE += outgoing_nbytes; | 1242 GPT_BYTE += outgoing_nbytes; |
1196 ZV_BYTE += outgoing_nbytes; | 1243 ZV_BYTE += outgoing_nbytes; |
1197 Z_BYTE += outgoing_nbytes; | 1244 Z_BYTE += outgoing_nbytes; |
1198 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ | 1245 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ |
1199 adjust_overlays_for_insert (PT, adjusted_nchars); | 1246 adjust_overlays_for_insert (PT, adjusted_nchars); |
1200 adjust_markers_for_insert (PT, PT_BYTE, PT + adjusted_nchars, | 1247 adjust_markers_for_insert (PT, PT_BYTE, PT + adjusted_nchars, |
1201 PT_BYTE + outgoing_nbytes, | 1248 PT_BYTE + outgoing_nbytes, |
1202 combined_before_bytes, combined_after_bytes, 0); | 1249 combined_before_bytes, combined_after_bytes, 0); |
1250 | |
1251 /* "Delete" the combined-after bytes, as far as intervals are concerned. | |
1252 Note that as far as the intervals are concerned, | |
1253 no insertion has yet taken place, so these bytes are right after PT. */ | |
1254 if (combined_after_bytes) | |
1255 offset_intervals (current_buffer, PT, - combined_after_bytes); | |
1256 | |
1257 /* Get the intervals for the part of the string we are inserting-- | |
1258 not including the combined-before bytes. */ | |
1259 intervals = BUF_INTERVALS (buf); | |
1260 if (combined_before_bytes != 0 | |
1261 || nbytes < BUF_Z_BYTE (buf) - BUF_BEG_BYTE (buf)) | |
1262 intervals = copy_intervals (intervals, from + combined_before_bytes, | |
1263 nchars - combined_before_bytes); | |
1264 | |
1265 /* Insert those intervals. */ | |
1266 graft_intervals_into_buffer (intervals, PT, nchars - combined_before_bytes, | |
1267 current_buffer, inherit); | |
1268 | |
1269 | |
1203 adjust_point (adjusted_nchars + combined_after_bytes, | 1270 adjust_point (adjusted_nchars + combined_after_bytes, |
1204 outgoing_nbytes + combined_after_bytes); | 1271 outgoing_nbytes + combined_after_bytes); |
1205 | 1272 |
1206 if (combined_after_bytes) | 1273 if (combined_after_bytes) |
1207 move_gap_both (GPT + 1, GPT_BYTE + combined_after_bytes); | 1274 move_gap_both (GPT + 1, GPT_BYTE + combined_after_bytes); |
1208 | 1275 |
1209 if (GPT_BYTE < GPT) | 1276 if (GPT_BYTE < GPT) |
1210 abort (); | 1277 abort (); |
1211 | |
1212 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ | |
1213 graft_intervals_into_buffer (copy_intervals (BUF_INTERVALS (buf), | |
1214 from, nchars), | |
1215 PT - adjusted_nchars, adjusted_nchars, | |
1216 current_buffer, inherit); | |
1217 } | 1278 } |
1218 | 1279 |
1219 /* This function should be called after moving gap to FROM and before | 1280 /* This function should be called after moving gap to FROM and before |
1220 altering text between FROM and TO. This adjusts various position | 1281 altering text between FROM and TO. This adjusts various position |
1221 keepers and markers as if the text is deleted. Don't forget to | 1282 keepers and markers as if the text is deleted. Don't forget to |
1239 adjust_after_replace (from, from_byte, to, to_byte, len, len_byte, | 1300 adjust_after_replace (from, from_byte, to, to_byte, len, len_byte, |
1240 combined_before_bytes, combined_after_bytes) | 1301 combined_before_bytes, combined_after_bytes) |
1241 int from, from_byte, to, to_byte, len, len_byte; | 1302 int from, from_byte, to, to_byte, len, len_byte; |
1242 int combined_before_bytes, combined_after_bytes; | 1303 int combined_before_bytes, combined_after_bytes; |
1243 { | 1304 { |
1244 int adjusted_nchars = len - !!combined_before_bytes - combined_after_bytes; | 1305 int adjusted_nchars = len - combined_before_bytes - combined_after_bytes; |
1245 record_insert (from - !!combined_before_bytes, len); | 1306 record_insert (from - !!combined_before_bytes, len); |
1246 if (from < PT) | 1307 if (from < PT) |
1247 adjust_point (len - (to - from) + combined_after_bytes, | 1308 adjust_point (len - (to - from) + combined_after_bytes, |
1248 len_byte - (to_byte - from_byte) + combined_after_bytes); | 1309 len_byte - (to_byte - from_byte) + combined_after_bytes); |
1249 #ifdef USE_TEXT_PROPERTIES | 1310 #ifdef USE_TEXT_PROPERTIES |
1280 int nbytes_del, nchars_del; | 1341 int nbytes_del, nchars_del; |
1281 register Lisp_Object temp; | 1342 register Lisp_Object temp; |
1282 struct gcpro gcpro1; | 1343 struct gcpro gcpro1; |
1283 int combined_before_bytes, combined_after_bytes; | 1344 int combined_before_bytes, combined_after_bytes; |
1284 int adjusted_inschars; | 1345 int adjusted_inschars; |
1346 INTERVAL intervals; | |
1285 | 1347 |
1286 GCPRO1 (new); | 1348 GCPRO1 (new); |
1287 | 1349 |
1288 if (prepare) | 1350 if (prepare) |
1289 { | 1351 { |
1361 combined_after_bytes | 1423 combined_after_bytes |
1362 = count_combining_after (XSTRING (new)->data, insbytes, PT, PT_BYTE); | 1424 = count_combining_after (XSTRING (new)->data, insbytes, PT, PT_BYTE); |
1363 | 1425 |
1364 /* This is the net amount that Z will increase from this insertion. */ | 1426 /* This is the net amount that Z will increase from this insertion. */ |
1365 adjusted_inschars | 1427 adjusted_inschars |
1366 = inschars - !!combined_before_bytes - combined_after_bytes; | 1428 = inschars - combined_before_bytes - combined_after_bytes; |
1367 | 1429 |
1368 /* Record deletion of the surrounding text that combines with | 1430 /* Record deletion of the surrounding text that combines with |
1369 the insertion. This, together with recording the insertion, | 1431 the insertion. This, together with recording the insertion, |
1370 will add up to the right stuff in the undo list. | 1432 will add up to the right stuff in the undo list. |
1371 | 1433 |
1393 #ifdef USE_TEXT_PROPERTIES | 1455 #ifdef USE_TEXT_PROPERTIES |
1394 offset_intervals (current_buffer, PT, adjusted_inschars - nchars_del); | 1456 offset_intervals (current_buffer, PT, adjusted_inschars - nchars_del); |
1395 #endif | 1457 #endif |
1396 | 1458 |
1397 GAP_SIZE -= insbytes; | 1459 GAP_SIZE -= insbytes; |
1398 GPT += inschars - !!combined_before_bytes - !!combined_after_bytes; | 1460 GPT += inschars - combined_before_bytes - !!combined_after_bytes; |
1399 ZV += adjusted_inschars; | 1461 ZV += adjusted_inschars; |
1400 Z += adjusted_inschars; | 1462 Z += adjusted_inschars; |
1401 GPT_BYTE += insbytes; | 1463 GPT_BYTE += insbytes; |
1402 ZV_BYTE += insbytes; | 1464 ZV_BYTE += insbytes; |
1403 ZV_BYTE += insbytes; | 1465 ZV_BYTE += insbytes; |
1412 adjust_overlays_for_insert (from, adjusted_inschars); | 1474 adjust_overlays_for_insert (from, adjusted_inschars); |
1413 adjust_markers_for_insert (from, from_byte, from + adjusted_inschars, | 1475 adjust_markers_for_insert (from, from_byte, from + adjusted_inschars, |
1414 from_byte + insbytes, | 1476 from_byte + insbytes, |
1415 combined_before_bytes, combined_after_bytes, 0); | 1477 combined_before_bytes, combined_after_bytes, 0); |
1416 | 1478 |
1417 #ifdef USE_TEXT_PROPERTIES | 1479 /* "Delete" the combined-after bytes, as far as intervals are concerned. |
1418 /* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */ | 1480 Note that as far as the intervals are concerned, |
1419 graft_intervals_into_buffer (XSTRING (new)->intervals, from, | 1481 no insertion has yet taken place, so these bytes are right after PT. */ |
1420 inschars, current_buffer, inherit); | 1482 if (combined_after_bytes) |
1421 #endif | 1483 offset_intervals (current_buffer, PT, - combined_after_bytes); |
1484 | |
1485 /* Get the intervals for the part of the string we are inserting-- | |
1486 not including the combined-before bytes. */ | |
1487 intervals = XSTRING (new)->intervals; | |
1488 if (combined_before_bytes != 0) | |
1489 intervals = copy_intervals (intervals, combined_before_bytes, | |
1490 inschars - combined_before_bytes); | |
1491 | |
1492 /* Insert those intervals. */ | |
1493 graft_intervals_into_buffer (intervals, from, | |
1494 inschars - combined_before_bytes, | |
1495 current_buffer, inherit); | |
1422 | 1496 |
1423 if (insbytes == 0) | 1497 if (insbytes == 0) |
1424 evaporate_overlays (from); | 1498 evaporate_overlays (from); |
1425 | 1499 |
1426 if (combined_after_bytes) | 1500 if (combined_after_bytes) |