From mboxrd@z Thu Jan 1 00:00:00 1970 From: Erik Hetzner Subject: [PATCH] org-attach.el: Fetch attachments from git annex Date: Mon, 4 Jan 2016 21:09:55 -0800 Message-ID: <568b532e.d111620a.b25a8.ffffbb7c@mx.google.com> Reply-To: Erik Hetzner Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGK5D-00034R-AR for emacs-orgmode@gnu.org; Tue, 05 Jan 2016 00:23:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGK5A-0000Ym-3p for emacs-orgmode@gnu.org; Tue, 05 Jan 2016 00:22:59 -0500 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]:34683) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGK59-0000Ya-Uo for emacs-orgmode@gnu.org; Tue, 05 Jan 2016 00:22:56 -0500 Received: by mail-pa0-x230.google.com with SMTP id uo6so189447648pac.1 for ; Mon, 04 Jan 2016 21:22:55 -0800 (PST) Received: from marut.e6h.org (50-0-83-149.dsl.static.fusionbroadband.com. [50.0.83.149]) by smtp.gmail.com with ESMTPSA id 78sm118276715pfr.41.2016.01.04.21.22.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jan 2016 21:22:54 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org * 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