From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: phillip.lord@russet.org.uk (Phillip Lord) Newsgroups: gmane.emacs.devel Subject: Re: Unbalanced change hooks (part 2) Date: Wed, 31 Aug 2016 12:00:37 +0100 Message-ID: <8760qh6w4q.fsf@russet.org.uk> References: <20160731121642.GB2205@acm.fritz.box> <83a8gxq288.fsf@gnu.org> <87h9ag3j8c.fsf@russet.org.uk> <87pooqcolw.fsf@russet.org.uk> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1472641268 21809 195.159.176.226 (31 Aug 2016 11:01:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 31 Aug 2016 11:01:08 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 31 13:01:01 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bf3GM-0004by-6t for ged-emacs-devel@m.gmane.org; Wed, 31 Aug 2016 13:00:58 +0200 Original-Received: from localhost ([::1]:53483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bf3GJ-0003qA-Vf for ged-emacs-devel@m.gmane.org; Wed, 31 Aug 2016 07:00:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bf3GE-0003q1-6O for emacs-devel@gnu.org; Wed, 31 Aug 2016 07:00:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bf3GA-0005qI-1G for emacs-devel@gnu.org; Wed, 31 Aug 2016 07:00:49 -0400 Original-Received: from cloud103.planethippo.com ([31.216.48.48]:55456) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bf3G9-0005q9-LT for emacs-devel@gnu.org; Wed, 31 Aug 2016 07:00:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=russet.org.uk; s=default; h=Content-Type:MIME-Version:Message-ID: In-Reply-To:Date:References:Subject:Cc:To:From; bh=I9ardiHs+391kKbGPKSuUhPXAaR8ZSMnBmctJgS+FNc=; b=sfOpJ/4Ww4wMbVBATISBjdKBOY RsAUQXt8ZQzNqvi7axt/2IZRqQOWVAPtpQk78S+boQDUNbw2j4vILGB99uPV6WjQvmjkPH9YbY2ZM 96gojlh4PYlfifsHCPbkjDM0u5E7QDZjJN8ltyOcjWXn9O+UYCgxCH/DN7kjbEJugiZQx+DB0ADnX H6TcmyIp6ZzsX183Iz8BfMe1G37qXSymaZb+fd1KtEQHqFsnyWneGwdtV76pKEMFg6K2/1kYYaKOu 58IYP10WnyxxVAK/j3m57nFIevkHuYqyLKHyvnVr4A8xM3LTabo7RF4CmYd/NSveAlfGCIR6qfFFa JEiIAnxg==; Original-Received: from janus-nat-128-240-225-60.ncl.ac.uk ([128.240.225.60]:39769 helo=russet.org.uk) by cloud103.planethippo.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_1) (envelope-from ) id 1bf3G7-000p0l-6v; Wed, 31 Aug 2016 12:00:43 +0100 In-Reply-To: (Stefan Monnier's message of "Tue, 30 Aug 2016 11:11:56 -0400") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cloud103.planethippo.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - russet.org.uk X-Get-Message-Sender-Via: cloud103.planethippo.com: authenticated_id: phillip.lord@russet.org.uk X-Authenticated-Sender: cloud103.planethippo.com: phillip.lord@russet.org.uk X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 31.216.48.48 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:207016 Archived-At: Stefan Monnier writes: >>> But it can admittedly be cumbersome since the old-text is now in a string >>> rather than being inside the buffer. >> Because, I am not using the before and after positions just to recognise >> the string that has changed. > > I was not suggesting to use those position to recognize the string: > I was suggesting to use the suggested code to get the old-string so that > you can then do what you need on the "before change" state. > >> I am have to calculate the equivalent positions in the other "lentic" >> buffer; and this can only be done before the change, since the two >> buffers are them in a consistent state. Oh dear, my English seems to be terrible in this paragraph. > > The idea is that my suggested code gives you the needed info. > More specifically, the other buffer is (well, should be) in a state > consistent with "the current buffer where start..end is replaced (back) > with `old-text'". I think it does not, I am afraid, because the "end" position of b-c-f is not reliably correct. Consider this buffer: One Two which is converted into this buffer ;; One ;; Two To calulate that the "T" are cognate locations, I count the number of lines, and then count backward from the end of the line. This works, so long as the buffers are also cognate. Now, say we have a deletion in buffer one starting at pos 3 ("e") to pos 5 ("T"). Pos 3 is fine -- it's equivalent to pos 6 in the commented buffer. But pos 5 is difficult. I have to calculate it's cognate position before the deletion, since the number of lines change. Which is what I do. All of this breaks if the end location on b-c-f is wrong wrt to a-c-f. Counting the number of lines does not work on a-c-f because the uncommented buffer has already changed. > So that should give you the info needed to update things without doing > a "complete flush". As mentioned, it may be inconvenient to use it > (depending on details of how the rest of the code is implemented) since > the old-text is now in a string rather than being right there in > the buffer. > >>> Note that in the subst-char-in-region you could "make it pairup" >>> yourself by hand: if you have (< (+ start length) (cdr lentic--b-c-pos)), >>> then you can just >>> >>> (let ((diff (- (cdr lentic--b-c-pos) (+ start length)))) >>> (cl-incf length diff) >>> (cl-incf end diff)) >>> >>> such that (eq (+ start length) (cdr lentic--b-c-pos)). >> So, this works because subst-char-in-region is guaranteed not to change >> the size of the region right? > > No. It works because a-c-f's arguments say "nothing was changed before > START and after END", so it's always safe (conservative) to move START > towards BOB or move END towards EOB (of course, when updating END you > also need to update LENGTH correspondingly). Ah, yes. But, unfortunately, I cannot calculate the location of the END position in the cognate buffer. If subst-char-in-region did just what you are suggesting I do (i.e. signally the maximal extent on a-c-f, as it does on b-c-f), then there would be no problem. I would love to change subst-char-in-region to achieve this. Making a-c-f signal the maximal extent is the trivial change; the alternative of having b-c-f know the real extent of the change is harder, but also could be done. Phil