emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Request for Mentor] subst-char-in-region


From: Stefan Monnier
Subject: Re: [Request for Mentor] subst-char-in-region
Date: Fri, 12 Dec 2014 11:17:22 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

>>> before(1,8)
>>> after(1,4,3)
>> That looks correct to me.
> Why? The doc says "the positions of the beginning and end of the old
> text to be changed" for before-change-function. But the text from 4 to 8
> is not changed. As indeed the after-change-functions value says.

Similarly if your subst-char-in-region changes "oaaao" to "xaaax" the
aaa part isn't changed, so you could argue that we should call b-c-f and
a-c-f twice (once per "o->x" change).  But instead we call them on
a "superset" of the actually changed text.  A tighter superset is
preferable, all other things being equal, but making a single call
rather than many "smaller" calls also is preferable.

> Given that the change in this case is a substution why is it not:
> before(1,4)
> after (1,4,3)
> This could be calculated, of course, by subst-char-in-region, although
> it would potentially require scanning the region twice (once to find
> start and stop, once to actually make changes).

Exactly, it doesn't seem worth scanning the region twice just to give
a slightly tighter bound to the b-c-f.

> At the moment, yes, it does.  I am keeping two buffers in sync by
> transfering changes between them. It does this by removing the text in
> "that buffer" between the before change values and replacing it with the
> text in "this buffer" (it's slightly more complex than this, but that's
> the basic idea).

Why do it this way?  Why not rely exclusively on the a-c-f?

Try your code on a diff-mode buffer using commands such as
diff-unified->context or diff-context->unified (hint, they use
combine-after-change-calls).

> In general, I have found that this works.

I think you mean "usually" rather than "in general".


        Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]