annotate lisp/org/org-attach.el @ 109418:6e96aca307a4

Merge from mainline.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Sun, 27 Jun 2010 22:48:36 +0000
parents 594e81986a75
children a150e8a14679
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106168
diff changeset
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
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
7 ;; Version: 6.35i
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
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
95 "Non-nil means allow attachment directories be inherited."
101458
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)))
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
244 (when (file-exists-p (expand-file-name ".git" dir))
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
245 (with-temp-buffer
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
246 (cd dir)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
247 (shell-command "git add .")
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
248 (shell-command "git ls-files --deleted" t)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
249 (mapc '(lambda (file)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
250 (unless (string= file "")
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
251 (shell-command
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
252 (concat "git rm \"" file "\""))))
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
253 (split-string (buffer-string) "\n"))
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
254 (shell-command "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
255
98645
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
256 (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
257 "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
258 (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
259 (save-excursion
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
260 (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
261 (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
262
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
263 (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
264 "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
265 (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
266
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
267 (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
268 "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
269 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
270 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
271 (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
272 (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
273 (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
274 (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
275 (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
276 (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
277 (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
278 (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
279 (cond
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
280 ((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
281 ((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
282 ((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
283 (org-attach-commit)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
284 (org-attach-tag)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
285 (if visit-dir
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
286 (dired attach-dir)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
287 (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
288
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
289 (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
290 "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
291 (interactive)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
292 (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
293 (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
294 "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
295 (interactive)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
296 (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
297 (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
298 "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
299 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
300 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
301 (interactive)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
302 (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
303
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
304 (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
305 "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
306 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
307 (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
308 (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
309 (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
310 (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
311 (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
312 (org-attach-tag)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
313 (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
314 (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
315
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
316 (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
317 "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
318 (interactive)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
319 (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
320 (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
321 (file (or file
104810
86b7fe7d1d8f 2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 104164
diff changeset
322 (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
323 "Delete attachment: "
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
324 (mapcar (lambda (f)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
325 (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
326 files)))))
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
327 (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
328 (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
329 (error "No such attachment: %s" file))
107863
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
330 (delete-file file)
594e81986a75 2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents: 106815
diff changeset
331 (org-attach-commit)))
98645
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
332
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
333 (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
334 "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
335 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
336 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
337 (interactive "P")
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
338 (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
339 (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
340 (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
341 (when
98645
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
342 (and attach-dir
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
343 (or force
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
344 (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
345 (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
346 (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
347 (org-attach-commit)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
348 (org-attach-untag))))
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
349
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
350 (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
351 "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
352 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
353 (interactive)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
354 (org-attach-commit)
101458
36abe982e7cd 2009-01-25 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 100908
diff changeset
355 (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
356 (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
357 (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
358 (when attach-dir
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
359 (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
360 (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
361 (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
362 (dolist (file files)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
363 (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
364 (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
365 (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
366
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
367 (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
368 "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
369 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
370 (delq nil
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
371 (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
372 (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
373
105973
b7d8222914b4 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 105341
diff changeset
374 (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
375 "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
376 (interactive "P")
b7d8222914b4 2009-11-13 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 105341
diff changeset
377 (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
378 (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
379
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
380 (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
381 "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
382 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
383 (interactive)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
384 (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
385 (dired attach-dir)))
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
386
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
387 (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
388 "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
389 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
390 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
391 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
392 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
393 (interactive "P")
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
394 (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
395 (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
396 (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
397 (car files)
104810
86b7fe7d1d8f 2009-09-02 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 104164
diff changeset
398 (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
399 (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
400 (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
401
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
402 (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
403 "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
404 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
405 (interactive)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
406 (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
407
99501
e3acb52d33e1 2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 99139
diff changeset
408 (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
409 "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
410 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
411 (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
412
e3acb52d33e1 2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 99139
diff changeset
413 (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
414 "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
415 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
416 prefix."
e3acb52d33e1 2008-11-12 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <dominik@science.uva.nl>
parents: 99139
diff changeset
417 (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
418
98645
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
419 (provide 'org-attach)
8339497a5b87 New files org-attach.el, org-list.el, org-plot.el.
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
420
98696
7e941d6d7c4c Add arch tagline
Miles Bader <miles@gnu.org>
parents: 98645
diff changeset
421 ;; 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
422 ;;; org-attach.el ends here