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: Tue, 30 Aug 2016 15:34:19 +0100 Message-ID: <87pooqcolw.fsf@russet.org.uk> References: <20160731121642.GB2205@acm.fritz.box> <83a8gxq288.fsf@gnu.org> <87h9ag3j8c.fsf@russet.org.uk> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1472567723 21685 195.159.176.226 (30 Aug 2016 14:35:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 30 Aug 2016 14:35:23 +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 Tue Aug 30 16:35:08 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 1bek82-0004DD-W0 for ged-emacs-devel@m.gmane.org; Tue, 30 Aug 2016 16:35:07 +0200 Original-Received: from localhost ([::1]:49450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bek80-0001cy-LZ for ged-emacs-devel@m.gmane.org; Tue, 30 Aug 2016 10:35:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bek7Q-0001cf-2q for emacs-devel@gnu.org; Tue, 30 Aug 2016 10:34:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bek7J-0003GZ-Um for emacs-devel@gnu.org; Tue, 30 Aug 2016 10:34:26 -0400 Original-Received: from cloud103.planethippo.com ([31.216.48.48]:45901) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bek7J-0003GM-Hb for emacs-devel@gnu.org; Tue, 30 Aug 2016 10:34:21 -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=fJSCKR5h/KO/eZzID6DMdwcDajzW6p+KDXrJWjP0Ais=; b=tAGzMjb3WZMoNgmIQpp27HCP55 Ev6b6Np5w3spAp94QfHg6HWgRBpKvrHsmYpPQIxW5g/10+xylyrCOwrSvafTSIpBRmFd/N3UScHO5 eBCAIkDy4sty3SGCHdnbVy8GphbyP20iZmNOJ5XR4AwFqpojKmnt4kk9FIrnF6RkxR0A6yObdoijM FevPWYwMQegkb+krvn7cNYnyRsYe6fZnjXTyyZ0M0V/KdQ3er1iWHikpOEOsW/IMJ66vaTMKJoy6Z uUqFukBYISTRkmZXWJeCpC8NUs9I4+wdgYcdAjk2V61pFhdNSMpaiV3yeMzCLhc9LBf2w3mNNP6eo A03mZpkQ==; Original-Received: from janus-nat-128-240-225-60.ncl.ac.uk ([128.240.225.60]:44866 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 1bek7I-001i0N-8F; Tue, 30 Aug 2016 15:34:20 +0100 In-Reply-To: (Stefan Monnier's message of "Mon, 29 Aug 2016 21:15:52 -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:206935 Archived-At: Stefan Monnier writes: >> (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)))) > > I don't understand what this is doing. That's a shame. I don't understand what it is doing either, and I was hoping that you might do. > It seems to be looking for indirect clues rather than checking > directly for the properties on which the code relies. Perhaps. At the moment, the only thing function that I know definately causes me problems is subst-char-in-region. > Why not do something like: > > (defun lentic--b-c-f (start end) > (setq-local lentic--b-c-pos (cons start end)) > ...) > > (defun lentic--a-c-f (start end length) > (if (prog1 (not (and (eq start (car lentic--b-c-pos)) > (eq (+ start length) (cdr lentic--b-c-pos)))) > (setq lentic--b-c-pos nil)) > ;; This a-c-f is not properly paired with the previous b-c-f. > > ;; Proper pairing > )) I will try and test this to see. > If the performance issue is serious enough, you can of course try to "do > it right" with something like: > > (defun lentic--b-c-f (start end) > (setq-local lentic--b-c-data > (cons start (buffer-substring start end))) > ...) > > (defun lentic--a-c-f (start end length) > ;; Get the before-change content of start..end. > (let ((old-text (substring (cdr lentic--b-c-data) > (- start (car lentic--b-c-data)) > (- end length (car lentic--b-c-data))))) > ;; Update lentic--b-c-data for possible subsequent other a-c-f calls. > (setcdr lentic--b-c-data > (concat (substring (cdr lentic--b-c-data) > 0 (- start (car lentic--b-c-data))) > (buffer-substring start end) > (substring (cdr lentic--b-c-data) > (- end length (car lentic--b-c-data))))) > )) > > 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 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. In the case that they are skewed, I have to throw all my knowledge away, since the converted positions are not unreliable. So I copy the whole buffer, and apply the general (unoptimized) transformation. >> 1) being able to know when b-c-f and a-c-f are not paired or consistent >> would be useful > > Does the above lentic--b-c-pos give the needed info? > >> 2) decreasing the number of times these occurs would be useful, even if >> it cannot be removed entirely. > > 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? But, how do I know that subst-char-in-region has been called? I discovered this problem first, when fill-paragraph broke lentic. It just so happens that subst-char-in-region was the culprit; it wasn't the command though. Phil