Mercurial > emacs
annotate lisp/org/org-attach.el @ 108944:b9c2b845f2e6
* lisp/emacs-lisp/advice.el (ad-compile-function):
Define warning-suppress-types before we let-bind it.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 08 Jun 2010 21:18:31 -0400 |
parents | 1d1d5d9bd884 |
children | 594e81986a75 376148b31b5e |
rev | line source |
---|---|
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
1 ;;; org-attach.el --- Manage file attachments to org-mode tasks |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
2 |
106815 | 3 ;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
4 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
5 ;; Author: John Wiegley <johnw@newartisans.com> |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
6 ;; Keywords: org data task |
106168
83924fb4f59c
2009-11-20 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
106022
diff
changeset
|
7 ;; Version: 6.33x |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
8 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
10 ;; |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
14 ;; (at your option) any later version. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
15 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
20 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
23 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
24 ;;; Commentary: |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
25 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
26 ;; See the Org-mode manual for information on how to use it. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
27 ;; |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
28 ;; Attachments are managed in a special directory called "data", which |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101757
diff
changeset
|
29 ;; lives in the same directory as the org file itself. If this data |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
30 ;; directory is initialized as a Git repository, then org-attach will |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
31 ;; automatically commit changes when it sees them. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
32 ;; |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
33 ;; Attachment directories are identified using a UUID generated for the |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
34 ;; task which has the attachments. These are added as property to the |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
35 ;; task when necessary, and should not be deleted or changed by the |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
36 ;; user, ever. UUIDs are generated by a mechanism defined in the variable |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
37 ;; `org-id-method'. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
38 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
39 ;;; Code: |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
40 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
41 (eval-when-compile |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
42 (require 'cl)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
43 (require 'org-id) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
44 (require 'org) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
45 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
46 (defgroup org-attach nil |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
47 "Options concerning entry attachments in Org-mode." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
48 :tag "Org Attach" |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
49 :group 'org) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
50 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
51 (defcustom org-attach-directory "data/" |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
52 "The directory where attachments are stored. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
53 If this is a relative path, it will be interpreted relative to the directory |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
54 where the Org file lives." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
55 :group 'org-attach |
100458
ba23e35d3eaf
2008-12-17 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100448
diff
changeset
|
56 :type 'directory) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
57 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
58 (defcustom org-attach-auto-tag "ATTACH" |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
59 "Tag that will be triggered automatically when an entry has an attachment." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
60 :group 'org-attach |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
61 :type '(choice |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
62 (const :tag "None" nil) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
63 (string :tag "Tag"))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
64 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
65 (defcustom org-attach-file-list-property "Attachments" |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
66 "The property used to keep a list of attachment belonging to this entry. |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
67 This is not really needed, so you may set this to nil if you don't want it. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
68 Also, for entries where children inherit the directory, the list of |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
69 attachments is not kept in this property." |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
70 :group 'org-attach |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
71 :type '(choice |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
72 (const :tag "None" nil) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
73 (string :tag "Tag"))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
74 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
75 (defcustom org-attach-method 'cp |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
76 "The preferred method to attach a file. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
77 Allowed values are: |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
78 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
79 mv rename the file to move it into the attachment directory |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
80 cp copy the file |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
81 ln create a hard link. Note that this is not supported |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
82 on all systems, and then the result is not defined." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
83 :group 'org-attach |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
84 :type '(choice |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
85 (const :tag "Copy" cp) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
86 (const :tag "Move/Rename" mv) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
87 (const :tag "Link" ln))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
88 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
89 (defcustom org-attach-expert nil |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
90 "Non-nil means do not show the splash buffer with the attach dispatcher." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
91 :group 'org-attach |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
92 :type 'boolean) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
93 |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
94 (defcustom org-attach-allow-inheritance t |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
95 "Non-nil means, allow attachment directories be inherited." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
96 :group 'org-attach |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
97 :type 'boolean) |
104164
ac1a55cc2c38
2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
101757
diff
changeset
|
98 |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
99 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
100 (defvar org-attach-inherited nil |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
101 "Indicates if the last access to the attachment directory was inherited.") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
102 |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
103 ;;;###autoload |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
104 (defun org-attach () |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
105 "The dispatcher for attachment commands. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
106 Shows a list of commands and prompts for another key to execute a command." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
107 (interactive) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
108 (let (c marker) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
109 (when (eq major-mode 'org-agenda-mode) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
110 (setq marker (or (get-text-property (point) 'org-hd-marker) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
111 (get-text-property (point) 'org-marker))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
112 (unless marker |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
113 (error "No task in current line"))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
114 (save-excursion |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
115 (when marker |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
116 (set-buffer (marker-buffer marker)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
117 (goto-char marker)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
118 (org-back-to-heading t) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
119 (save-excursion |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
120 (save-window-excursion |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
121 (unless org-attach-expert |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
122 (with-output-to-temp-buffer "*Org Attach*" |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
123 (princ "Select an Attachment Command: |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
124 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
125 a Select a file and attach it to the task, using `org-attach-method'. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
126 c/m/l Attach a file using copy/move/link method. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
127 n Create a new attachment, as an Emacs buffer. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
128 z Synchronize the current task with its attachment |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
129 directory, in case you added attachments yourself. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
130 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
131 o Open current task's attachments. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
132 O Like \"o\", but force opening in Emacs. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
133 f Open current task's attachment directory. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
134 F Like \"f\", but force using dired in Emacs. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
135 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
136 d Delete one attachment, you will be prompted for a file name. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
137 D Delete all of a task's attachments. A safer way is |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
138 to open the directory in dired and delete from there. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
139 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
140 s Set a specific attachment directory for this entry. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
141 i Make children of the current entry inherit its attachment directory."))) |
99501
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
142 (org-fit-window-to-buffer (get-buffer-window "*Org Attach*")) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
143 (message "Select command: [acmlzoOfFdD]") |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
144 (setq c (read-char-exclusive)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
145 (and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*")))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
146 (cond |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
147 ((memq c '(?a ?\C-a)) (call-interactively 'org-attach-attach)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
148 ((memq c '(?c ?\C-c)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
149 (let ((org-attach-method 'cp)) (call-interactively 'org-attach-attach))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
150 ((memq c '(?m ?\C-m)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
151 (let ((org-attach-method 'mv)) (call-interactively 'org-attach-attach))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
152 ((memq c '(?l ?\C-l)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
153 (let ((org-attach-method 'ln)) (call-interactively 'org-attach-attach))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
154 ((memq c '(?n ?\C-n)) (call-interactively 'org-attach-new)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
155 ((memq c '(?z ?\C-z)) (call-interactively 'org-attach-sync)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
156 ((memq c '(?o ?\C-o)) (call-interactively 'org-attach-open)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
157 ((eq c ?O) (call-interactively 'org-attach-open-in-emacs)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
158 ((memq c '(?f ?\C-f)) (call-interactively 'org-attach-reveal)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
159 ((memq c '(?F)) (call-interactively 'org-attach-reveal-in-emacs)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
160 ((memq c '(?d ?\C-d)) (call-interactively |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
161 'org-attach-delete-one)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
162 ((eq c ?D) (call-interactively 'org-attach-delete-all)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
163 ((eq c ?q) (message "Abort")) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
164 ((memq c '(?s ?\C-s)) (call-interactively |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
165 'org-attach-set-directory)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
166 ((memq c '(?i ?\C-i)) (call-interactively |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
167 'org-attach-set-inherit)) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
168 (t (error "No such attachment command %c" c)))))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
169 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
170 (defun org-attach-dir (&optional create-if-not-exists-p) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
171 "Return the directory associated with the current entry. |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
172 This first checks for a local property ATTACH_DIR, and then for an inherited |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
173 property ATTACH_DIR_INHERIT. If neither exists, the default mechanism |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
174 using the entry ID will be invoked to access the unique directory for the |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
175 current entry. |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
176 If the directory does not exist and CREATE-IF-NOT-EXISTS-P is non-nil, |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
177 the directory and (if necessary) the corresponding ID will be created." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
178 (let (attach-dir uuid inherit) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
179 (setq org-attach-inherited (org-entry-get nil "ATTACH_DIR_INHERIT")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
180 (cond |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
181 ((setq attach-dir (org-entry-get nil "ATTACH_DIR")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
182 (org-attach-check-absolute-path attach-dir)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
183 ((and org-attach-allow-inheritance |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
184 (setq inherit (org-entry-get nil "ATTACH_DIR_INHERIT" t))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
185 (setq attach-dir |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
186 (save-excursion |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
187 (save-restriction |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
188 (widen) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
189 (goto-char org-entry-property-inherited-from) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
190 (let (org-attach-allow-inheritance) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
191 (org-attach-dir create-if-not-exists-p))))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
192 (org-attach-check-absolute-path attach-dir) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
193 (setq org-attach-inherited t)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
194 (t ; use the ID |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
195 (org-attach-check-absolute-path nil) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
196 (setq uuid (org-id-get (point) create-if-not-exists-p)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
197 (when (or uuid create-if-not-exists-p) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
198 (unless uuid (error "ID retrieval/creation failed")) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
199 (setq attach-dir (expand-file-name |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
200 (format "%s/%s" |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
201 (substring uuid 0 2) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
202 (substring uuid 2)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
203 (expand-file-name org-attach-directory)))))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
204 (when attach-dir |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
205 (if (and create-if-not-exists-p |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
206 (not (file-directory-p attach-dir))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
207 (make-directory attach-dir t)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
208 (and (file-exists-p attach-dir) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
209 attach-dir)))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
210 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
211 (defun org-attach-check-absolute-path (dir) |
105973
b7d8222914b4
2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
105341
diff
changeset
|
212 "Check if we have enough information to root the attachment directory. |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
213 When DIR is given, check also if it is already absolute. Otherwise, |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
214 assume that it will be relative, and check if `org-attach-directory' is |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
215 absolute, or if at least the current buffer has a file name. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
216 Throw an error if we cannot root the directory." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
217 (or (and dir (file-name-absolute-p dir)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
218 (file-name-absolute-p org-attach-directory) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
219 (buffer-file-name (buffer-base-buffer)) |
105166
172e1951f385
* org.el (org-tree-to-indirect-buffer, org-convert-to-oddeven-levels)
Juanma Barranquero <lekktu@gmail.com>
parents:
104810
diff
changeset
|
220 (error "Need absolute `org-attach-directory' to attach in buffers without filename"))) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
221 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
222 (defun org-attach-set-directory () |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
223 "Set the ATTACH_DIR property of the current entry. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
224 The property defines the directory that is used for attachments |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
225 of the entry." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
226 (interactive) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
227 (let ((dir (org-entry-get nil "ATTACH_DIR"))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
228 (setq dir (read-directory-name "Attachment directory: " dir)) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
229 (org-entry-put nil "ATTACH_DIR" dir))) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
230 |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
231 (defun org-attach-set-inherit () |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
232 "Set the ATTACH_DIR_INHERIT property of the current entry. |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
233 The property defines the directory that is used for attachments |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
234 of the entry and any children that do not explicitly define (by setting |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
235 the ATTACH_DIR property) their own attachment directory." |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
236 (interactive) |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
237 (org-entry-put nil "ATTACH_DIR_INHERIT" "t") |
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
238 (message "Children will inherit attachment directory")) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
239 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
240 (defun org-attach-commit () |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
241 "Commit changes to git if `org-attach-directory' is properly initialized. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
242 This checks for the existence of a \".git\" directory in that directory." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
243 (let ((dir (expand-file-name org-attach-directory))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
244 (if (file-exists-p (expand-file-name ".git" dir)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
245 (shell-command |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
246 (concat "(cd " dir "; " |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
247 " git add .; " |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
248 " git ls-files --deleted -z | xargs -0 git rm; " |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
249 " git commit -m 'Synchronized attachments')"))))) |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
250 |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
251 (defun org-attach-tag (&optional off) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
252 "Turn the autotag on or (if OFF is set) off." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
253 (when org-attach-auto-tag |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
254 (save-excursion |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
255 (org-back-to-heading t) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
256 (org-toggle-tag org-attach-auto-tag (if off 'off 'on))))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
257 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
258 (defun org-attach-untag () |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
259 "Turn the autotag off." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
260 (org-attach-tag 'off)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
261 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
262 (defun org-attach-attach (file &optional visit-dir method) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
263 "Move/copy/link FILE into the attachment directory of the current task. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
264 If VISIT-DIR is non-nil, visit the directory with dired. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
265 METHOD may be `cp', `mv', or `ln', default taken from `org-attach-method'." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
266 (interactive "fFile to keep as an attachment: \nP") |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
267 (setq method (or method org-attach-method)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
268 (let ((basename (file-name-nondirectory file))) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
269 (when (and org-attach-file-list-property (not org-attach-inherited)) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
270 (org-entry-add-to-multivalued-property |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
271 (point) org-attach-file-list-property basename)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
272 (let* ((attach-dir (org-attach-dir t)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
273 (fname (expand-file-name basename attach-dir))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
274 (cond |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
275 ((eq method 'mv) (rename-file file fname)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
276 ((eq method 'cp) (copy-file file fname)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
277 ((eq method 'ln) (add-name-to-file file fname))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
278 (org-attach-commit) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
279 (org-attach-tag) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
280 (if visit-dir |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
281 (dired attach-dir) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
282 (message "File \"%s\" is now a task attachment." basename))))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
283 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
284 (defun org-attach-attach-cp () |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
285 "Attach a file by copying it." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
286 (interactive) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
287 (let ((org-attach-method 'cp)) (call-interactively 'org-attach-attach))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
288 (defun org-attach-attach-mv () |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
289 "Attach a file by moving (renaming) it." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
290 (interactive) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
291 (let ((org-attach-method 'mv)) (call-interactively 'org-attach-attach))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
292 (defun org-attach-attach-ln () |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
293 "Attach a file by creating a hard link to it. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
294 Beware that this does not work on systems that do not support hard links. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
295 On some systems, this apparently does copy the file instead." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
296 (interactive) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
297 (let ((org-attach-method 'ln)) (call-interactively 'org-attach-attach))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
298 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
299 (defun org-attach-new (file) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
300 "Create a new attachment FILE for the current task. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
301 The attachment is created as an Emacs buffer." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
302 (interactive "sCreate attachment named: ") |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
303 (when (and org-attach-file-list-property (not org-attach-inherited)) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
304 (org-entry-add-to-multivalued-property |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
305 (point) org-attach-file-list-property file)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
306 (let ((attach-dir (org-attach-dir t))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
307 (org-attach-tag) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
308 (find-file (expand-file-name file attach-dir)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
309 (message "New attachment %s" file))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
310 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
311 (defun org-attach-delete-one (&optional file) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
312 "Delete a single attachment." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
313 (interactive) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
314 (let* ((attach-dir (org-attach-dir t)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
315 (files (org-attach-file-list attach-dir)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
316 (file (or file |
104810
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
317 (org-icompleting-read |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
318 "Delete attachment: " |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
319 (mapcar (lambda (f) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
320 (list (file-name-nondirectory f))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
321 files))))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
322 (setq file (expand-file-name file attach-dir)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
323 (unless (file-exists-p file) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
324 (error "No such attachment: %s" file)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
325 (delete-file file))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
326 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
327 (defun org-attach-delete-all (&optional force) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
328 "Delete all attachments from the current task. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
329 This actually deletes the entire attachment directory. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
330 A safer way is to open the directory in dired and delete from there." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
331 (interactive "P") |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
332 (when (and org-attach-file-list-property (not org-attach-inherited)) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
333 (org-entry-delete (point) org-attach-file-list-property)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
334 (let ((attach-dir (org-attach-dir))) |
100267
c851df8e004e
2008-12-07 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99866
diff
changeset
|
335 (when |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
336 (and attach-dir |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
337 (or force |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
338 (y-or-n-p "Are you sure you want to remove all attachments of this entry? "))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
339 (shell-command (format "rm -fr %s" attach-dir)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
340 (message "Attachment directory removed") |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
341 (org-attach-commit) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
342 (org-attach-untag)))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
343 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
344 (defun org-attach-sync () |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
345 "Synchronize the current tasks with its attachments. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
346 This can be used after files have been added externally." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
347 (interactive) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
348 (org-attach-commit) |
101458
36abe982e7cd
2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
100908
diff
changeset
|
349 (when (and org-attach-file-list-property (not org-attach-inherited)) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
350 (org-entry-delete (point) org-attach-file-list-property)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
351 (let ((attach-dir (org-attach-dir))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
352 (when attach-dir |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
353 (let ((files (org-attach-file-list attach-dir))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
354 (and files (org-attach-tag)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
355 (when org-attach-file-list-property |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
356 (dolist (file files) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
357 (unless (string-match "^\\." file) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
358 (org-entry-add-to-multivalued-property |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
359 (point) org-attach-file-list-property file)))))))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
360 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
361 (defun org-attach-file-list (dir) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
362 "Return a list of files in the attachment directory. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
363 This ignores files starting with a \".\", and files ending in \"~\"." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
364 (delq nil |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
365 (mapcar (lambda (x) (if (string-match "^\\." x) nil x)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
366 (directory-files dir nil "[^~]\\'")))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
367 |
105973
b7d8222914b4
2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
105341
diff
changeset
|
368 (defun org-attach-reveal (&optional if-exists) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
369 "Show the attachment directory of the current task in dired." |
105973
b7d8222914b4
2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
105341
diff
changeset
|
370 (interactive "P") |
b7d8222914b4
2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
105341
diff
changeset
|
371 (let ((attach-dir (org-attach-dir (not if-exists)))) |
b7d8222914b4
2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
105341
diff
changeset
|
372 (and attach-dir (org-open-file attach-dir)))) |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
373 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
374 (defun org-attach-reveal-in-emacs () |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
375 "Show the attachment directory of the current task. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
376 This will attempt to use an external program to show the directory." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
377 (interactive) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
378 (let ((attach-dir (org-attach-dir t))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
379 (dired attach-dir))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
380 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
381 (defun org-attach-open (&optional in-emacs) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
382 "Open an attachment of the current task. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
383 If there are more than one attachment, you will be prompted for the file name. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
384 This command will open the file using the settings in `org-file-apps' |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
385 and in the system-specific variants of this variable. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
386 If IN-EMACS is non-nil, force opening in Emacs." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
387 (interactive "P") |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
388 (let* ((attach-dir (org-attach-dir t)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
389 (files (org-attach-file-list attach-dir)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
390 (file (if (= (length files) 1) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
391 (car files) |
104810
86b7fe7d1d8f
2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
104164
diff
changeset
|
392 (org-icompleting-read "Open attachment: " |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
393 (mapcar 'list files) nil t)))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
394 (org-open-file (expand-file-name file attach-dir) in-emacs))) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
395 |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
396 (defun org-attach-open-in-emacs () |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
397 "Open attachment, force opening in Emacs. |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
398 See `org-attach-open'." |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
399 (interactive) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
400 (org-attach-open 'in-emacs)) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
401 |
99501
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
402 (defun org-attach-expand (file) |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
403 "Return the full path to the current entry's attachment file FILE. |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
404 Basically, this adds the path to the attachment directory." |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
405 (expand-file-name file (org-attach-dir))) |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
406 |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
407 (defun org-attach-expand-link (file) |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
408 "Return a file link pointing to the current entry's attachment file FILE. |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
409 Basically, this adds the path to the attachment directory, and a \"file:\" |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
410 prefix." |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
411 (concat "file:" (org-attach-expand file))) |
e3acb52d33e1
2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents:
99139
diff
changeset
|
412 |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
413 (provide 'org-attach) |
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
414 |
98696 | 415 ;; arch-tag: fce93c2e-fe07-4fa3-a905-e10dcc7a6248 |
98645
8339497a5b87
New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
416 ;;; org-attach.el ends here |