unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10117: duplicate evaluation of after-change-functions hooks in revert-buffer
@ 2011-11-23 11:18 Tiphaine Turpin
  2011-11-23 14:42 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Tiphaine Turpin @ 2011-11-23 11:18 UTC (permalink / raw)
  To: 10117

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






^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#10117: duplicate evaluation of after-change-functions hooks in revert-buffer
  2011-11-23 11:18 bug#10117: duplicate evaluation of after-change-functions hooks in revert-buffer Tiphaine Turpin
@ 2011-11-23 14:42 ` Stefan Monnier
       [not found]   ` <4ECD0A5D.90907@inria.fr>
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2011-11-23 14:42 UTC (permalink / raw)
  To: Tiphaine Turpin; +Cc: 10117

> 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 ?

Well, it should be, yes.

> What could possibly cause such a duplicate event ?

A bug in revert-buffer?  revert-buffer modifies the buffer on its own
rather than via calls to delete and insert, so it runs those
change-functions "by hand".  Do you have a small test case reproducing
the problem?


        Stefan





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#10117: duplicate evaluation of after-change-functions hooks in revert-buffer
       [not found]   ` <4ECD0A5D.90907@inria.fr>
@ 2011-12-01 20:23     ` Stefan Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2011-12-01 20:23 UTC (permalink / raw)
  To: Tiphaine Turpin; +Cc: 10117-done

>> 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)
     {






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-12-01 20:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-23 11:18 bug#10117: duplicate evaluation of after-change-functions hooks in revert-buffer Tiphaine Turpin
2011-11-23 14:42 ` Stefan Monnier
     [not found]   ` <4ECD0A5D.90907@inria.fr>
2011-12-01 20:23     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).