;; Copyright (C) 2009-2012 Free Software Foundation, Inc
;; Author: Toby Cubitt <toby-undo-tree@dr-qubit.org>
-;; Version: 0.5.2
+;; Version: 0.5.3
;; Keywords: convenience, files, undo, redo, history, tree
;; URL: http://www.dr-qubit.org/emacs.php
;; Repository: http://www.dr-qubit.org/git/undo-tree.git
;;; Change Log:
;;
+;; Version 0.5.3
+;; * modified `undo-list-transfer-to-tree' and `undo-list-pop-changeset' to
+;; cope better if undo boundary before undo-tree-canary is missing
+;; (e.g. org-mode's `org-self-insert-cluster-for-undo' removes this undo
+;; boundary)
+;; * added `undo-tree-history-directory-alist', the undo history file analogue
+;; of `backup-directory-alist'
+;;
;; Version 0.5.2
;; * added `~' to end of default history save-file name
;; * avoid error in `undo-tree-save-history' when undo is disabled in buffer
'boolean))
+(defcustom undo-tree-history-directory-alist nil
+ "Alist of filename patterns and undo history directory names.
+Each element looks like (REGEXP . DIRECTORY). Undo history for
+files with names matching REGEXP will be saved in DIRECTORY.
+DIRECTORY may be relative or absolute. If it is absolute, so
+that all matching files are backed up into the same directory,
+the file names in this directory will be the full name of the
+file backed up with all directory separators changed to `!' to
+prevent clashes. This will not work correctly if your filesystem
+truncates the resulting name.
+
+For the common case of all backups going into one directory, the
+alist should contain a single element pairing \".\" with the
+appropriate directory name.
+
+If this variable is nil, or it fails to match a filename, the
+backup is made in the original file's directory.
+
+On MS-DOS filesystems without long names this variable is always
+ignored."
+ :group 'undo-tree
+ :type '(repeat (cons (regexp :tag "Regexp matching filename")
+ (directory :tag "Undo history directory name"))))
+
+
(defcustom undo-tree-visualizer-relative-timestamps t
"When non-nil, display times relative to current time
when displaying time stamps in visualizer.
(undo-tree-move-GC-elts-to-pool (car p))
(while (and discard-pos (integerp (car buffer-undo-list)))
(setq buffer-undo-list (cdr buffer-undo-list)))
- (car buffer-undo-list))
+ (and (car buffer-undo-list)
+ (not (eq (car buffer-undo-list) 'undo-tree-canary))))
(setcdr p (list (pop buffer-undo-list)))
(setq p (cdr p)))
changeset)))
(when (null buffer-undo-list)
(setq buffer-undo-list '(nil undo-tree-canary)))
- (unless (eq (cadr buffer-undo-list) 'undo-tree-canary)
+ (unless (or (eq (cadr buffer-undo-list) 'undo-tree-canary)
+ (eq (car buffer-undo-list) 'undo-tree-canary))
;; create new node from first changeset in `buffer-undo-list', save old
;; `buffer-undo-tree' current node, and make new node the current node
(let* ((node (undo-tree-make-node nil (undo-list-pop-changeset)))
;; if no undo history has been discarded from `buffer-undo-list' since
;; last transfer, splice new tree fragment onto end of old
;; `buffer-undo-tree' current node
- (if (eq (cadr buffer-undo-list) 'undo-tree-canary)
+ (if (or (eq (cadr buffer-undo-list) 'undo-tree-canary)
+ (eq (car buffer-undo-list) 'undo-tree-canary))
(progn
(setf (undo-tree-node-previous node) splice)
(push node (undo-tree-node-next splice))
-(defun undo-tree-make-history-save-file-name ()
- (concat (file-name-directory (buffer-file-name))
- "." (file-name-nondirectory (buffer-file-name)) ".~undo-tree~"))
+(defun undo-tree-make-history-save-file-name (file)
+ "Create the undo history file name for FILE.
+Normally this is the file's name with `.' prepended and
+`~undo-tree~' appended.
+
+A match for FILE is sought in `undo-tree-history-directory-alist';
+see the documentation of that variable. If the directory for the
+backup doesn't exist, it is created."
+ (let* ((backup-directory-alist undo-tree-history-directory-alist)
+ (name (make-backup-file-name-1 file)))
+ (concat (file-name-directory name) "." (file-name-nondirectory name)
+ ".~undo-tree~")))
(defun undo-tree-save-history (&optional filename overwrite)
(unless filename
(setq filename
(if buffer-file-name
- (undo-tree-make-history-save-file-name)
+ (undo-tree-make-history-save-file-name buffer-file-name)
(expand-file-name (read-file-name "File to save in: ") nil))))
(when (or (not (file-exists-p filename))
overwrite
(unless filename
(setq filename
(if buffer-file-name
- (undo-tree-make-history-save-file-name)
+ (undo-tree-make-history-save-file-name buffer-file-name)
(expand-file-name (read-file-name "File to load from: ") nil))))
;; attempt to read undo-tree from FILENAME