From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [Request for Mentor] subst-char-in-region Date: Fri, 12 Dec 2014 11:17:22 -0500 Message-ID: References: <87r3w5jdow.fsf@newcastle.ac.uk> <87bnn8j4c9.fsf@newcastle.ac.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1418401071 27692 80.91.229.3 (12 Dec 2014 16:17:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Dec 2014 16:17:51 +0000 (UTC) Cc: emacs-devel@gnu.org To: phillip.lord@newcastle.ac.uk (Phillip Lord) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 12 17:17:43 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XzSuU-0005xI-JK for ged-emacs-devel@m.gmane.org; Fri, 12 Dec 2014 17:17:42 +0100 Original-Received: from localhost ([::1]:58105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzSuU-0002RT-4s for ged-emacs-devel@m.gmane.org; Fri, 12 Dec 2014 11:17:42 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzSuJ-0002QZ-EF for emacs-devel@gnu.org; Fri, 12 Dec 2014 11:17:38 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzSuB-0000rD-VC for emacs-devel@gnu.org; Fri, 12 Dec 2014 11:17:31 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:30470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzSuB-0000r5-RA for emacs-devel@gnu.org; Fri, 12 Dec 2014 11:17:23 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwPAOwQflTO+ILA/2dsb2JhbABbDoJ5g2CFWsUdBAICgSQXAQEBAQEBfIQDAQEDAScvIwULCzQSFBgNLohACdZZAQEBAQYBAQEBHpBvB4RIBYsBkjGPc4IKgXiDO14hgncBAQE X-IPAS-Result: AjwPAOwQflTO+ILA/2dsb2JhbABbDoJ5g2CFWsUdBAICgSQXAQEBAQEBfIQDAQEDAScvIwULCzQSFBgNLohACdZZAQEBAQYBAQEBHpBvB4RIBYsBkjGPc4IKgXiDO14hgncBAQE X-IronPort-AV: E=Sophos;i="5.07,502,1413259200"; d="scan'208";a="100290266" Original-Received: from 206-248-130-192.dsl.teksavvy.com (HELO pastel.home) ([206.248.130.192]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 12 Dec 2014 11:17:23 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id ED1C02F23; Fri, 12 Dec 2014 11:17:22 -0500 (EST) In-Reply-To: <87bnn8j4c9.fsf@newcastle.ac.uk> (Phillip Lord's message of "Fri, 12 Dec 2014 15:05:42 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:179933 Archived-At: >>> 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