diff options
| author | Eli Zaretskii <eliz@gnu.org> | 2018-06-30 16:50:31 +0300 |
|---|---|---|
| committer | Eli Zaretskii <eliz@gnu.org> | 2018-06-30 16:50:31 +0300 |
| commit | ab983522a140187fa2f7bd996c6e3760b0db8d09 (patch) | |
| tree | 26e3809db4db02393ff8d889feef6eeb0e05cb96 | |
| parent | 2f149c074d4323e607f4c91b5e6f80c4efd8e09b (diff) | |
| download | emacs-ab983522a140187fa2f7bd996c6e3760b0db8d09.tar.gz | |
Improve on last change in replace-buffer-contents
* src/editfns.c (Freplace_buffer_contents): Call modification
hooks only for the actual region where changes are made.
(Bug#31888)
| -rw-r--r-- | src/editfns.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/editfns.c b/src/editfns.c index 4d3c838d2ff..90022117140 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3238,9 +3238,21 @@ differences between the two buffers. */) Instead, we announce a single modification for the entire modified region. But don't do that if the caller inhibited modification hooks, because then they don't want that. */ + ptrdiff_t from, to; if (!inhibit_modification_hooks) { - prepare_to_modify_buffer (BEGV, ZV, NULL); + ptrdiff_t k, l; + + /* Find the first character position to be changed. */ + for (k = 0; k < size_a && !bit_is_set (ctx.deletions, k); k++) + ; + from = BEGV + k; + + /* Find the last character position to be changed. */ + for (l = size_a; l > 0 && !bit_is_set (ctx.deletions, l - 1); l--) + ; + to = BEGV + l; + prepare_to_modify_buffer (from, to, NULL); specbind (Qinhibit_modification_hooks, Qt); modification_hooks_inhibited = true; } @@ -3293,8 +3305,9 @@ differences between the two buffers. */) if (modification_hooks_inhibited) { - signal_after_change (BEGV, size_a, ZV - BEGV); - update_compositions (BEGV, ZV, CHECK_BORDER); + ptrdiff_t updated_to = to + ZV - BEGV - size_a; + signal_after_change (from, to - from, updated_to - from); + update_compositions (from, updated_to, CHECK_INSIDE); } return Qnil; |
