bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#28852: make revert-buffer ('g') in VC diff buffers keep point


From: Lars Ingebrigtsen
Subject: bug#28852: make revert-buffer ('g') in VC diff buffers keep point
Date: Mon, 24 Jun 2019 19:40:57 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]