* lisp.h (modify_region_1): Remove 3rd arg and rename to...
(modify_text): ...new prototype.
(prepare_to_modify_buffer_1): New prototype.
* textprop.c (modify_region): Rename to...
(modify_text_properties): ...new function.
(add_text_properties_1, set_text_properties, Fremove_text_properties)
(Fremove_list_of_text_properties): Adjust users.
* insdel.c (modify_region_1): Remove 3rd arg and reimplement as...
(modify_text): ...new function.
(prepare_to_modify_buffer): Reimplement mostly as a wrapper for...
(prepare_to_modify_buffer_1): ...new function.
* casefiddle.c (casify_region):
* editfns.c (Fsubst_char_in_region, Ftranslate_region_internal)
(Ftranspose_regions): Use modify_text.
+2013-08-06 Dmitry Antipov <dmantipov@yandex.ru>
+
+ Invalidate region caches only if buffer text is going to be changed.
+ * lisp.h (modify_region_1): Remove 3rd arg and rename to...
+ (modify_text): ...new prototype.
+ (prepare_to_modify_buffer_1): New prototype.
+ * textprop.c (modify_region): Rename to...
+ (modify_text_properties): ...new function.
+ (add_text_properties_1, set_text_properties, Fremove_text_properties)
+ (Fremove_list_of_text_properties): Adjust users.
+ * insdel.c (modify_region_1): Remove 3rd arg and reimplement as...
+ (modify_text): ...new function.
+ (prepare_to_modify_buffer): Reimplement mostly as a wrapper for...
+ (prepare_to_modify_buffer_1): ...new function.
+ * casefiddle.c (casify_region):
+ * editfns.c (Fsubst_char_in_region, Ftranslate_region_internal)
+ (Ftranspose_regions): Use modify_text.
+
2013-08-05 Stefan Monnier <monnier@iro.umontreal.ca>
* lisp.mk (lisp): Add nadvice.elc.
validate_region (&b, &e);
start = XFASTINT (b);
end = XFASTINT (e);
- modify_region_1 (start, end, false);
+ modify_text (start, end);
record_change (start, end - start);
start_byte = CHAR_TO_BYTE (start);
else if (!changed)
{
changed = -1;
- modify_region_1 (pos, XINT (end), false);
+ modify_text (pos, XINT (end));
if (! NILP (noundo))
{
pos = XINT (start);
pos_byte = CHAR_TO_BYTE (pos);
end_pos = XINT (end);
- modify_region_1 (pos, end_pos, false);
+ modify_text (pos, end_pos);
cnt = 0;
for (; pos < end_pos; )
if (end1 == start2) /* adjacent regions */
{
- modify_region_1 (start1, end2, false);
+ modify_text (start1, end2);
record_change (start1, len1 + len2);
tmp_interval1 = copy_intervals (cur_intv, start1, len1);
{
USE_SAFE_ALLOCA;
- modify_region_1 (start1, end1, false);
- modify_region_1 (start2, end2, false);
+ modify_text (start1, end1);
+ modify_text (start2, end2);
record_change (start1, len1);
record_change (start2, len2);
tmp_interval1 = copy_intervals (cur_intv, start1, len1);
{
USE_SAFE_ALLOCA;
- modify_region_1 (start1, end2, false);
+ modify_text (start1, end2);
record_change (start1, (end2 - start1));
tmp_interval1 = copy_intervals (cur_intv, start1, len1);
tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid);
USE_SAFE_ALLOCA;
record_change (start1, (end2 - start1));
- modify_region_1 (start1, end2, false);
+ modify_text (start1, end2);
tmp_interval1 = copy_intervals (cur_intv, start1, len1);
tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid);
return deletion;
}
-/* Call this if you're about to change the region of current buffer
+/* Call this if you're about to change the text of current buffer
from character positions START to END. This checks the read-only
properties of the region, calls the necessary modification hooks,
and warns the next redisplay that it should pay attention to that
- area.
-
- If PRESERVE_CHARS_MODIFF, do not update CHARS_MODIFF.
- Otherwise set CHARS_MODIFF to the new value of MODIFF. */
+ area. */
void
-modify_region_1 (ptrdiff_t start, ptrdiff_t end, bool preserve_chars_modiff)
+modify_text (ptrdiff_t start, ptrdiff_t end)
{
prepare_to_modify_buffer (start, end, NULL);
BUF_COMPUTE_UNCHANGED (current_buffer, start - 1, end);
-
if (MODIFF <= SAVE_MODIFF)
record_first_change ();
MODIFF++;
- if (! preserve_chars_modiff)
- CHARS_MODIFF = MODIFF;
+ CHARS_MODIFF = MODIFF;
bset_point_before_scroll (current_buffer, Qnil);
}
by holding its value temporarily in a marker. */
void
-prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end,
- ptrdiff_t *preserve_ptr)
+prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end,
+ ptrdiff_t *preserve_ptr)
{
struct buffer *base_buffer;
}
signal_before_change (start, end, preserve_ptr);
+ Vdeactivate_mark = Qt;
+}
+
+/* Like above, but called when we know that the buffer text
+ will be modified and region caches should be invalidated. */
+
+void
+prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end,
+ ptrdiff_t *preserve_ptr)
+{
+ prepare_to_modify_buffer_1 (start, end, preserve_ptr);
if (current_buffer->newline_cache)
invalidate_region_cache (current_buffer,
invalidate_region_cache (current_buffer,
current_buffer->width_run_cache,
start - BEG, Z - end);
-
- Vdeactivate_mark = Qt;
}
-\f
+
/* These macros work with an argument named `preserve_ptr'
and a local variable named `preserve_marker'. */
extern void del_range_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool);
extern Lisp_Object del_range_2 (ptrdiff_t, ptrdiff_t,
ptrdiff_t, ptrdiff_t, bool);
-extern void modify_region_1 (ptrdiff_t, ptrdiff_t, bool);
+extern void modify_text (ptrdiff_t, ptrdiff_t);
extern void prepare_to_modify_buffer (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
+extern void prepare_to_modify_buffer_1 (ptrdiff_t, ptrdiff_t, ptrdiff_t *);
extern void signal_after_change (ptrdiff_t, ptrdiff_t, ptrdiff_t);
extern void adjust_after_insert (ptrdiff_t, ptrdiff_t, ptrdiff_t,
ptrdiff_t, ptrdiff_t);
xsignal0 (Qtext_read_only);
}
-/* Prepare to modify the region of BUFFER from START to END. */
+/* Prepare to modify the text properties of BUFFER from START to END. */
static void
-modify_region (Lisp_Object buffer, Lisp_Object start, Lisp_Object end)
+modify_text_properties (Lisp_Object buffer, Lisp_Object start, Lisp_Object end)
{
+ ptrdiff_t b = XINT (start), e = XINT (end);
struct buffer *buf = XBUFFER (buffer), *old = current_buffer;
set_buffer_internal (buf);
- modify_region_1 (XINT (start), XINT (end), true);
+
+ prepare_to_modify_buffer_1 (b, e, NULL);
+
+ BUF_COMPUTE_UNCHANGED (buf, b - 1, e);
+ if (MODIFF <= SAVE_MODIFF)
+ record_first_change ();
+ MODIFF++;
+
+ bset_point_before_scroll (current_buffer, Qnil);
+
set_buffer_internal (old);
}
ptrdiff_t prev_total_length = TOTAL_LENGTH (i);
ptrdiff_t prev_pos = i->position;
- modify_region (object, start, end);
+ modify_text_properties (object, start, end);
/* If someone called us recursively as a side effect of
- modify_region, and changed the intervals behind our back
+ modify_text_properties, and changed the intervals behind our back
(could happen if lock_file, called by prepare_to_modify_buffer,
triggers redisplay, and that calls add-text-properties again
in the same buffer), we cannot continue with I, because its
otherwise. */
Lisp_Object
-set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, Lisp_Object object, Lisp_Object coherent_change_p)
+set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
+ Lisp_Object object, Lisp_Object coherent_change_p)
{
register INTERVAL i;
Lisp_Object ostart, oend;
}
if (BUFFERP (object) && !NILP (coherent_change_p))
- modify_region (object, start, end);
+ modify_text_properties (object, start, end);
set_text_properties_1 (start, end, properties, object, i);
ptrdiff_t prev_total_length = TOTAL_LENGTH (i);
ptrdiff_t prev_pos = i->position;
- modify_region (object, start, end);
+ modify_text_properties (object, start, end);
/* If someone called us recursively as a side effect of
- modify_region, and changed the intervals behind our back
+ modify_text_properties, and changed the intervals behind our back
(could happen if lock_file, called by prepare_to_modify_buffer,
triggers redisplay, and that calls add-text-properties again
in the same buffer), we cannot continue with I, because its
/* We are at the beginning of an interval, with len to scan.
The flag `modified' records if changes have been made.
- When object is a buffer, we must call modify_region before changes are
- made and signal_after_change when we are done.
- We call modify_region before calling remove_properties if modified == 0,
+ When object is a buffer, we must call modify_text_properties
+ before changes are made and signal_after_change when we are done.
+ We call modify_text_properties before calling remove_properties if modified == 0,
and we call signal_after_change before returning if modified != 0. */
for (;;)
{
else if (LENGTH (i) == len)
{
if (!modified && BUFFERP (object))
- modify_region (object, start, end);
+ modify_text_properties (object, start, end);
remove_properties (Qnil, properties, i, object);
if (BUFFERP (object))
signal_after_change (XINT (start), XINT (end) - XINT (start),
i = split_interval_left (i, len);
copy_properties (unchanged, i);
if (!modified && BUFFERP (object))
- modify_region (object, start, end);
+ modify_text_properties (object, start, end);
remove_properties (Qnil, properties, i, object);
if (BUFFERP (object))
signal_after_change (XINT (start), XINT (end) - XINT (start),
if (interval_has_some_properties_list (properties, i))
{
if (!modified && BUFFERP (object))
- modify_region (object, start, end);
+ modify_text_properties (object, start, end);
remove_properties (Qnil, properties, i, object);
modified = 1;
}