You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
#include <config.h>
QUIT;
}
-/* Add `amount' to the position of every marker in the current buffer
- whose current position is between `from' (exclusive) and `to' (inclusive).
+/* Add AMOUNT to the position of every marker in the current buffer
+ whose current position is between FROM (exclusive) and TO (inclusive).
+
Also, any markers past the outside of that interval, in the direction
of adjustment, are first moved back to the near end of the interval
- and then adjusted by `amount'. */
+ and then adjusted by AMOUNT.
+
+ When the latter adjustment is done, if AMOUNT is negative,
+ we record the adjustment for undo. (This case happens only for
+ deletion.) */
static void
adjust_markers (from, to, amount)
}
else
{
+ /* Here's the case where a marker is inside text being deleted.
+ AMOUNT can be negative for gap motion, too,
+ but then this range contains no markers. */
if (mpos > from + amount && mpos <= from)
- mpos = from + amount;
+ {
+ record_marker_adjustment (marker, from + amount - mpos);
+ mpos = from + amount;
+ }
}
if (mpos > from && mpos <= to)
mpos += amount;
}
}
+/* Adjust markers whose insertion-type is t
+ for an insertion of AMOUNT characters at POS. */
+
+static void
+adjust_markers_for_insert (pos, amount)
+ register int pos, amount;
+{
+ Lisp_Object marker;
+
+ marker = BUF_MARKERS (current_buffer);
+
+ while (!NILP (marker))
+ {
+ register struct Lisp_Marker *m = XMARKER (marker);
+ if (m->insertion_type && m->bufpos == pos)
+ m->bufpos += amount;
+ marker = m->chain;
+ }
+}
+
/* Add the specified amount to point. This is used only when the value
of point changes due to an insert or delete; it does not represent
a conceptual change in point as a marker. In particular, point is
not crossing any interval boundaries, so there's no need to use the
usual SET_PT macro. In fact it would be incorrect to do so, because
- either the old or the new value of point is out of synch with the
+ either the old or the new value of point is out of sync with the
current set of intervals. */
static void
adjust_point (amount)
That won't work because so many places use `int'. */
if (Z - BEG + GAP_SIZE + increment
- >= ((unsigned) 1 << (min (INTBITS, VALBITS) - 1)))
+ >= ((unsigned) 1 << (min (BITS_PER_INT, VALBITS) - 1)))
error ("Buffer exceeds maximum size");
BLOCK_INPUT;
ZV += length;
Z += length;
adjust_overlays_for_insert (PT, length);
+ adjust_markers_for_insert (PT, length);
adjust_point (length);
#ifdef USE_TEXT_PROPERTIES
ZV += length;
Z += length;
adjust_overlays_for_insert (PT, length);
+ adjust_markers_for_insert (PT, length);
/* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
graft_intervals_into_buffer (XSTRING (string)->intervals, PT, length,
ZV += length;
Z += length;
adjust_overlays_for_insert (PT, length);
+ adjust_markers_for_insert (PT, length);
adjust_point (length);
/* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
if (prepare)
prepare_to_modify_buffer (from, to);
+ /* Relocate all markers pointing into the new, larger gap
+ to point at the end of the text before the gap.
+ This has to be done before recording the deletion,
+ so undo handles this after reinserting the text. */
+ adjust_markers (to + GAP_SIZE, to + GAP_SIZE, - numdel - GAP_SIZE);
+
record_delete (from, numdel);
MODIFF++;
/* Only defined if Emacs is compiled with USE_TEXT_PROPERTIES */
offset_intervals (current_buffer, from, - numdel);
- /* Relocate all markers pointing into the new, larger gap
- to point at the end of the text before the gap. */
- adjust_markers (to + GAP_SIZE, to + GAP_SIZE, - numdel - GAP_SIZE);
-
/* Adjust the overlay center as needed. This must be done after
adjusting the markers that bound the overlays. */
adjust_overlays_for_delete (from, numdel);
That way, if there's an error in them, they will stay nil. */
before_change_functions = Vbefore_change_functions;
after_change_functions = Vafter_change_functions;
- Vbefore_change_function = Qnil;
- Vafter_change_function = Qnil;
+ Vbefore_change_functions = Qnil;
+ Vafter_change_functions = Qnil;
GCPRO2 (before_change_functions, after_change_functions);
/* Actually run the hook functions. */
POS is the address of the start of the changed text.
LENDEL is the number of characters of the text before the change.
(Not the whole buffer; just the part that was changed.)
- LENINS is the number of characters in the changed text.
-
- (Hence POS + LENINS - LENDEL is the position after the changed text.) */
+ LENINS is the number of characters in that part of the text
+ after the change. */
void
signal_after_change (pos, lendel, lenins)
That way, if there's an error in them, they will stay nil. */
before_change_functions = Vbefore_change_functions;
after_change_functions = Vafter_change_functions;
- Vbefore_change_function = Qnil;
- Vafter_change_function = Qnil;
+ Vbefore_change_functions = Qnil;
+ Vafter_change_functions = Qnil;
GCPRO2 (before_change_functions, after_change_functions);
/* Actually run the hook functions. */
if (!NILP (current_buffer->overlays_before)
|| !NILP (current_buffer->overlays_after))
report_overlay_modification (make_number (pos),
- make_number (pos + lenins - lendel),
+ make_number (pos + lenins),
1,
make_number (pos), make_number (pos + lenins),
make_number (lendel));
+
+ /* After an insertion, call the text properties
+ insert-behind-hooks or insert-in-front-hooks. */
+ if (lendel == 0)
+ report_interval_modification (pos, pos + lenins);
}