From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: phillip.lord@russet.org.uk (Phillip Lord) Newsgroups: gmane.emacs.bugs Subject: bug#23632: 25.1.50; Gratuitous undo boundary in latex-insert-block Date: Tue, 31 May 2016 22:42:36 +0100 Message-ID: <87wpm9q4z7.fsf@russet.org.uk> References: <87lh2vo7s6.fsf@gmail.com> <87shx23830.fsf@gmail.com> <87wpmcwn13.fsf@russet.org.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1464731405 25676 80.91.229.3 (31 May 2016 21:50:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 31 May 2016 21:50:05 +0000 (UTC) Cc: 23632@debbugs.gnu.org, Stefan Monnier To: Chong Yidong Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 31 23:49:53 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1b7rSc-00011F-4W for geb-bug-gnu-emacs@m.gmane.org; Tue, 31 May 2016 23:44:26 +0200 Original-Received: from localhost ([::1]:38573 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7rSa-0003FF-5y for geb-bug-gnu-emacs@m.gmane.org; Tue, 31 May 2016 17:44:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7rSH-00037X-Hv for bug-gnu-emacs@gnu.org; Tue, 31 May 2016 17:44:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b7rSE-0003MJ-O7 for bug-gnu-emacs@gnu.org; Tue, 31 May 2016 17:44:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7rSE-0003MC-KM for bug-gnu-emacs@gnu.org; Tue, 31 May 2016 17:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1b7rSE-0006mD-7b for bug-gnu-emacs@gnu.org; Tue, 31 May 2016 17:44:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: phillip.lord@russet.org.uk (Phillip Lord) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 31 May 2016 21:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23632 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 23632-submit@debbugs.gnu.org id=B23632.146473098225962 (code B ref 23632); Tue, 31 May 2016 21:44:02 +0000 Original-Received: (at 23632) by debbugs.gnu.org; 31 May 2016 21:43:02 +0000 Original-Received: from localhost ([127.0.0.1]:48813 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b7rRF-0006kc-Do for submit@debbugs.gnu.org; Tue, 31 May 2016 17:43:01 -0400 Original-Received: from cloud103.planethippo.com ([31.216.48.48]:46375) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b7rRC-0006kF-ND for 23632@debbugs.gnu.org; Tue, 31 May 2016 17:42:59 -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:References:Message-ID :Date:In-Reply-To:Subject:Cc:To:From; bh=gyamnXSomSjUndahX/N69ib2OFVkKYTA4MqaWUHNwAg=; b=PtOQdGvrjqhr/aAe0YH1KDr/F2 gTqVFbbXWtjZr6XMe+Ae1kKinHgcr687RyOcY0Ax6Ie46BV2SJcRjCgAAhC6AsOfyAcU5+F9Ik+jc vvymx2K5cnABPUrEfJXfjvzvaaz1l4N/Menedl4DV1bWllQ38x6nWjKMnL3lgzqVrQyMzNfMoF0If 9orNmYfMXA6+NuCbLM0gYhcLw1S6F0m6LHfYrO3Py9kOOCzyEOulJulT0hcMK9zVnel9Y0Idb1UJm bWeorOrN4F0KkFGMd1bMYsPe6Ogio4xXGGuOc8GrGulesjz7kd2jB8FG7dPaE3jaSdF9QdxT6cMFk gNmBlzQw==; Original-Received: from cpc1-benw10-2-0-cust373.gate.cable.virginm.net ([77.98.219.118]:36549 helo=russet.org.uk) by cloud103.planethippo.com with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.86_1) (envelope-from ) id 1b7rR6-004MEi-5R; Tue, 31 May 2016 22:42:52 +0100 In-Reply-To: <87wpmcwn13.fsf@russet.org.uk> (Phillip Lord's message of "Sun, 29 May 2016 22:51:36 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.94 (gnu/linux) 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 - debbugs.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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:118909 Archived-At: --=-=-= Content-Type: text/plain phillip.lord@russet.org.uk (Phillip Lord) writes: > Chong Yidong writes: > >>> The attached patch, which gets rid of the undo boundary, seems to fix >>> this: >> >> Actually, the previous patch does not DTRT: if you switch back to the >> original buffer from the minibuffer, and make further editing changes, >> those changes would get lost because buffer-undo-list is temporarily >> rebound. >> >> Here is a different patch, which works by removing the undo boundary in >> buffer-undo-list if there's one. It also tweaks HTML mode and Texinfo >> mode, which have similar issues. It defines a new function >> `undo-amalgamate', split off from `undo-auto-amalgamate', for >> convenience. > > > In and off itself, the patch seems fine, but my concern is that that the > previous heuristic did the right thing, the new heuristic does not. If > you've found three instances where it's causing a problem, then there > will be others also. > > I'm not 100% sure why the old system didn't insert an undo-boundary. > But, if we could solve this entirely in the undo system without changes > to client code that would be nicer. > > Not sure how yet -- need a few days to think about it. Perhaps, > suppressing the auto-boundary functionality when only the mini-buffer > has changed. I've debugged this now. The problem, I think, is that latex-insert-block uses recursive editing (via `completing-read', then `read-from-minibuffer') -- so the minibuffer is edited, then the exit-minibuffer command runs, causing an undo boundary to be added to minibuffer (correctly) but also to the latex buffer because it has also changed. The patch below seems to fix -- I need to test it out tomorrow in case it has any other unexpected effects. What worries me is that it just deals with the minibuffer. I wonder whether there are other circumstances where a recursive edit is going to break things. Stefan, would welcome your opinion here. Incidentally, this is a nightmare to debug. Emacs needs to be able to write to standard out, so I could log without changing any buffers! --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Stop-mini-buffer-causing-undo-boundaries.patch >From 9116e7f00f90fb14857d21698b1e6870fcf98bbd Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Mon, 30 May 2016 22:50:36 +0100 Subject: [PATCH] Stop mini-buffer causing undo boundaries * lisp/simple.el (undo-auto--boundaries): Check whether minibuffer is current, and if so limit undo-boundaries to it. Addresses #23632 --- lisp/simple.el | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index c5aa292..788cbb2 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2887,12 +2887,21 @@ undo-auto--boundaries "Check recently changed buffers and add a boundary if necessary. REASON describes the reason that the boundary is being added; see `undo-last-boundary' for more information." - (dolist (b undo-auto--undoably-changed-buffers) - (when (buffer-live-p b) - (with-current-buffer b - (unless undo-auto-disable-boundaries - (undo-auto--ensure-boundary cause))))) - (setq undo-auto--undoably-changed-buffers nil)) + ;; We treat the minibuffer specially, because some commands use the + ;; minibuffer after changing the buffer that they are launched + ;; from. Changes in the minibuffer force an undo-boundary in the + ;; launched buffer without this handling. (see bug #23632) + (if (minibufferp) + (progn + (undo-auto--ensure-boundary cause) + (setq undo-auto--undoably-changed-buffers + (delq (current-buffer) undo-auto--undoably-changed-buffers))) + (dolist (b undo-auto--undoably-changed-buffers) + (when (buffer-live-p b) + (with-current-buffer b + (unless undo-auto-disable-boundaries + (undo-auto--ensure-boundary cause))))) + (setq undo-auto--undoably-changed-buffers nil))) (defun undo-auto--boundary-timer () "Timer which will run `undo--auto-boundary-timer'." -- 2.8.3 --=-=-=--