5

Is there an emacs extension that takes periodic snapshots (once a minute, once every x keystrokes, whatever) of a file while it is being edited similar to the change history in Eclipse or the edit history in Google Docs and other programs?

I'm hoping for something that'll let me easy navigate through the changes I've made from day to day - Is there anything like this already written?

Edit

I should be more specific - I'm not looking for a VCS. I'm looking for a minor-mode or something similar I can just switch on and have hard copies of the revisions on disk.

4

4 に答える 4

5

There's a built-in feature called autosave that saves after N keystrokes (and maybe after M seconds, I'm not sure). I generally use this if Emacs crashes, not for looking at what edits I've made; undo is better for that. Here's my config:

(setq autosave-dir (concat user-emacs-directory "autosaves/")
      auto-save-list-file-prefix (concat emacs-persistence-directory
                                         "autosave-list"))
(if (not (file-exists-p autosave-dir))
    (make-directory autosave-dir t))
(add-to-list 'auto-save-file-name-transforms
             `("\\`/?\\([^/]*/\\)*\\([^/]*\\)\\'" ,(concat autosave-dir "\\2") t))
;; tramp autosaves
(setq tramp-auto-save-directory (concat user-emacs-directory "tramp-autosaves/"))
(if (not (file-exists-p tramp-auto-save-directory))
    (make-directory tramp-auto-save-directory))

There's also a backup system that creates a copy after every save (not autosave). I use this for what I think you're asking for - looking at history since my last VCS commit. Here's my config:

(setq make-backup-files t
      vc-make-backup-files t
      version-control t
      kept-new-versions 256
      kept-old-versions 0
      delete-old-versions t
      backup-by-copying t)
(setq backup-dir (concat user-emacs-directory "backup/"))
(if (not (file-exists-p backup-dir))
    (make-directory backup-dir))
(add-to-list 'backup-directory-alist
             `(".*" . ,backup-dir))
(defun force-backup-of-buffer ()
  (setq buffer-backed-up nil))
(add-hook 'before-save-hook 'force-backup-of-buffer)
;; this is what tramp uses
(setq tramp-backup-directory-alist backup-directory-alist)

(add-to-path "backup-walker")
(autoload 'backup-walker-start "backup-walker"
  "start walking with the latest backup" t)

I use the excellent backup-walker to navigate through the backups.

于 2012-05-11T15:54:52.953 に答える
5

The best solution I have found for this is undo-tree, which is the Emacs equivalent to gundo for vim: it lets you visualise the tree of undo/redo, navigate through the changes and go back and forth between different versions.

undo-tree can be installed using ELPA; once it is installed, add the following to .emacs:

(require 'undo-tree)
(global-undo-tree-mode)

The undo tree can then be visualised using Ctrl-x u (undo-tree-visualize). The different “versions” can be navigated in a very intuitive manner, using arrow keys.

The history can also be made persistent using undo-tree-save-history.

于 2014-04-23T21:22:31.167 に答える
4

If you really value keeping your changes, I would highly recommend starting to use git. It will work for your windows and linux coding environments. I use it to port changes from code back and forth. It does a great job of fixing all the little line endings and merging changes.

If you really just want it to keep old versions, then emacs can create a new backup every time that you save. It just creates another file right next to your current one. That way you can control how often it makes a new backup (every time you save).

Here's a good page that talks about the options:

ftp://ftp.gnu.org/pub/old-gnu/Manuals/emacs-20.7/html_chapter/emacs_18.html#SEC109

于 2012-05-10T22:24:42.787 に答える
1

Try http://www.emacswiki.org/emacs/BackupEachSave

It has saved me a number of times allowing me to backtrack.

于 2012-05-11T15:31:39.613 に答える