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: Fri, 19 Aug 2016 15:51:15 +0100 Message-ID: <87h9ag3j8c.fsf@russet.org.uk> References: <20160731121642.GB2205@acm.fritz.box> <83a8gxq288.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1471618306 20858 195.159.176.226 (19 Aug 2016 14:51:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 19 Aug 2016 14:51:46 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: ofv@wanadoo.es, Alan Mackenzie , rcopley@gmail.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 19 16:51:41 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 1bal91-00054K-Uj for ged-emacs-devel@m.gmane.org; Fri, 19 Aug 2016 16:51:40 +0200 Original-Received: from localhost ([::1]:57630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bal8z-0005BE-5t for ged-emacs-devel@m.gmane.org; Fri, 19 Aug 2016 10:51:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bal8m-00059K-9d for emacs-devel@gnu.org; Fri, 19 Aug 2016 10:51:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bal8l-0005n1-5D for emacs-devel@gnu.org; Fri, 19 Aug 2016 10:51:24 -0400 Original-Received: from cloud103.planethippo.com ([31.216.48.48]:53884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bal8g-0005l6-BX; Fri, 19 Aug 2016 10:51:18 -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=HGml4WbESKuPo8TnTls+q9vve28qRsFtvTtkouo/7WY=; b=gmMBMO3HFNkSTvvD33M2/iD5v+ qJMR0pGJBUSYMIw8M04kHX+muxPA60K+C7WwBiu7ywQkl1gIWC2G+Br0h/d95sYdyaAhdXJAaeyKc LgnQFKzyP1CnqQK3zRcSAVONnemtetbZPtAqOkGs3kOd5HxMJzgj9DJbp1oN3nrtckE4l6F3B0/rt ZYdf5K0IfqxMG9Ay3DYsMKP1dlIqqVIr4nwOU7wze5Vv+5ayihj+REzEBVnEa3aqDn0LSiy72fBge IdgTgekIb/PPZ3NkfqXiIbwu8UNv2uZETapNJz7MHx2CfdocTY2DmxNsctQl2JY+KjgctsdUHjQen ZkmvXbCg==; Original-Received: from janus-nat-128-240-225-60.ncl.ac.uk ([128.240.225.60]:53817 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 1bal8f-003wJY-2E; Fri, 19 Aug 2016 15:51:17 +0100 In-Reply-To: <83a8gxq288.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 31 Jul 2016 18:03:19 +0300") 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:206675 Archived-At: Eli Zaretskii writes: > My interpretation of these two variables is that they are two hooks > provided for different kinds of features, because hooking into both > should not generally be required. It should suffice for an > application that wants to react to a change in a buffer to hook into > after-change-functions only. My apologies for jumping into the discussion so late, but I have been travelling. I make use of both b-c-f and a-c-f in my package called lentic. This percolates changes in one buffer into another which is related but may not be indentical to the first. To enable this, I have to be able to convert between cognate positions in the two buffers; that is the positions which are equivalent in the two buffers. But I have to do this BEFORE the changes occur, because at this point the two buffers are in a consistent state. This is not true after the change has happened in one buffer and before it has been percolated to the next. Having b-c-f and a-c-f paired is not essential for this, but is (or would be) greately helpful. It would also be good if the values passed to b-c-f and a-c-f were consistent. Unfortunately this is not true either (subst-char-in-region at least is guilty here, passing different "end" positions in b-c-f and a-c-f). I use the following logic to detect when b-c-f and a-c-f are "skewed" -- that is inconsistent with each other. "start" and "stop" are the parameters of a-c-f and "length-before" is the value of the length parameter of b-c-f called immediately before a-c-f. (or ;; previously this was not skewed if no region, but actually, ;; if there is no region we need to copy everything, we can ;; also do by declaring skew -- this is important for the ;; multi-lentic situation (not (or start stop length-before)) ;; skews only occur in insertions which result in a positive ;; length-before. This also picks up no-insertion changes (and (< 0 length-before) ;; = start stop means we have a deletion because ;; there is no range after. Deletions seem to be ;; safe. (not (= start stop)))) This seems to work for me, but it's guess work. I do not understand quite why it works, and there are (undoubtly) some cases where it does not. I realise that there may be practical difficulties in making the two hooks consistent, although I think that this would be a laudable aim. But failing this, it would be at least nice to know when the hooks are not consistent; either in documentation, or better as a parameter, so I could stop guessing. The implications for lentic are significant; even though I can generally avoid issues with the code above, the assumption that the whole buffer is dirty generates a large amount of undo information. Fortuantely, it happens only rarely, or this would simply prevent my approach from working. Which leads me to two conclusions: 1) being able to know when b-c-f and a-c-f are not paired or consistent would be useful 2) decreasing the number of times these occurs would be useful, even if it cannot be removed entirely. Phil