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

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

Reverting but keeping undo


From: Óscar Fuentes
Subject: Reverting but keeping undo
Date: Wed, 15 May 2013 12:38:40 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

`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)




reply via email to

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