aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2019-07-02 16:04:16 -0400
committerStefan Monnier2019-07-02 16:04:16 -0400
commitdc3093904d74a7c51d452439888c4f36e4274e9f (patch)
treeb829cf7425eaea8a39ffddb3e771626bdf5d9bf0 /src
parent1c88af362f038c010f1a5c63e0ed5a431ba5d5a7 (diff)
downloademacs-dc3093904d74a7c51d452439888c4f36e4274e9f.tar.gz
emacs-dc3093904d74a7c51d452439888c4f36e4274e9f.zip
* src/insdel.c (insert_from_gap_1): New fun, extracted from insert_from_gap.
(insert_from_gap): Use it. * src/lisp.h (insert_from_gap_1): Declare it. * src/json.c (Fjson_insert): * src/fileio.c (Finsert_file_contents): Use it.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c12
-rw-r--r--src/insdel.c53
-rw-r--r--src/json.c12
-rw-r--r--src/lisp.h1
4 files changed, 41 insertions, 37 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 7f4478a9448..fc938ebe1fa 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4436,17 +4436,7 @@ by calling `format-decode', which see. */)
4436 report_file_error ("Read error", orig_filename); 4436 report_file_error ("Read error", orig_filename);
4437 4437
4438 /* Make the text read part of the buffer. */ 4438 /* Make the text read part of the buffer. */
4439 GAP_SIZE -= inserted; 4439 insert_from_gap_1 (inserted, inserted, false);
4440 GPT += inserted;
4441 GPT_BYTE += inserted;
4442 ZV += inserted;
4443 ZV_BYTE += inserted;
4444 Z += inserted;
4445 Z_BYTE += inserted;
4446
4447 if (GAP_SIZE > 0)
4448 /* Put an anchor to ensure multi-byte form ends at gap. */
4449 *GPT_ADDR = 0;
4450 4440
4451 notfound: 4441 notfound:
4452 4442
diff --git a/src/insdel.c b/src/insdel.c
index 85fffd8fd16..1da8d551c73 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -115,7 +115,7 @@ gap_left (ptrdiff_t charpos, ptrdiff_t bytepos, bool newgap)
115 i = GPT_BYTE; 115 i = GPT_BYTE;
116 to = GAP_END_ADDR; 116 to = GAP_END_ADDR;
117 from = GPT_ADDR; 117 from = GPT_ADDR;
118 new_s1 = GPT_BYTE; 118 new_s1 = GPT_BYTE; /* May point in the middle of multibyte sequences. */
119 119
120 /* Now copy the characters. To move the gap down, 120 /* Now copy the characters. To move the gap down,
121 copy characters up. */ 121 copy characters up. */
@@ -133,11 +133,17 @@ gap_left (ptrdiff_t charpos, ptrdiff_t bytepos, bool newgap)
133 make_gap_smaller set inhibit-quit. */ 133 make_gap_smaller set inhibit-quit. */
134 if (QUITP) 134 if (QUITP)
135 { 135 {
136 /* FIXME: This can point in the middle of a multibyte character. */
136 bytepos = new_s1; 137 bytepos = new_s1;
137 charpos = BYTE_TO_CHAR (bytepos); 138 charpos = BYTE_TO_CHAR (bytepos);
138 break; 139 break;
139 } 140 }
140 /* Move at most 32000 chars before checking again for a quit. */ 141 /* Move at most 32000 chars before checking again for a quit. */
142 /* FIXME: This 32KB chunk size dates back to before 1991.
143 Maybe we should bump it to reflect the >1000x increase
144 in memory size and bandwidth since that time.
145 Is it even worthwhile checking `quit` within this loop?
146 Especially since make_gap_smaller/larger binds inhibit-quit anyway! */
141 if (i > 32000) 147 if (i > 32000)
142 i = 32000; 148 i = 32000;
143 new_s1 -= i; 149 new_s1 -= i;
@@ -164,7 +170,7 @@ gap_right (ptrdiff_t charpos, ptrdiff_t bytepos)
164{ 170{
165 register unsigned char *to, *from; 171 register unsigned char *to, *from;
166 register ptrdiff_t i; 172 register ptrdiff_t i;
167 ptrdiff_t new_s1; 173 ptrdiff_t new_s1; /* May point in the middle of multibyte sequences. */
168 174
169 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT); 175 BUF_COMPUTE_UNCHANGED (current_buffer, charpos, GPT);
170 176
@@ -189,6 +195,7 @@ gap_right (ptrdiff_t charpos, ptrdiff_t bytepos)
189 make_gap_smaller set inhibit-quit. */ 195 make_gap_smaller set inhibit-quit. */
190 if (QUITP) 196 if (QUITP)
191 { 197 {
198 /* FIXME: This can point in the middle of a multibyte character. */
192 bytepos = new_s1; 199 bytepos = new_s1;
193 charpos = BYTE_TO_CHAR (bytepos); 200 charpos = BYTE_TO_CHAR (bytepos);
194 break; 201 break;
@@ -1072,6 +1079,34 @@ insert_from_string_1 (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
1072 1079
1073/* Insert a sequence of NCHARS chars which occupy NBYTES bytes 1080/* Insert a sequence of NCHARS chars which occupy NBYTES bytes
1074 starting at GAP_END_ADDR - NBYTES (if text_at_gap_tail) and at 1081 starting at GAP_END_ADDR - NBYTES (if text_at_gap_tail) and at
1082 GPT_ADDR (if not text_at_gap_tail).
1083 Contrary to insert_from_gap, this does not invalidate any cache,
1084 nor update any markers, nor record any buffer modification information
1085 of any sort. */
1086void
1087insert_from_gap_1 (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail)
1088{
1089 eassert (NILP (BVAR (current_buffer, enable_multibyte_characters))
1090 ? nchars == nbytes : nchars <= nbytes);
1091
1092 GAP_SIZE -= nbytes;
1093 if (! text_at_gap_tail)
1094 {
1095 GPT += nchars;
1096 GPT_BYTE += nbytes;
1097 }
1098 ZV += nchars;
1099 Z += nchars;
1100 ZV_BYTE += nbytes;
1101 Z_BYTE += nbytes;
1102
1103 /* Put an anchor to ensure multi-byte form ends at gap. */
1104 if (GAP_SIZE > 0) *(GPT_ADDR) = 0;
1105 eassert (GPT <= GPT_BYTE);
1106}
1107
1108/* Insert a sequence of NCHARS chars which occupy NBYTES bytes
1109 starting at GAP_END_ADDR - NBYTES (if text_at_gap_tail) and at
1075 GPT_ADDR (if not text_at_gap_tail). */ 1110 GPT_ADDR (if not text_at_gap_tail). */
1076 1111
1077void 1112void
@@ -1090,19 +1125,7 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail)
1090 record_insert (GPT, nchars); 1125 record_insert (GPT, nchars);
1091 modiff_incr (&MODIFF); 1126 modiff_incr (&MODIFF);
1092 1127
1093 GAP_SIZE -= nbytes; 1128 insert_from_gap_1 (nchars, nbytes, text_at_gap_tail);
1094 if (! text_at_gap_tail)
1095 {
1096 GPT += nchars;
1097 GPT_BYTE += nbytes;
1098 }
1099 ZV += nchars;
1100 Z += nchars;
1101 ZV_BYTE += nbytes;
1102 Z_BYTE += nbytes;
1103 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
1104
1105 eassert (GPT <= GPT_BYTE);
1106 1129
1107 adjust_overlays_for_insert (ins_charpos, nchars); 1130 adjust_overlays_for_insert (ins_charpos, nchars);
1108 adjust_markers_for_insert (ins_charpos, ins_bytepos, 1131 adjust_markers_for_insert (ins_charpos, ins_bytepos,
diff --git a/src/json.c b/src/json.c
index 4c897d4be04..607b8d32646 100644
--- a/src/json.c
+++ b/src/json.c
@@ -740,17 +740,7 @@ usage: (json-insert OBJECT &rest ARGS) */)
740 if (inserted_bytes > 0) 740 if (inserted_bytes > 0)
741 { 741 {
742 /* Make the inserted text part of the buffer, as unibyte text. */ 742 /* Make the inserted text part of the buffer, as unibyte text. */
743 GAP_SIZE -= inserted_bytes; 743 insert_from_gap_1 (inserted_bytes, inserted_bytes, false);
744 GPT += inserted_bytes;
745 GPT_BYTE += inserted_bytes;
746 ZV += inserted_bytes;
747 ZV_BYTE += inserted_bytes;
748 Z += inserted_bytes;
749 Z_BYTE += inserted_bytes;
750
751 if (GAP_SIZE > 0)
752 /* Put an anchor to ensure multi-byte form ends at gap. */
753 *GPT_ADDR = 0;
754 744
755 /* If required, decode the stuff we've read into the gap. */ 745 /* If required, decode the stuff we've read into the gap. */
756 struct coding_system coding; 746 struct coding_system coding;
diff --git a/src/lisp.h b/src/lisp.h
index a0619e64f20..1a1d8ee7e48 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3667,6 +3667,7 @@ extern void insert (const char *, ptrdiff_t);
3667extern void insert_and_inherit (const char *, ptrdiff_t); 3667extern void insert_and_inherit (const char *, ptrdiff_t);
3668extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t, 3668extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
3669 bool, bool, bool); 3669 bool, bool, bool);
3670extern void insert_from_gap_1 (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
3670extern void insert_from_gap (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail); 3671extern void insert_from_gap (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
3671extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t, 3672extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
3672 ptrdiff_t, ptrdiff_t, bool); 3673 ptrdiff_t, ptrdiff_t, bool);