From: Stefan Monnier <monnier@iro.umontreal.ca>
To: phillip.lord@newcastle.ac.uk (Phillip Lord)
Cc: emacs-devel@gnu.org
Subject: Re: [Request for Mentor] subst-char-in-region
Date: Fri, 12 Dec 2014 11:17:22 -0500 [thread overview]
Message-ID: <jwvk31wua18.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87bnn8j4c9.fsf@newcastle.ac.uk> (Phillip Lord's message of "Fri, 12 Dec 2014 15:05:42 +0000")
>>> 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
next prev parent reply other threads:[~2014-12-12 16:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-12 11:43 [Request for Mentor] subst-char-in-region Phillip Lord
2014-12-12 14:35 ` Stefan Monnier
2014-12-12 15:05 ` Phillip Lord
2014-12-12 16:17 ` Stefan Monnier [this message]
2014-12-15 12:15 ` Phillip Lord
2014-12-15 14:29 ` Stefan Monnier
2014-12-16 11:30 ` Phillip Lord
2014-12-16 14:07 ` Stefan Monnier
2014-12-16 16:05 ` Phillip Lord
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=jwvk31wua18.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=phillip.lord@newcastle.ac.uk \
/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.