Skip to main content
added 12 characters in body
Source Link
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
              (finddelete-alternateregion (point-filemin) bak(point-max))
              (set-visitedinsert-file-namecontents filebak))
          (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.

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
              (find-alternate-file bak)
              (set-visited-file-name file))
          (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.

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.

Source Link
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
              (find-alternate-file bak)
              (set-visited-file-name file))
          (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.