From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#22295: viper-mode undo bug introduced between Nov 10 and Nov 14 Date: Fri, 10 Jun 2016 13:05:22 -0400 Message-ID: References: <83vb2h6lfq.fsf@gnu.org> <83r3d56jrg.fsf@gnu.org> <87poso7nf5.fsf@russet.org.uk> <878tzatbte.fsf@russet.org.uk> <877fe85z1e.fsf@russet.org.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1465578414 3529 80.91.229.3 (10 Jun 2016 17:06:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 Jun 2016 17:06:54 +0000 (UTC) Cc: 22295@debbugs.gnu.org, Jim Meyering , Michael Kifer To: phillip.lord@russet.org.uk (Phillip Lord) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jun 10 19:06:40 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 1bBPsx-00071D-P3 for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Jun 2016 19:06:19 +0200 Original-Received: from localhost ([::1]:43514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBPsx-0007w9-36 for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Jun 2016 13:06:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBPsk-0007t8-Q1 for bug-gnu-emacs@gnu.org; Fri, 10 Jun 2016 13:06:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bBPsg-00011S-SU for bug-gnu-emacs@gnu.org; Fri, 10 Jun 2016 13:06:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52090) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBPsg-00011O-PB for bug-gnu-emacs@gnu.org; Fri, 10 Jun 2016 13:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bBPsg-0005qs-HU for bug-gnu-emacs@gnu.org; Fri, 10 Jun 2016 13:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Jun 2016 17:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22295 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22295-submit@debbugs.gnu.org id=B22295.146557832722442 (code B ref 22295); Fri, 10 Jun 2016 17:06:02 +0000 Original-Received: (at 22295) by debbugs.gnu.org; 10 Jun 2016 17:05:27 +0000 Original-Received: from localhost ([127.0.0.1]:36193 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bBPs6-0005pt-Um for submit@debbugs.gnu.org; Fri, 10 Jun 2016 13:05:27 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:36535) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bBPs5-0005pl-53 for 22295@debbugs.gnu.org; Fri, 10 Jun 2016 13:05:25 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id u5AH5MDb011351; Fri, 10 Jun 2016 13:05:22 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 4A8C8602E9; Fri, 10 Jun 2016 13:05:22 -0400 (EDT) In-Reply-To: <877fe85z1e.fsf@russet.org.uk> (Phillip Lord's message of "Wed, 01 Jun 2016 23:23:25 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV5702=0 X-NAI-Spam-Version: 2.3.0.9418 : core <5702> : inlines <4918> : streams <1649780> : uri <2227947> 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:119387 Archived-At: >> The old code seemed "simple" enough that the problem was probably >> simple to fix (once identified). > Well, most problems are simple to fix once you actually know what they > are. The problem seems to be the following: when you hit ESC, Viper will remove boundaries from the undo-list, without making any changes to the buffer, so the top-level loop won't add a boundary before the next command and ends up hence "amalgamating" the next command with the previous one. In the old code, we just always blindly added a boundary to current-buffer before running a command, whereas now we only do so if the buffer has been modified since the last time we pushed a boundary. I think the patch below fixes the original problem. Another way to fix it would be to change undo-auto--add-boundary so it always considers (current-buffer) regardless of undo-auto--undoably-changed-buffers. Stefan diff --git a/lisp/emulation/viper-cmd.el b/lisp/emulation/viper-cmd.el index 93cf3b0..ca52f98 100644 --- a/lisp/emulation/viper-cmd.el +++ b/lisp/emulation/viper-cmd.el @@ -1715,7 +1715,8 @@ viper-adjust-undo (let ((inhibit-quit t) tmp tmp2) (setq viper-undo-needs-adjustment nil) - (if (listp buffer-undo-list) + (when (listp buffer-undo-list) + (let ((had-boundary (null (car buffer-undo-list)))) (if (setq tmp (memq viper-buffer-undo-list-mark buffer-undo-list)) (progn (setq tmp2 (cdr tmp)) ; the part after mark @@ -1729,8 +1730,11 @@ viper-adjust-undo (delq viper-buffer-undo-list-mark buffer-undo-list)) ;; restore tail of buffer-undo-list (setq buffer-undo-list (nconc buffer-undo-list tmp2))) - (setq buffer-undo-list (delq nil buffer-undo-list))))) - )) + (setq buffer-undo-list (delq nil buffer-undo-list))) + ;; The top-level loop only adds boundaries if there has been + ;; modifications in the buffer, so make sure we don't accidentally + ;; drop the "final" boundary (bug#22295). + (if had-boundary (undo-boundary))))))) (defun viper-set-complex-command-for-undo ()