From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Markus Triska Newsgroups: gmane.emacs.bugs Subject: bug#23906: 25.0.95; Undo boundary after process output is not consistent Date: Mon, 18 Jul 2016 21:03:14 +0200 Message-ID: <877fci93bh.fsf@metalevel.at> References: <83r3b6lih2.fsf@gnu.org> <87h9bw5rfd.fsf@russet.org.uk> <87eg70i8k5.fsf@metalevel.at> <87d1mikef5.fsf@russet.org.uk> <874m7usn1m.fsf@metalevel.at> <8760sao9im.fsf@metalevel.at> <87mvllyypo.fsf@russet.org.uk> <87zipkzkge.fsf@metalevel.at> <87shvcfiox.fsf@russet.org.uk> <87shvccl2h.fsf@metalevel.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1468868874 3315 80.91.229.3 (18 Jul 2016 19:07:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 Jul 2016 19:07:54 +0000 (UTC) Cc: Phillip Lord , 23906@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jul 18 21:07:45 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 1bPDtI-0004bp-Sw for geb-bug-gnu-emacs@m.gmane.org; Mon, 18 Jul 2016 21:07:45 +0200 Original-Received: from localhost ([::1]:49839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPDtI-0002Nr-4H for geb-bug-gnu-emacs@m.gmane.org; Mon, 18 Jul 2016 15:07:44 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPDpo-0007nu-AG for bug-gnu-emacs@gnu.org; Mon, 18 Jul 2016 15:04:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPDpi-0003S0-FG for bug-gnu-emacs@gnu.org; Mon, 18 Jul 2016 15:04:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43670) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPDpi-0003Rw-Br for bug-gnu-emacs@gnu.org; Mon, 18 Jul 2016 15:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bPDph-00068N-Vl for bug-gnu-emacs@gnu.org; Mon, 18 Jul 2016 15:04:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Markus Triska Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Jul 2016 19:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23906 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 23906-submit@debbugs.gnu.org id=B23906.146886859823525 (code B ref 23906); Mon, 18 Jul 2016 19:04:01 +0000 Original-Received: (at 23906) by debbugs.gnu.org; 18 Jul 2016 19:03:18 +0000 Original-Received: from localhost ([127.0.0.1]:56007 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPDoz-00067N-N2 for submit@debbugs.gnu.org; Mon, 18 Jul 2016 15:03:17 -0400 Original-Received: from metalevel.at ([78.46.218.83]:42888) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPDox-00067E-Ll for 23906@debbugs.gnu.org; Mon, 18 Jul 2016 15:03:16 -0400 Original-Received: by metalevel.at (Postfix, from userid 1000) id 57AA1A0379; Mon, 18 Jul 2016 21:03:14 +0200 (CEST) In-Reply-To: (Stefan Monnier's message of "Mon, 18 Jul 2016 00:18:36 -0400") User-Agent: Emacs/24.4 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:121233 Archived-At: Stefan Monnier writes: > How 'bout the patch below (see the viper part to get an idea about how > to use it in ediprolog)? It's pretty awesome, thank you! I have added it to ediprolog.el with the patch below, please let me know if you have any comments. I like particularly that your functions work together in a pure way: It's OK if the handle is simply *not* used. At least I *think* that is the case, i.e., prepare-change-group does not alter the undo list or any other global state. I am particularly interested in this case because in ediprolog, the following situation may arise: 1) a query is started with M-x ediprolog-dwim RET 2) interaction with Prolog takes place 3) critically, user presses C-g to exit the interaction (!) 4) user makes (unrelated) changes elsewhere in the buffer 5) user re-enters the interaction with M-x ediprolog-toplevel RET 7) interaction resumes 8) after a few more answers, interaction finishes 9) C-/ (user presses undo) To see what I mean, please try M-x ediprolog-dwim RET on the following query, and press SPACE twice: ?- between(1, 3, X). %@ X = 1 ; %@ X = 2 at this state, press C-g to exit the interaction, and (optionally) make other changes in the buffer. Then do M-x ediprolog-toplevel RET to resume interaction, and press SPACE once more. In total, you obtain: ?- between(1, 3, X). %@ X = 1 ; %@ X = 2 ; %@ X = 3. Ideally, if you then press C-/, the *whole* interaction would be undone, and I may find a good way to do this. However, in its current state (with the patch below), such interrupted and resumed interactions still result in undo boundaries, which is also acceptable. Thus, with the primitives you provide, the case I care most about, namely a single continuous interaction, now works exactly as expected on undo (it is undone as a unit on), and interruptions work acceptably well. Therefore, thank you very much for this! One thing I noticed in the interaction above is that point is sometimes at a very unexpected position after undo, in particular if the buffer contents are modified after the query is interrupted. I will file a separate issue for this. And a question: Is there any reason not to write viper-adjust-undo as: (defun viper-adjust-undo () (when viper--undo-change-group-handle (undo-amalgamate-change-group viper--undo-change-group-handle) (setq viper--undo-change-group-handle nil))) The patch to ediprolog.el follows. Thank you and all the best! Markus diff --git a/ediprolog.el b/ediprolog.el index ee89095..408284b 100644 --- a/ediprolog.el +++ b/ediprolog.el @@ -347,11 +347,13 @@ arguments, equivalent to `ediprolog-remove-interactions'." (error "Missing `.' at the end of this query"))) (query (buffer-substring-no-properties from to))) (end-of-line) - (insert "\n" ediprolog-indent-prefix ediprolog-prefix) - (ediprolog-interact - (format "%s\n" (mapconcat #'identity - ;; `%' can precede each query line - (split-string query "\n[ \t%]*") " ")))) + (let ((handle (prepare-change-group))) + (insert "\n" ediprolog-indent-prefix ediprolog-prefix) + (ediprolog-interact + (format "%s\n" (mapconcat #'identity + ;; `%' can precede each query line + (split-string query "\n[ \t%]*") " "))) + (undo-amalgamate-change-group handle))) t)) ;;;###autoload