/* Buffer insertion/deletion and gap motion for GNU Emacs.
- Copyright (C) 1985-1986, 1993-1995, 1997-2011
+ Copyright (C) 1985-1986, 1993-1995, 1997-2012
Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include "lisp.h"
#include "intervals.h"
-#include "buffer.h"
#include "character.h"
+#include "buffer.h"
#include "window.h"
#include "blockinput.h"
#include "region-cache.h"
-#ifndef NULL
-#define NULL 0
-#endif
-
static void insert_from_string_1 (Lisp_Object string,
ptrdiff_t pos, ptrdiff_t pos_byte,
ptrdiff_t nchars, ptrdiff_t nbytes,
static void gap_left (ptrdiff_t charpos, ptrdiff_t bytepos, int newgap);
static void gap_right (ptrdiff_t charpos, ptrdiff_t bytepos);
-static Lisp_Object Fcombine_after_change_execute (void);
-
/* List of elements of the form (BEG-UNCHANGED END-UNCHANGED CHANGE-AMOUNT)
describing changes which happened while combine_after_change_calls
was nonzero. We use this to decide how to call them
Lisp_Object Qinhibit_modification_hooks;
static void signal_before_change (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
-\f
-#define CHECK_MARKERS() \
- do \
- { \
- if (check_markers_debug_flag) \
- check_markers (); \
- } \
- while (0)
+
+/* Also used in marker.c to enable expensive marker checks. */
+
+#ifdef MARKER_DEBUG
static void
check_markers (void)
abort ();
}
}
-\f
+
+#else /* not MARKER_DEBUG */
+
+#define check_markers() do { } while (0)
+
+#endif /* MARKER_DEBUG */
+
/* Move gap to position CHARPOS.
Note that this can quit! */
was specified or may be where a quit was detected. */
GPT_BYTE = bytepos;
GPT = charpos;
- if (bytepos < charpos)
- abort ();
+ eassert (charpos <= bytepos);
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
QUIT;
}
GPT = charpos;
GPT_BYTE = bytepos;
- if (bytepos < charpos)
- abort ();
+ eassert (charpos <= bytepos);
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
QUIT;
}
for (m = BUF_MARKERS (current_buffer); m; m = m->next)
{
charpos = m->charpos;
-
- if (charpos > Z)
- abort ();
+ eassert (charpos <= Z);
/* If the marker is after the deletion,
relocate by number of chars / bytes deleted. */
}
}
- CHECK_MARKERS ();
+ check_markers ();
}
\f
Z_BYTE += nbytes;
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
- if (GPT_BYTE < GPT)
- abort ();
+ eassert (GPT <= GPT_BYTE);
/* The insert may have been in the unchanged region, so check again. */
if (Z - GPT < END_UNCHANGED)
adjust_point (nchars, nbytes);
- CHECK_MARKERS ();
+ check_markers ();
}
\f
/* Insert the part of the text of STRING, a Lisp object assumed to be
Z_BYTE += outgoing_nbytes;
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
- if (GPT_BYTE < GPT)
- abort ();
+ eassert (GPT <= GPT_BYTE);
/* The insert may have been in the unchanged region, so check again. */
if (Z - GPT < END_UNCHANGED)
adjust_point (nchars, outgoing_nbytes);
- CHECK_MARKERS ();
+ check_markers ();
}
\f
/* Insert a sequence of NCHARS chars which occupy NBYTES bytes
Z_BYTE += nbytes;
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
- if (GPT_BYTE < GPT)
- abort ();
+ eassert (GPT <= GPT_BYTE);
adjust_overlays_for_insert (GPT - nchars, nchars);
adjust_markers_for_insert (GPT - nchars, GPT_BYTE - nbytes,
if (GPT - nchars < PT)
adjust_point (nchars, nbytes);
- CHECK_MARKERS ();
+ check_markers ();
}
\f
/* Insert text from BUF, NCHARS characters starting at CHARPOS, into the
Z_BYTE += outgoing_nbytes;
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
- if (GPT_BYTE < GPT)
- abort ();
+ eassert (GPT <= GPT_BYTE);
/* The insert may have been in the unchanged region, so check again. */
if (Z - GPT < END_UNCHANGED)
if (Z - GPT < END_UNCHANGED)
END_UNCHANGED = Z - GPT;
- CHECK_MARKERS ();
+ check_markers ();
if (len == 0)
evaporate_overlays (from);
ptrdiff_t outgoing_insbytes = insbytes;
Lisp_Object deletion;
- CHECK_MARKERS ();
+ check_markers ();
GCPRO1 (new);
deletion = Qnil;
UNGCPRO;
- /* Make args be valid */
+ /* Make args be valid. */
if (from < BEGV)
from = BEGV;
if (to > ZV)
GPT_BYTE = from_byte;
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
- if (GPT_BYTE < GPT)
- abort ();
+ eassert (GPT <= GPT_BYTE);
if (GPT - BEG < BEG_UNCHANGED)
BEG_UNCHANGED = GPT - BEG;
Z_BYTE += outgoing_insbytes;
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
- if (GPT_BYTE < GPT)
- abort ();
+ eassert (GPT <= GPT_BYTE);
/* Adjust the overlay center as needed. This must be done after
adjusting the markers that bound the overlays. */
if (outgoing_insbytes == 0)
evaporate_overlays (from);
- CHECK_MARKERS ();
+ check_markers ();
MODIFF++;
CHARS_MODIFF = MODIFF;
{
ptrdiff_t nbytes_del, nchars_del;
- CHECK_MARKERS ();
+ check_markers ();
nchars_del = to - from;
nbytes_del = to_byte - from_byte;
GPT_BYTE = from_byte;
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
- if (GPT_BYTE < GPT)
- abort ();
+ eassert (GPT <= GPT_BYTE);
if (GPT - BEG < BEG_UNCHANGED)
BEG_UNCHANGED = GPT - BEG;
Z_BYTE += insbytes;
if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
- if (GPT_BYTE < GPT)
- abort ();
+ eassert (GPT <= GPT_BYTE);
/* Adjust the overlay center as needed. This must be done after
adjusting the markers that bound the overlays. */
if (insbytes == 0)
evaporate_overlays (from);
- CHECK_MARKERS ();
+ check_markers ();
MODIFF++;
CHARS_MODIFF = MODIFF;
register ptrdiff_t nbytes_del, nchars_del;
Lisp_Object deletion;
- CHECK_MARKERS ();
+ check_markers ();
nchars_del = to - from;
nbytes_del = to_byte - from_byte;
needs to access the previous gap contents. */
*(GPT_ADDR) = 0;
- if (GPT_BYTE < GPT)
- abort ();
+ eassert (GPT <= GPT_BYTE);
if (GPT - BEG < BEG_UNCHANGED)
BEG_UNCHANGED = GPT - BEG;
if (Z - GPT < END_UNCHANGED)
END_UNCHANGED = Z - GPT;
- CHECK_MARKERS ();
+ check_markers ();
evaporate_overlays (from);
/* Let redisplay consider other windows than selected_window
if modifying another buffer. */
- if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
+ if (XBUFFER (WVAR (XWINDOW (selected_window), buffer)) != current_buffer)
++windows_or_buffers_changed;
if (BUF_INTERVALS (current_buffer) != 0)
combine_after_change_list = Qnil;
combine_after_change_buffer = Qnil;
- DEFVAR_BOOL ("check-markers-debug-flag", check_markers_debug_flag,
- doc: /* Non-nil means enable debugging checks for invalid marker positions. */);
- check_markers_debug_flag = 0;
DEFVAR_LISP ("combine-after-change-calls", Vcombine_after_change_calls,
doc: /* Used internally by the `combine-after-change-calls' macro. */);
Vcombine_after_change_calls = Qnil;