Skip to main content
2 of 2
added 12 characters in body
glucas
  • 20.9k
  • 1
  • 56
  • 84

How about this:

(defun revert-to-backup ()
  "Reverts to the latest backup file associated with the current buffer."
  (interactive)
  (let ((file (buffer-file-name)))
    (when file
      (let ((bak (file-newest-backup (buffer-file-name))))
        (if bak
            (progn
              (delete-region (point-min) (point-max))
              (insert-file-contents bak))
          (message "No backups found!"))))))

With this command you can revert the current buffer to its latest backup. The revert is not saved automatically, I'm assuming you might want to at least look at the content before hitting C-x C-s to save.

glucas
  • 20.9k
  • 1
  • 56
  • 84