aboutsummaryrefslogtreecommitdiffstats
path: root/src/insdel.c
diff options
context:
space:
mode:
authorStefan Monnier2011-03-31 00:24:03 -0400
committerStefan Monnier2011-03-31 00:24:03 -0400
commit40d83b412f584cc02e68d4eac8fd5e6eb769e2fe (patch)
treeb56f27a7e6d75a8c1fd27b00179a27b5efea0a32 /src/insdel.c
parentf488fb6528738131ef41859e1f04125f2e50efce (diff)
parent44f230aa043ebb222aa0876b44d70484d5dd38db (diff)
downloademacs-40d83b412f584cc02e68d4eac8fd5e6eb769e2fe.tar.gz
emacs-40d83b412f584cc02e68d4eac8fd5e6eb769e2fe.zip
Merge from trunk
Diffstat (limited to 'src/insdel.c')
-rw-r--r--src/insdel.c80
1 files changed, 7 insertions, 73 deletions
diff --git a/src/insdel.c b/src/insdel.c
index ad3460f9a64..4bdcb4bc0b7 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -41,8 +41,6 @@ static void insert_from_buffer_1 (struct buffer *buf,
41 int inherit); 41 int inherit);
42static void gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap); 42static void gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap);
43static void gap_right (EMACS_INT charpos, EMACS_INT bytepos); 43static void gap_right (EMACS_INT charpos, EMACS_INT bytepos);
44static void adjust_markers_gap_motion (EMACS_INT from, EMACS_INT to,
45 EMACS_INT amount);
46static void adjust_markers_for_insert (EMACS_INT from, EMACS_INT from_byte, 44static void adjust_markers_for_insert (EMACS_INT from, EMACS_INT from_byte,
47 EMACS_INT to, EMACS_INT to_byte, 45 EMACS_INT to, EMACS_INT to_byte,
48 int before_markers); 46 int before_markers);
@@ -162,10 +160,9 @@ gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap)
162 memmove (to, from, i); 160 memmove (to, from, i);
163 } 161 }
164 162
165 /* Adjust markers, and buffer data structure, to put the gap at BYTEPOS. 163 /* Adjust buffer data structure, to put the gap at BYTEPOS.
166 BYTEPOS is where the loop above stopped, which may be what was specified 164 BYTEPOS is where the loop above stopped, which may be what
167 or may be where a quit was detected. */ 165 was specified or may be where a quit was detected. */
168 adjust_markers_gap_motion (bytepos, GPT_BYTE, GAP_SIZE);
169 GPT_BYTE = bytepos; 166 GPT_BYTE = bytepos;
170 GPT = charpos; 167 GPT = charpos;
171 if (bytepos < charpos) 168 if (bytepos < charpos)
@@ -217,8 +214,6 @@ gap_right (EMACS_INT charpos, EMACS_INT bytepos)
217 from += i, to += i; 214 from += i, to += i;
218 } 215 }
219 216
220 adjust_markers_gap_motion (GPT_BYTE + GAP_SIZE, bytepos + GAP_SIZE,
221 - GAP_SIZE);
222 GPT = charpos; 217 GPT = charpos;
223 GPT_BYTE = bytepos; 218 GPT_BYTE = bytepos;
224 if (bytepos < charpos) 219 if (bytepos < charpos)
@@ -227,67 +222,6 @@ gap_right (EMACS_INT charpos, EMACS_INT bytepos)
227 QUIT; 222 QUIT;
228} 223}
229 224
230/* Add AMOUNT to the byte position of every marker in the current buffer
231 whose current byte position is between FROM (exclusive) and TO (inclusive).
232
233 Also, any markers past the outside of that interval, in the direction
234 of adjustment, are first moved back to the near end of the interval
235 and then adjusted by AMOUNT.
236
237 When the latter adjustment is done, if AMOUNT is negative,
238 we record the adjustment for undo. (This case happens only for
239 deletion.)
240
241 The markers' character positions are not altered,
242 because gap motion does not affect character positions. */
243
244int adjust_markers_test;
245
246static void
247adjust_markers_gap_motion (EMACS_INT from, EMACS_INT to, EMACS_INT amount)
248{
249 /* Now that a marker has a bytepos, not counting the gap,
250 nothing needs to be done here. */
251#if 0
252 Lisp_Object marker;
253 register struct Lisp_Marker *m;
254 register EMACS_INT mpos;
255
256 marker = BUF_MARKERS (current_buffer);
257
258 while (!NILP (marker))
259 {
260 m = XMARKER (marker);
261 mpos = m->bytepos;
262 if (amount > 0)
263 {
264 if (mpos > to && mpos < to + amount)
265 {
266 if (adjust_markers_test)
267 abort ();
268 mpos = to + amount;
269 }
270 }
271 else
272 {
273 /* Here's the case where a marker is inside text being deleted.
274 AMOUNT can be negative for gap motion, too,
275 but then this range contains no markers. */
276 if (mpos > from + amount && mpos <= from)
277 {
278 if (adjust_markers_test)
279 abort ();
280 mpos = from + amount;
281 }
282 }
283 if (mpos > from && mpos <= to)
284 mpos += amount;
285 m->bufpos = mpos;
286 marker = m->chain;
287 }
288#endif
289}
290
291/* Adjust all markers for a deletion 225/* Adjust all markers for a deletion
292 whose range in bytes is FROM_BYTE to TO_BYTE. 226 whose range in bytes is FROM_BYTE to TO_BYTE.
293 The range in charpos is FROM to TO. 227 The range in charpos is FROM to TO.
@@ -2137,14 +2071,14 @@ signal_before_change (EMACS_INT start_int, EMACS_INT end_int,
2137 2071
2138 specbind (Qinhibit_modification_hooks, Qt); 2072 specbind (Qinhibit_modification_hooks, Qt);
2139 2073
2140 /* If buffer is unmodified, run a special hook for that case. */ 2074 /* If buffer is unmodified, run a special hook for that case. The
2075 check for Vfirst_change_hook is just a minor optimization. */
2141 if (SAVE_MODIFF >= MODIFF 2076 if (SAVE_MODIFF >= MODIFF
2142 && !NILP (Vfirst_change_hook) 2077 && !NILP (Vfirst_change_hook))
2143 && !NILP (Vrun_hooks))
2144 { 2078 {
2145 PRESERVE_VALUE; 2079 PRESERVE_VALUE;
2146 PRESERVE_START_END; 2080 PRESERVE_START_END;
2147 call1 (Vrun_hooks, Qfirst_change_hook); 2081 Frun_hooks (1, &Qfirst_change_hook);
2148 } 2082 }
2149 2083
2150 /* Now run the before-change-functions if any. */ 2084 /* Now run the before-change-functions if any. */