From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#28852: make revert-buffer ('g') in VC diff buffers keep point Date: Mon, 24 Jun 2019 19:40:57 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="197296"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 28852@debbugs.gnu.org To: charles@aurox.ch (Charles A. Roelli) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 24 19:56:35 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hfTCj-000pAV-GX for geb-bug-gnu-emacs@m.gmane.org; Mon, 24 Jun 2019 19:56:33 +0200 Original-Received: from localhost ([::1]:53564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfTCi-0007GD-En for geb-bug-gnu-emacs@m.gmane.org; Mon, 24 Jun 2019 13:56:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49699) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfSys-0003Ob-6O for bug-gnu-emacs@gnu.org; Mon, 24 Jun 2019 13:42:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfSyo-0007YZ-OI for bug-gnu-emacs@gnu.org; Mon, 24 Jun 2019 13:42:14 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44371) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfSyg-0007Q7-3Q for bug-gnu-emacs@gnu.org; Mon, 24 Jun 2019 13:42:06 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hfSyf-0006fP-T8 for bug-gnu-emacs@gnu.org; Mon, 24 Jun 2019 13:42:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 24 Jun 2019 17:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28852 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 28852-submit@debbugs.gnu.org id=B28852.156139806625543 (code B ref 28852); Mon, 24 Jun 2019 17:42:01 +0000 Original-Received: (at 28852) by debbugs.gnu.org; 24 Jun 2019 17:41:06 +0000 Original-Received: from localhost ([127.0.0.1]:57912 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hfSxk-0006du-M9 for submit@debbugs.gnu.org; Mon, 24 Jun 2019 13:41:06 -0400 Original-Received: from quimby.gnus.org ([80.91.231.51]:34060) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hfSxi-0006di-P2 for 28852@debbugs.gnu.org; Mon, 24 Jun 2019 13:41:03 -0400 Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=stories) by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hfSxe-0005zJ-0v; Mon, 24 Jun 2019 19:41:00 +0200 In-Reply-To: (Charles A. Roelli's message of "Tue, 17 Oct 2017 19:58:00 +0200") 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: 209.51.188.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:161259 Archived-At: charles@aurox.ch (Charles A. Roelli) writes: >> At the moment, when you hit 'g' in a *vc-diff* buffer, the cursor is >> moved back to (point-min), which can be annoying. Yes, I agree. > +(defun vc-diff-restore-buffer (original new) > + "Restore point in buffer NEW to where it was in ORIGINAL. > + > +This function works by updating buffer ORIGINAL with the contents > +of NEW (without destroying existing markers), swapping their text > +objects, and finally killing buffer ORIGINAL." > + (with-current-buffer original > + (let ((inhibit-read-only t)) > + (replace-buffer-contents new))) > + (with-current-buffer new > + (buffer-swap-text original)) > + (kill-buffer original)) This will restore point to the same point it was before... but not to "where it was", necessarily, I think? That is, if your point is at character 105, then it'll be on character 105 after this, but since the contents may (and will) change, what's on character 105 may be totally different after running the diff -- new changes will appear and others will disappear. I remember discussing a "sloppy save excursion" on emacs-devel once: Save as much data as possible about the old buffer contents, and then try to move point to a similar context in the new buffer contents, even if that means moving to a different line. This is a general problem in many buffers that display generated content and need to get back to "where it was" after a `g'. But I can't remember what the conclusion was, and now I can't find the discussion... Does anybody remember? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no