static void adjust_markers_gap_motion P_ ((int, int, int));
static void adjust_markers_for_insert P_ ((int, int, int, int, int, int, int));
static void adjust_markers_for_delete P_ ((int, int, int, int));
+static void adjust_markers_for_record_delete P_ ((int, int, int, int));
static void adjust_point P_ ((int, int));
Lisp_Object Fcombine_after_change_execute ();
Lisp_Object marker;
register struct Lisp_Marker *m;
register int charpos;
- /* This is what GAP_SIZE will be when this deletion is finished. */
- int coming_gap_size = GAP_SIZE + to_byte - from_byte;
marker = BUF_MARKERS (current_buffer);
}
}
\f
+/* Adjust all markers for calling record_delete for combining bytes.
+ whose range in bytes is FROM_BYTE to TO_BYTE.
+ The range in charpos is FROM to TO. */
+
+static void
+adjust_markers_for_record_delete (from, from_byte, to, to_byte)
+ register int from, from_byte, to, to_byte;
+{
+ Lisp_Object marker;
+ register struct Lisp_Marker *m;
+ register int charpos;
+
+ marker = BUF_MARKERS (current_buffer);
+
+ while (!NILP (marker))
+ {
+ m = XMARKER (marker);
+ charpos = m->charpos;
+
+ /* If the marker is after the deletion,
+ relocate by number of chars / bytes deleted. */
+ if (charpos > to)
+ ;
+ /* Here's the case where a marker is inside text being deleted. */
+ else if (charpos > from)
+ record_marker_adjustment (marker, from - charpos);
+
+ marker = m->chain;
+ }
+}
+\f
/* Adjust markers for an insertion that stretches from FROM / FROM_BYTE
to TO / TO_BYTE. We have to relocate the charpos of every marker
that points after the insertion (but not their bytepos).
from the buffer and reinsert them. */
if (combined_after_bytes)
- record_delete (PT, combined_after_bytes);
+ {
+ adjust_markers_for_record_delete (PT, PT_BYTE,
+ PT + combined_after_bytes,
+ PT_BYTE + combined_after_bytes);
+ record_delete (PT, combined_after_bytes);
+ }
if (combined_before_bytes)
- record_delete (PT - 1, 1);
+ {
+ adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1),
+ PT, PT_BYTE);
+ record_delete (PT - 1, 1);
+ }
record_insert (PT - !!combined_before_bytes,
nchars - combined_before_bytes + !!combined_before_bytes);
from the buffer and reinsert them. */
if (combined_after_bytes)
- record_delete (PT, combined_after_bytes);
+ {
+ adjust_markers_for_record_delete (PT, PT_BYTE,
+ PT + combined_after_bytes,
+ PT_BYTE + combined_after_bytes);
+ record_delete (PT, combined_after_bytes);
+ }
if (combined_before_bytes)
- record_delete (PT - 1, 1);
+ {
+ adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1),
+ PT, PT_BYTE);
+ record_delete (PT - 1, 1);
+ }
record_insert (PT - !!combined_before_bytes,
nchars - combined_before_bytes + !!combined_before_bytes);
from the buffer and reinsert them. */
if (combined_after_bytes)
- record_delete (PT, combined_after_bytes);
+ {
+ adjust_markers_for_record_delete (PT, PT_BYTE,
+ PT + combined_after_bytes,
+ PT_BYTE + combined_after_bytes);
+ record_delete (PT, combined_after_bytes);
+ }
if (combined_before_bytes)
- record_delete (PT - 1, 1);
+ {
+ adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1),
+ PT, PT_BYTE);
+ record_delete (PT - 1, 1);
+ }
record_insert (PT - !!combined_before_bytes,
nchars - combined_before_bytes + !!combined_before_bytes);
= count_combining_after (GPT_ADDR, len_byte, from, from_byte);
if (combined_after_bytes)
- record_delete (from, combined_after_bytes);
+ {
+ adjust_markers_for_record_delete (from, from_byte,
+ from + combined_after_bytes,
+ from_byte + combined_after_bytes);
+ record_delete (from, combined_after_bytes);
+ }
if (combined_before_bytes)
- record_delete (from - 1, 1);
+ {
+ adjust_markers_for_record_delete (from - 1, CHAR_TO_BYTE (from - 1),
+ from, from_byte);
+ record_delete (from - 1, 1);
+ }
/* Update various buffer positions for the new text. */
GAP_SIZE -= len_byte;
from the buffer and reinsert them. */
if (combined_after_bytes)
- record_delete (PT, combined_after_bytes);
+ {
+ adjust_markers_for_record_delete (PT, PT_BYTE,
+ PT + combined_after_bytes,
+ PT_BYTE + combined_after_bytes);
+ record_delete (PT, combined_after_bytes);
+ }
if (combined_before_bytes)
- record_delete (PT - 1, 1);
+ {
+ adjust_markers_for_record_delete (PT - 1, CHAR_TO_BYTE (PT - 1),
+ PT, PT_BYTE);
+ record_delete (PT - 1, 1);
+ }
record_insert (PT - !!combined_before_bytes,
inschars - combined_before_bytes + !!combined_before_bytes);
Do this before recording the deletion,
so that undo handles this after reinserting the text. */
adjust_markers_for_delete (from, from_byte, to, to_byte);
-
+ if (combined_after_bytes)
+ {
+ int from_byte_1 = from_byte;
+ DEC_POS (from_byte_1);
+
+ /* Adjust markers for the phony deletion
+ that we are about to call record_undo for. */
+
+ /* Here we delete the markers that formerly
+ pointed at TO ... TO + COMBINED_AFTER_BYTES.
+ But because of the call to adjust_markers_for_delete, above,
+ they now point at FROM ... FROM + COMBINED_AFTER_BYTES. */
+ adjust_markers_for_record_delete (from, from_byte,
+ from + combined_after_bytes,
+ from_byte + combined_after_bytes);
+
+ adjust_markers_for_record_delete (from - 1, from_byte_1,
+ from, from_byte);
+ }
record_delete (from - !!combined_after_bytes,
nchars_del + combined_after_bytes + !!combined_after_bytes);
+
if (combined_after_bytes)
/* COMBINED_AFTER_BYTES nonzero means that the above record_delete
moved the gap by calling Fbuffer_substring. We must move the
end_unchanged = Z - GPT;
if (combined_after_bytes)
- combine_bytes (from, from_byte, combined_after_bytes);
+ {
+ combine_bytes (from, from_byte, combined_after_bytes);
- if (combined_after_bytes)
- record_insert (GPT - 1, 1);
+ record_insert (GPT - 1, 1);
+ }
evaporate_overlays (from);
signal_after_change (from, nchars_del, 0);