X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/4431e6d9b30062407a60897db58356a36cedf49f..adf2aa61404305e58e71cde0193bb650aff2c4b3:/src/insdel.c diff --git a/src/insdel.c b/src/insdel.c index ed68426424..ebd096a292 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -1057,6 +1057,9 @@ insert_from_buffer_1 (struct buffer *buf, ptrdiff_t outgoing_nbytes = incoming_nbytes; INTERVAL intervals; + if (nchars == 0) + return; + /* Make OUTGOING_NBYTES describe the text as it will be inserted in this buffer. */ @@ -1211,12 +1214,9 @@ adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte, adjust_markers_for_insert (from, from_byte, from + len, from_byte + len_byte, 0); - if (! EQ (BVAR (current_buffer, undo_list), Qt)) - { - if (nchars_del > 0) - record_delete (from, prev_text); - record_insert (from, len); - } + if (nchars_del > 0) + record_delete (from, prev_text); + record_insert (from, len); if (len > nchars_del) adjust_overlays_for_insert (from, len - nchars_del); @@ -1373,12 +1373,12 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, emacs_abort (); #endif - if (! EQ (BVAR (current_buffer, undo_list), Qt)) + /* Record the insertion first, so that when we undo, + the deletion will be undone first. Thus, undo + will insert before deleting, and thus will keep + the markers before and after this text separate. */ + if (!NILP (deletion)) { - /* Record the insertion first, so that when we undo, - the deletion will be undone first. Thus, undo - will insert before deleting, and thus will keep - the markers before and after this text separate. */ record_insert (from + SCHARS (deletion), inschars); record_delete (from, deletion); } @@ -1718,8 +1718,7 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte, so that undo handles this after reinserting the text. */ adjust_markers_for_delete (from, from_byte, to, to_byte); - if (! EQ (BVAR (current_buffer, undo_list), Qt)) - record_delete (from, deletion); + record_delete (from, deletion); MODIFF++; CHARS_MODIFF = MODIFF; @@ -1760,27 +1759,22 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte, 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); } @@ -1796,8 +1790,8 @@ modify_region_1 (ptrdiff_t start, ptrdiff_t end, bool preserve_chars_modiff) 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; @@ -1868,6 +1862,17 @@ prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end, } 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, @@ -1877,10 +1882,12 @@ prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end, invalidate_region_cache (current_buffer, current_buffer->width_run_cache, start - BEG, Z - end); - - Vdeactivate_mark = Qt; + if (current_buffer->bidi_paragraph_cache) + invalidate_region_cache (current_buffer, + current_buffer->bidi_paragraph_cache, + start - BEG, Z - end); } - + /* These macros work with an argument named `preserve_ptr' and a local variable named `preserve_marker'. */ @@ -1913,12 +1920,18 @@ prepare_to_modify_buffer (ptrdiff_t start, ptrdiff_t end, VARIABLE is the variable to maybe set to nil. NO-ERROR-FLAG is nil if there was an error, anything else meaning no error (so this function does nothing). */ -static Lisp_Object -reset_var_on_error (Lisp_Object val) +struct rvoe_arg +{ + Lisp_Object *location; + bool errorp; +}; + +static void +reset_var_on_error (void *ptr) { - if (NILP (XCDR (val))) - Fset (XCAR (val), Qnil); - return Qnil; + struct rvoe_arg *p = ptr; + if (p->errorp) + *p->location = Qnil; } /* Signal a change to the buffer immediately before it happens. @@ -1936,6 +1949,7 @@ signal_before_change (ptrdiff_t start_int, ptrdiff_t end_int, Lisp_Object preserve_marker; struct gcpro gcpro1, gcpro2, gcpro3; ptrdiff_t count = SPECPDL_INDEX (); + struct rvoe_arg rvoe_arg; if (inhibit_modification_hooks) return; @@ -1963,13 +1977,14 @@ signal_before_change (ptrdiff_t start_int, ptrdiff_t end_int, if (!NILP (Vbefore_change_functions)) { Lisp_Object args[3]; - Lisp_Object rvoe_arg = Fcons (Qbefore_change_functions, Qnil); + rvoe_arg.location = &Vbefore_change_functions; + rvoe_arg.errorp = 1; PRESERVE_VALUE; PRESERVE_START_END; /* Mark before-change-functions to be reset to nil in case of error. */ - record_unwind_protect (reset_var_on_error, rvoe_arg); + record_unwind_protect_ptr (reset_var_on_error, &rvoe_arg); /* Actually run the hook functions. */ args[0] = Qbefore_change_functions; @@ -1978,7 +1993,7 @@ signal_before_change (ptrdiff_t start_int, ptrdiff_t end_int, Frun_hook_with_args (3, args); /* There was no error: unarm the reset_on_error. */ - XSETCDR (rvoe_arg, Qt); + rvoe_arg.errorp = 0; } if (buffer_has_overlays ()) @@ -2009,6 +2024,8 @@ void signal_after_change (ptrdiff_t charpos, ptrdiff_t lendel, ptrdiff_t lenins) { ptrdiff_t count = SPECPDL_INDEX (); + struct rvoe_arg rvoe_arg; + if (inhibit_modification_hooks) return; @@ -2042,10 +2059,11 @@ signal_after_change (ptrdiff_t charpos, ptrdiff_t lendel, ptrdiff_t lenins) if (!NILP (Vafter_change_functions)) { Lisp_Object args[4]; - Lisp_Object rvoe_arg = Fcons (Qafter_change_functions, Qnil); + rvoe_arg.location = &Vafter_change_functions; + rvoe_arg.errorp = 1; /* Mark after-change-functions to be reset to nil in case of error. */ - record_unwind_protect (reset_var_on_error, rvoe_arg); + record_unwind_protect_ptr (reset_var_on_error, &rvoe_arg); /* Actually run the hook functions. */ args[0] = Qafter_change_functions; @@ -2055,7 +2073,7 @@ signal_after_change (ptrdiff_t charpos, ptrdiff_t lendel, ptrdiff_t lenins) Frun_hook_with_args (4, args); /* There was no error: unarm the reset_on_error. */ - XSETCDR (rvoe_arg, Qt); + rvoe_arg.errorp = 0; } if (buffer_has_overlays ()) @@ -2075,11 +2093,10 @@ signal_after_change (ptrdiff_t charpos, ptrdiff_t lendel, ptrdiff_t lenins) unbind_to (count, Qnil); } -static Lisp_Object +static void Fcombine_after_change_execute_1 (Lisp_Object val) { Vcombine_after_change_calls = val; - return val; } DEFUN ("combine-after-change-execute", Fcombine_after_change_execute,