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#22295: viper-mode undo bug introduced between Nov 10 and Nov 14 Date: Sat, 14 May 2016 14:57:02 +0100 Message-ID: <87poso7nf5.fsf@russet.org.uk> References: <83vb2h6lfq.fsf@gnu.org> <83r3d56jrg.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1463234308 24106 80.91.229.3 (14 May 2016 13:58:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 14 May 2016 13:58:28 +0000 (UTC) Cc: Michael Kifer , 22295@debbugs.gnu.org, jim@meyering.net To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 14 15:58:13 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 1b1a56-00070D-LI for geb-bug-gnu-emacs@m.gmane.org; Sat, 14 May 2016 15:58:12 +0200 Original-Received: from localhost ([::1]:37788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1a55-0002Fy-VQ for geb-bug-gnu-emacs@m.gmane.org; Sat, 14 May 2016 09:58:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1a52-0002EI-OA for bug-gnu-emacs@gnu.org; Sat, 14 May 2016 09:58:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1a4w-0003Xa-Ll for bug-gnu-emacs@gnu.org; Sat, 14 May 2016 09:58:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39216) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1a4w-0003XW-IK for bug-gnu-emacs@gnu.org; Sat, 14 May 2016 09:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1b1a4w-0005Su-DT for bug-gnu-emacs@gnu.org; Sat, 14 May 2016 09:58: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: Sat, 14 May 2016 13:58: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.146323423320950 (code B ref 22295); Sat, 14 May 2016 13:58:02 +0000 Original-Received: (at 22295) by debbugs.gnu.org; 14 May 2016 13:57:13 +0000 Original-Received: from localhost ([127.0.0.1]:51553 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b1a49-0005Rq-21 for submit@debbugs.gnu.org; Sat, 14 May 2016 09:57:13 -0400 Original-Received: from cloud103.planethippo.com ([31.216.48.48]:36897) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b1a46-0005Rb-Bw for 22295@debbugs.gnu.org; Sat, 14 May 2016 09:57:11 -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=SA1JK6v29DxGqCpn8MHN43XuuPD6zM0Quhpt4dna69k=; b=Zkd2FzRZVGsbqrpw/atH9mc2E0 esDdBbNA1QiZC1RVvpPJ7nHh6imf585ZYvlzk5yEQTQwVdZZSTXOg862lU3P0VwNR9vFn4ArqjUeI /VroSCpCEpf4tY/jI7nN+iMQUNtzwfX3SeVQxTYI2Qs/XXaCScen0PzSt+T7MM8mc1htnW9eMmKZE 7aOsebJkdUQdHdFXojHdnZv5tY6a+utpdUjvWVGeGWHC4W83GFRvXB72mI0o892+XnSGAckqgpSo+ W3PfyY0dfiZQxLjQ3I5BqbVGAQ8gV6eEoJYO75G5AUcyfHirAsSfAdc22sCk6x39J4sIEzqd9ZFQL ZAK2D3dQ==; Original-Received: from cpc1-benw10-2-0-cust373.gate.cable.virginm.net ([77.98.219.118]:56301 helo=russet.org.uk) by cloud103.planethippo.com with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) (Exim 4.86_1) (envelope-from ) id 1b1a3z-003R2c-92; Sat, 14 May 2016 14:57:03 +0100 In-Reply-To: <83r3d56jrg.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 14 May 2016 13:01:23 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.93 (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:118239 Archived-At: Eli Zaretskii writes: >> Date: Sat, 14 May 2016 12:25:13 +0300 >> From: Eli Zaretskii >> Cc: 22295@debbugs.gnu.org, Jim Meyering >> >> > From: Jim Meyering >> > Date: Sat, 2 Jan 2016 20:01:36 -0800 >> > >> > Hello, >> > I noticed that viper-mode's "undo" ('u') command began to undo too much >> > and was able quickly to determine that it worked fine with my snapshot >> > built from git master some time on Nov 10, yet that it began to undo >> > too much four days later. >> > >> > To demonstrate the problem (without risking changing anything in your >> > home directory), run this: >> > >> > mkdir /tmp/x && HOME=/tmp/x emacs -Q -f viper-mode -nw >> > ~/previously-nonexistent-file >> > >> > then respond "y", "y", "5" to get past the "viperize" setup questions. >> > To reproduce the error, insert two lines, terminating each "insertion" with ESC, >> > so that each is recorded as a separate undo'able operation. I.e., type this >> > >> > a 1 ESC >> > >> > to create the first line, then >> > >> > o 2 ESC >> > >> > to create the second. >> > Finally, hit "u" to undo creation of the second and you'll see that it undoes >> > both operations, erasing both lines. This is rather disruptive when that first >> > bit of text was a long paragraph or two -- the novice may think that it's lost, >> > because redo does not restore it -- however, it is available in emacs's >> > yank buffer. >> >> Phillip, could you please look into this? This sounds like a annoying >> problem for users of viper-mode, and AFAIU it happens on the release >> branch as well. > > (Adding Michael to the addressees.) > > I took a short look, and it sounds like we need more experts here. > Undo in viper has its own implementation, which tries to do something > that is not immediately clear to me, and is not really documented > anywhere. I guess vi users will know that, but I'm not one of them. > > The viper-undo command and related functions manipulate the Emacs undo > data structures directly, see viper-adjust-undo. I guess the recent > changes in low-level undo implementation run afoul of what viper-mode > tries to do. > > I hope the above provides enough hints to find the reason for this > problem and solve it. > Sorry for slow response -- was travelling. Yep, viper is doing strange things to undo -- it adds a symbol ('viper) to the undo list, then removes it later, amalgamating everything upto 'viper. I've got a complete test case (below in case anyone is interested -- I'll make a proper unit test of it on master eventually). On e0f64e7b4f9c3bbc12c4909ca8c8aa751f1fca4a (a random commit around the time of the error). This produced a undo list like so: (nil (2 . 4) nil (2 . 3) (1 . 2) (t . -1)) While on emacs-25 it gives (my comments): ((3 . 4) ;; insertion from 3 to 4 (2 . 3) ;; insertion from 2 to 3 nil ;; boundary (2 . 3) ;; insertion from 2 to 3 (1 . 2) ;; insertion from 1 to 2 (t . -1) ;; buffer created with file that does not exist ) So it looks like the amalgamation that Emacs is supposed to be doing is failing. No idea at all where the head "nil" has gone. Will work on this more. (setq viper-inhibit-startup-message 't) (setq viper-expert-level '5) (find-file "/tmp/file.txt") (setq viper-mode t) (require 'viper) ;; leave emacs lisp in Emacs mode or edebug becomes impossible (setq viper-vi-state-mode-list (delq 'emacs-lisp-mode viper-vi-state-mode-list)) (setq viper-emacs-state-mode-list (cons 'emacs-lisp-mode viper-vi-state-mode-list)) ;; alas edebug "print last eval" is still broken (require 'edebug) (edebug-instrument-function 'viper-adjust-undo) ;; a 1 (execute-kbd-macro [?a ?1 escape ?o ?2 escape])