emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-attach.el: Fetch attachments from git annex
@ 2016-01-05  5:09 Erik Hetzner
  2016-01-05  5:30 ` Eric Abrahamsen
                   ` (2 more replies)
  0 siblings, 3 replies; 40+ messages in thread
From: Erik Hetzner @ 2016-01-05  5:09 UTC (permalink / raw)
  To: emacs-orgmode

* 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

^ permalink raw reply related	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2016-02-14 11:50 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-05  5:09 [PATCH] org-attach.el: Fetch attachments from git annex Erik Hetzner
2016-01-05  5:30 ` Eric Abrahamsen
2016-01-05  6:11 ` Erik Hetzner
2016-01-05  6:36   ` Kyle Meyer
2016-01-05  9:56   ` Rasmus
2016-01-05 17:14     ` Kyle Meyer
2016-01-05 18:16       ` Rasmus
2016-01-05 19:30         ` Kyle Meyer
2016-01-05 21:55           ` Rasmus
2016-01-06  5:43             ` Kyle Meyer
2016-01-06  1:27     ` Erik Hetzner
2016-01-06  9:37       ` Rasmus
2016-01-05  6:21 ` Kyle Meyer
2016-01-06  1:15   ` Erik Hetzner
2016-01-25  5:24     ` Erik Hetzner
2016-01-25 21:19       ` Rasmus
2016-01-25  4:34         ` Erik Hetzner
2016-01-26  7:40           ` Kyle Meyer
2016-01-26 16:39             ` Erik Hetzner
2016-01-26 17:34               ` Kyle Meyer
2016-01-26 22:04                 ` Rasmus
2016-01-25  4:34                   ` [PATCH] org-attach.el: Get " Erik Hetzner
2016-01-27 22:20                     ` Rasmus
2016-02-01  3:32                       ` Erik Hetzner
2016-01-29  5:39                     ` Kyle Meyer
2016-01-25  4:34                       ` Erik Hetzner
2016-02-05  2:41                         ` Kyle Meyer
2016-02-06 12:18                         ` Rasmus
2016-02-07 17:15                           ` Erik Hetzner
2016-02-07 20:48                             ` Achim Gratz
2016-02-09  5:25                               ` Erik Hetzner
2016-02-09 19:40                                 ` Achim Gratz
2016-02-09 21:12                                   ` Erik Hetzner
2016-02-09 22:19                                     ` Achim Gratz
2016-02-11  2:24                                       ` Erik Hetzner
2016-02-11 18:57                                         ` Achim Gratz
2016-02-09  5:40                               ` [PATCH] testing/lisp/test-org-attach-annex.el: New file Erik Hetzner
2016-02-14 11:50                                 ` Achim Gratz
2016-01-26  5:31         ` [PATCH] org-attach.el: Fetch attachments from git annex Erik Hetzner
2016-01-26 22:10           ` Rasmus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).