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

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

Re: Reverting but keeping undo


From: W. Greenhouse
Subject: Re: Reverting but keeping undo
Date: Thu, 16 May 2013 05:29:38 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Óscar Fuentes <ofv@wanadoo.es> writes:

> `revert-buffer' discards undo history. I can understand that undo
> history might be in conflict with the new contents of the buffer. How
> dangerous is that? Apart from that, what could be wrong with using the
> recipe published in
>
> http://www.emacswiki.org/emacs/RevertBuffer#toc4
>
> ?
>
> For your convenience, this is the recipe:
>
> (defun revert-buffer-keep-undo (&rest -)
>   "Revert buffer but keep undo history."
>   (interactive)
>   (let ((inhibit-read-only t))
>     (erase-buffer)
>     (insert-file-contents (buffer-file-name))
>     (set-visited-file-modtime (visited-file-modtime))
>     (set-buffer-modified-p nil)))
>
> Install in command ‘revert-buffer’ with
>
>   (setq revert-buffer-function 'revert-buffer-keep-undo)

This looks like a nice simple hack, but it doesn't do half of the things
that revert-buffer does, such as resetting local variables and possibly
picking a different major mode and file encoding if the change in file
contents warrants it.  From looking at the code of `revert-buffer', this
problem could be solved without getting rid of all those nice features
if you put an advice around revert-buffer that stashed
`buffer-undo-list' away inside a let-bound variable before revertying,
and then reset `buffer-undo-list' from that variable afterwards.

-- 
BOFH excuse #453:

Spider infestation in warm case parts




reply via email to

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