branch: elpa/undo-fu-session
commit 42fdbe086f569a614c65b76965924c02254de1b9
Author: Campbell Barton <ideasma...@gmail.com>
Commit: Campbell Barton <ideasma...@gmail.com>

    Support custom file-system locations for undo data
    
    Resolves #9.
---
 readme.rst         | 29 +++++++++++++++++++++++++++++
 undo-fu-session.el | 20 +++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/readme.rst b/readme.rst
index 1264bd5afe..77ac62d7f2 100644
--- a/readme.rst
+++ b/readme.rst
@@ -115,6 +115,35 @@ With exceptions added for cases where undo-session should 
not be stored.
    Directories to consider temporary when 
``undo-fu-session-ignore-temp-files`` is enabled.
 
 
+Customization (Data Storage)
+----------------------------
+
+This is advanced functionality for users who prefer to define their own method
+of defining the file-system location of undo-fu-session data.
+
+``undo-fu-session-make-file-name-function``: 
``'undo-fu-session-make-file-name``
+   This function takes two arguments ``(filepath extension)`` and must return
+   a the path where undo data is stored, ending with ``extension``.
+
+If you wish to store undo data next in the same directory as the file being 
edited
+this example shows how it can be achieved.
+
+Take care, if you define paths outside of ``undo-fu-session-directory`` the 
following functionality
+
+- ``undo-fu-session-file-limit`` isn't applied.
+- ``undo-fu-session-compression-update`` won't update compression on existing 
undo data.
+
+This example function stores undo data for ``~/file.txt`` as 
``~/.#file#.undo-fu-session.gz``.
+
+.. code-block:: elisp
+
+   (setq undo-fu-session-make-file-name-function
+         (lambda (filepath extension)
+           (let* ((filename (file-name-nondirectory filepath))
+                  (dirpath (substring filepath 0 (- (length filepath) (length 
filename)))))
+             (concat dirpath ".#" filename "#.undo-fu-session" extension))))
+
+
 Details
 =======
 
diff --git a/undo-fu-session.el b/undo-fu-session.el
index 7a33428efc..aced354eee 100755
--- a/undo-fu-session.el
+++ b/undo-fu-session.el
@@ -60,6 +60,12 @@
   "The directory to store undo data."
   :type 'string)
 
+(defcustom undo-fu-session-make-file-name-function 
'undo-fu-session-make-file-name
+  "The function that computes the session file-path for the current buffer.
+The function takes two arguments (path, extension).
+The returned path must use the extension argument."
+  :type 'function)
+
 (defcustom undo-fu-session-ignore-encrypted-files t
   "Ignore encrypted files for undo session."
   :type 'boolean)
@@ -501,11 +507,23 @@ Argument PENDING-LIST an `pending-undo-list' compatible 
list."
 
 (defun undo-fu-session--make-file-name (filename)
   "Take the path FILENAME and return a name base on this."
+  (declare (important-return-value t))
+  (let ((ext (undo-fu-session--file-name-ext)))
+    (condition-case err
+        (funcall undo-fu-session-make-file-name-function filename ext)
+      (error
+       (message "Undo-Fu-Session: error (%s) running callback %S, using the 
default callback"
+                (error-message-string err)
+                undo-fu-session-make-file-name-function)
+       (undo-fu-session-make-file-name filename ext)))))
+
+(defun undo-fu-session-make-file-name (filename ext)
+  "Take the path FILENAME, EXT and return a name base on this."
   (declare (important-return-value t) (side-effect-free error-free))
   (concat
    (file-name-concat undo-fu-session-directory
                      (url-hexify-string (convert-standard-filename 
(expand-file-name filename))))
-   (undo-fu-session--file-name-ext)))
+   ext))
 
 (defun undo-fu-session--match-file-name (filename test-files)
   "Return t if FILENAME match any item in TEST-FILES."

Reply via email to