From: Chong Yidong <cyd@stupidchicken.com>
To: rms@gnu.org
Cc: emacs-devel@gnu.org
Subject: Re: [n_schumacher@web.de: modification hooks called only once in c-mode]
Date: Fri, 10 Aug 2007 20:46:37 -0400 [thread overview]
Message-ID: <874pj6j3te.fsf@stupidchicken.com> (raw)
In-Reply-To: <E1IIdZx-00046A-9G@fencepost.gnu.org> (Richard Stallman's message of "Wed\, 08 Aug 2007 00\:55\:29 -0400")
Richard Stallman <rms@gnu.org> writes:
> Would someone please DTRT, then ack?
> If the fix is simple enough, it should be installed in Emacs 22.
> ....
>
> (defun test-bug-hook (overlay afterp beg end &optional r)
> (message "%s hook called" (if afterp "after" "before")))
>
> (defun test-bug ()
> (let ((beg (point))
> ov)
> (insert "foobar")
> (setq ov (make-overlay beg (point)))
> (overlay-put ov 'face 'highlight)
> (overlay-put ov 'insert-in-front-hooks '(test-bug-hook))))
>
> 1) Create a new buffer in c-mode, evaluate (test-bug), and insert a char
> before the overlay.
>
> Result:
> before hook called
>
> The hook is never called after the change.
The problem is in report_overlay_modification in buffer.c. This
function, which is called both before and after a modification,
compiles a list of modification-hooks to run and executes them. When
called before modification, it first does
last_overlay_modification_hooks_used = 0;
to reset the list of modification hooks to run.
The bug arises when you have an after-change hook that does buffer
changes (in this case, this is c-after-change, which calls
c-invalidate-sws-region-after). The sequence of events is:
1. User issues command to modify the buffer.
2. Before the change is applied, report_overlay_modification is
called. It resets last_overlay_modification_hooks_used to zero,
then compiles a list of hooks to run. This includes both the
insert-in-front hook and the after-change hook.
3. The insert-in-front hook runs.
4. The buffer modification is applies.
5. The after-change hook runs, modifying the buffer elsewhere.
6. This results in report_overlay_modification being called, which
resets last_overlay_modification_hooks_used to zero. The
insert-in-front hook, which was scheduled to run next, gets rubbed
out.
One simple fix is to bind inhibit-modification-hooks in
c-after-change.
A deeper fix would be to make report_overlay_modification check if it
is being called in a modification hook, and take steps to prevent
scheduled hooks from being rubbed out. I'm not sure this behavior is
significantly more "correct" than the existing one, however; it may be
better to leave it as is.
In either case, I'd suggest not putting the fix for this in Emacs
22.2. The first fix can cause subtle problems since c-after-change is
a core part of cc-mode, and the second one is also somewhat delicate.
It can go in the trunk, and be merged into the branch for 22.3 if no
problems are found.
next prev parent reply other threads:[~2007-08-11 0:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-08 4:55 [n_schumacher@web.de: modification hooks called only once in c-mode] Richard Stallman
2007-08-11 0:46 ` Chong Yidong [this message]
2007-08-12 4:14 ` Richard Stallman
2007-08-12 5:50 ` Stefan Monnier
2007-08-13 0:52 ` Richard Stallman
2007-08-13 4:10 ` Stefan Monnier
2007-08-13 5:59 ` David Kastrup
2007-08-16 20:46 ` Stefan Monnier
2007-08-13 9:40 ` martin rudalics
2007-08-13 14:01 ` Stefan Monnier
-- strict thread matches above, loose matches on Subject: below --
2007-07-31 20:22 Richard Stallman
2007-07-24 22:17 Richard Stallman
2007-08-01 9:16 ` Johan Bockgård
2007-08-02 15:45 ` Richard Stallman
2007-07-17 15:06 Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874pj6j3te.fsf@stupidchicken.com \
--to=cyd@stupidchicken.com \
--cc=emacs-devel@gnu.org \
--cc=rms@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.