emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH] org-attach.el: Fetch attachments from git annex


From: Erik Hetzner
Subject: [O] [PATCH] org-attach.el: Fetch attachments from git annex
Date: Mon, 4 Jan 2016 21:09:55 -0800
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (Gojō) APEL/10.8 EasyPG/1.0.0 Emacs/25.1.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)

* org-attach.el (org-attach-use-annex): New function to check if git
  annex should be used.
  (org-annex-open): Automatically fetch attached files from git annex when
  opening if appropriate.
---
 lisp/org-attach.el | 41 +++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index b3cd7b7..b3fde48 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -270,6 +270,14 @@ the ATTACH_DIR property) their own attachment directory."
   (org-entry-put nil "ATTACH_DIR_INHERIT" "t")
   (message "Children will inherit attachment directory"))
 
+(defun org-attach-use-annex ()
+  "Return true if we should use git annex for attachments."
+  (let* ((dir (expand-file-name org-attach-directory))
+        (git-dir (vc-git-root dir)))
+    (and org-attach-git-annex-cutoff
+         (or (file-exists-p (expand-file-name "annex" git-dir))
+             (file-exists-p (expand-file-name ".git/annex" git-dir))))))
+
 (defun org-attach-commit ()
   "Commit changes to git if `org-attach-directory' is properly initialized.
 This checks for the existence of a \".git\" directory in that directory."
@@ -279,20 +287,16 @@ This checks for the existence of a \".git\" directory in 
that directory."
     (when (and git-dir (executable-find "git"))
       (with-temp-buffer
        (cd dir)
-       (let ((have-annex
-              (and org-attach-git-annex-cutoff
-                   (or (file-exists-p (expand-file-name "annex" git-dir))
-                       (file-exists-p (expand-file-name ".git/annex" 
git-dir))))))
-         (dolist (new-or-modified
-                  (split-string
-                   (shell-command-to-string
-                    "git ls-files -zmo --exclude-standard") "\0" t))
-           (if (and have-annex
-                    (>= (nth 7 (file-attributes new-or-modified))
-                        org-attach-git-annex-cutoff))
-               (call-process "git" nil nil nil "annex" "add" new-or-modified)
-             (call-process "git" nil nil nil "add" new-or-modified))
-           (incf changes)))
+        (dolist (new-or-modified
+                 (split-string
+                  (shell-command-to-string
+                   "git ls-files -zmo --exclude-standard") "\0" t))
+          (if (and (org-attach-use-annex)
+                   (>= (nth 7 (file-attributes new-or-modified))
+                       org-attach-git-annex-cutoff))
+              (call-process "git" nil nil nil "annex" "add" new-or-modified)
+            (call-process "git" nil nil nil "add" new-or-modified))
+           (incf changes))
        (dolist (deleted
                 (split-string
                  (shell-command-to-string "git ls-files -z --deleted") "\0" t))
@@ -465,8 +469,13 @@ If IN-EMACS is non-nil, force opening in Emacs."
         (file (if (= (length files) 1)
                   (car files)
                 (org-icompleting-read "Open attachment: "
-                                      (mapcar 'list files) nil t))))
-    (org-open-file (expand-file-name file attach-dir) in-emacs)))
+                                      (mapcar 'list files) nil t)))
+         (path (expand-file-name file attach-dir)))
+    (if (and (file-symlink-p path)
+             (org-attach-use-annex)
+             (not (file-exists-p (file-symlink-p path))))
+        (call-process "git" nil nil nil "annex" "get" path))
+    (org-open-file path in-emacs)))
 
 (defun org-attach-open-in-emacs ()
   "Open attachment, force opening in Emacs.
-- 
2.5.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]