--- Begin Message ---
Subject: |
duplicate evaluation of after-change-functions hooks in revert-buffer |
Date: |
Wed, 23 Nov 2011 12:18:15 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 |
Hi,
I'm having a strange behavior while trying to track the modifications to
a buffer: calling revert-buffer triggers the following calls to my
after-change-functions hook
- a region deletion (which is exactly the changed region between the
buffer and the file)
- a region insertion (the new contents for the changed region)
- the same insertion again.
I don't care about how many modifications the reverting is splited into,
or whether these are minimal or all the buffer contents is considered
new, but the duplicate insertion leads me into invalid assumptions about
the new contents (I use this to maintain a exact mapping of the buffer
into an external tool).
Am I wrong when I assume that the sequence of modifications passed to
the after-change-functions is an exact trace of the buffer contents
evolution ? What could possibly cause such a duplicate event ?
Note: I'm not doing anything strange in the hook like changing the
buffers' contents. This is just a numeric computation which update some
buffer-local variables which track the set of "unprocessed"
modifications. The hook is added as buffer-local (and global value of
after-change-functions is nil).
Regards,
Tiphaine Turpin
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#10117: duplicate evaluation of after-change-functions hooks in revert-buffer |
Date: |
Thu, 01 Dec 2011 15:23:29 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (gnu/linux) |
>> change-functions "by hand". Do you have a small test case reproducing
>> the problem?
> Here is an example:
> First open the attached file in Emacs and evaluate it. Then:
> echo ';Hi!' >>revert-bug.el
> The *Messages* buffer shows the following:
> modify [175, 180[ (old-len=0) [2 times]
Indeed, I see that too. I've installed the patch below which should
fix it. Thanks for the simple test case.
Stefan
=== modified file 'src/fileio.c'
--- src/fileio.c 2011-11-26 21:40:41 +0000
+++ src/fileio.c 2011-12-01 20:14:53 +0000
@@ -4100,6 +4100,16 @@
adjust_after_insert (PT, PT_BYTE, PT + inserted, PT_BYTE + inserted,
inserted);
+ /* Call after-change hooks for the inserted text, aside from the case
+ of normal visiting (not with REPLACE), which is done in a new buffer
+ "before" the buffer is changed. */
+ if (inserted > 0 && total > 0
+ && (NILP (visit) || !NILP (replace)))
+ {
+ signal_after_change (PT, 0, inserted);
+ update_compositions (PT, PT, CHECK_BORDER);
+ }
+
/* Now INSERTED is measured in characters. */
handled:
@@ -4270,16 +4280,6 @@
unbind_to (count1, Qnil);
}
- /* Call after-change hooks for the inserted text, aside from the case
- of normal visiting (not with REPLACE), which is done in a new buffer
- "before" the buffer is changed. */
- if (inserted > 0 && total > 0
- && (NILP (visit) || !NILP (replace)))
- {
- signal_after_change (PT, 0, inserted);
- update_compositions (PT, PT, CHECK_BORDER);
- }
-
if (!NILP (visit)
&& current_buffer->modtime == -1)
{
--- End Message ---