2015-11-13 22:51:28 +00:00
|
|
|
|
;;; org-attach.el --- Manage file attachments to Org tasks -*- lexical-binding: t; -*-
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
2019-01-01 10:50:56 +00:00
|
|
|
|
;; Copyright (C) 2008-2019 Free Software Foundation, Inc.
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
|
|
|
|
;; Author: John Wiegley <johnw@newartisans.com>
|
|
|
|
|
;; Keywords: org data task
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2016-08-23 20:13:56 +00:00
|
|
|
|
;; See the Org manual for information on how to use it.
|
2008-10-01 07:25:18 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Attachments are managed in a special directory called "data", which
|
2009-02-06 14:00:27 +00:00
|
|
|
|
;; lives in the same directory as the org file itself. If this data
|
2008-10-01 07:25:18 +00:00
|
|
|
|
;; directory is initialized as a Git repository, then org-attach will
|
|
|
|
|
;; automatically commit changes when it sees them.
|
|
|
|
|
;;
|
|
|
|
|
;; Attachment directories are identified using a UUID generated for the
|
|
|
|
|
;; task which has the attachments. These are added as property to the
|
|
|
|
|
;; task when necessary, and should not be deleted or changed by the
|
|
|
|
|
;; user, ever. UUIDs are generated by a mechanism defined in the variable
|
|
|
|
|
;; `org-id-method'.
|
|
|
|
|
|
2008-10-09 10:19:43 +00:00
|
|
|
|
;;; Code:
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
2016-07-25 13:54:06 +00:00
|
|
|
|
(require 'cl-lib)
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(require 'org)
|
2016-07-25 13:54:06 +00:00
|
|
|
|
(require 'org-id)
|
2013-12-06 14:22:50 +00:00
|
|
|
|
(require 'vc-git)
|
2013-09-02 11:33:52 +00:00
|
|
|
|
|
2017-05-09 15:51:32 +00:00
|
|
|
|
(declare-function dired-dwim-target-directory "dired-aux")
|
|
|
|
|
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(defgroup org-attach nil
|
2016-10-11 16:00:08 +00:00
|
|
|
|
"Options concerning entry attachments in Org mode."
|
2008-10-09 10:19:43 +00:00
|
|
|
|
:tag "Org Attach"
|
2008-10-01 07:25:18 +00:00
|
|
|
|
:group 'org)
|
|
|
|
|
|
|
|
|
|
(defcustom org-attach-directory "data/"
|
|
|
|
|
"The directory where attachments are stored.
|
|
|
|
|
If this is a relative path, it will be interpreted relative to the directory
|
|
|
|
|
where the Org file lives."
|
|
|
|
|
:group 'org-attach
|
2017-12-04 13:55:20 +00:00
|
|
|
|
:type 'directory
|
|
|
|
|
:safe #'stringp)
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
2016-02-10 22:37:03 +00:00
|
|
|
|
(defcustom org-attach-commit t
|
|
|
|
|
"If non-nil commit attachments with git.
|
|
|
|
|
This is only done if the Org file is in a git repository."
|
|
|
|
|
:group 'org-attach
|
|
|
|
|
:type 'boolean
|
2017-01-26 04:39:18 +00:00
|
|
|
|
:version "26.1"
|
2016-02-10 22:37:03 +00:00
|
|
|
|
:package-version '(Org . "9.0"))
|
|
|
|
|
|
2012-10-20 14:47:01 +00:00
|
|
|
|
(defcustom org-attach-git-annex-cutoff (* 32 1024)
|
|
|
|
|
"If non-nil, files larger than this will be annexed instead of stored."
|
|
|
|
|
:group 'org-attach
|
Add :version and :package-version
* ox.el (org-export-snippet-translation-alist)
(org-export-coding-system, org-export-in-background)
(org-export-async-init-file, org-export-invisible-backends)
(org-export-dispatch-use-expert-ui):
* ox-texinfo.el (org-texinfo-filename, org-texinfo-classes)
(org-texinfo-format-headline-function)
(org-texinfo-node-description-column)
(org-texinfo-active-timestamp-format)
(org-texinfo-link-with-unknown-path-format)
(org-texinfo-tables-verbatim)
(org-texinfo-table-scientific-notation)
(org-texinfo-text-markup-alist)
(org-texinfo-format-drawer-function)
(org-texinfo-format-inlinetask-function)
(org-texinfo-info-process):
* ox-man.el (org-man-tables-centered)
(org-man-table-scientific-notation)
(org-man-source-highlight, org-man-source-highlight-langs)
(org-man-pdf-process, org-man-logfiles-extensions):
* ox-html.el (org-html-allow-name-attribute-in-anchors)
(org-html-coding-system, org-html-divs):
* ox-ascii.el (org-ascii-text-width)
(org-ascii-headline-spacing, org-ascii-indented-line-width)
(org-ascii-paragraph-spacing, org-ascii-charset)
(org-ascii-underline, org-ascii-bullets)
(org-ascii-links-to-notes)
(org-ascii-table-keep-all-vertical-lines)
(org-ascii-table-widen-columns)
(org-ascii-table-use-ascii-art)
(org-ascii-format-drawer-function)
(org-ascii-format-inlinetask-function):
* org.el (org-modules, org-export-backends)
(org-highlight-latex-and-related, orgstruct-setup-hook):
* org-attach.el (org-attach-git-annex-cutoff):
* org-archive.el (org-archive-file-header-format):
* org-agenda.el (org-agenda-todo-ignore-time-comparison-use-seconds):
* ob-python.el (org-babel-python-hline-to)
(org-babel-python-None-to):
* ob-ditaa.el (org-ditaa-eps-jar-path):
* ob-core.el (org-babel-results-keyword): Add :version and
:package-version.
* ox-ascii.el: Use utf-8-emacs as the file coding system.
2013-03-05 15:34:16 +00:00
|
|
|
|
:version "24.4"
|
|
|
|
|
:package-version '(Org . "8.0")
|
2012-10-20 14:47:01 +00:00
|
|
|
|
:type '(choice
|
|
|
|
|
(const :tag "None" nil)
|
|
|
|
|
(integer :tag "Bytes")))
|
|
|
|
|
|
2008-10-06 07:38:50 +00:00
|
|
|
|
(defcustom org-attach-auto-tag "ATTACH"
|
|
|
|
|
"Tag that will be triggered automatically when an entry has an attachment."
|
|
|
|
|
:group 'org-attach
|
|
|
|
|
:type '(choice
|
|
|
|
|
(const :tag "None" nil)
|
|
|
|
|
(string :tag "Tag")))
|
|
|
|
|
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(defcustom org-attach-file-list-property "Attachments"
|
|
|
|
|
"The property used to keep a list of attachment belonging to this entry.
|
2009-01-19 07:42:38 +00:00
|
|
|
|
This is not really needed, so you may set this to nil if you don't want it.
|
|
|
|
|
Also, for entries where children inherit the directory, the list of
|
|
|
|
|
attachments is not kept in this property."
|
2008-10-08 10:46:40 +00:00
|
|
|
|
:group 'org-attach
|
|
|
|
|
:type '(choice
|
|
|
|
|
(const :tag "None" nil)
|
|
|
|
|
(string :tag "Tag")))
|
|
|
|
|
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(defcustom org-attach-method 'cp
|
2008-10-09 10:19:43 +00:00
|
|
|
|
"The preferred method to attach a file.
|
2008-10-07 12:28:21 +00:00
|
|
|
|
Allowed values are:
|
|
|
|
|
|
|
|
|
|
mv rename the file to move it into the attachment directory
|
|
|
|
|
cp copy the file
|
2008-10-09 10:19:43 +00:00
|
|
|
|
ln create a hard link. Note that this is not supported
|
2012-04-12 18:20:39 +00:00
|
|
|
|
on all systems, and then the result is not defined.
|
|
|
|
|
lns create a symbol link. Note that this is not supported
|
2008-10-09 10:19:43 +00:00
|
|
|
|
on all systems, and then the result is not defined."
|
2008-10-07 12:28:21 +00:00
|
|
|
|
:group 'org-attach
|
|
|
|
|
:type '(choice
|
|
|
|
|
(const :tag "Copy" cp)
|
|
|
|
|
(const :tag "Move/Rename" mv)
|
2012-04-12 18:20:39 +00:00
|
|
|
|
(const :tag "Hard Link" ln)
|
|
|
|
|
(const :tag "Symbol Link" lns)))
|
2008-10-07 12:28:21 +00:00
|
|
|
|
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(defcustom org-attach-expert nil
|
|
|
|
|
"Non-nil means do not show the splash buffer with the attach dispatcher."
|
|
|
|
|
:group 'org-attach
|
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(defcustom org-attach-allow-inheritance t
|
2010-01-21 15:15:40 +00:00
|
|
|
|
"Non-nil means allow attachment directories be inherited."
|
2009-01-19 07:42:38 +00:00
|
|
|
|
:group 'org-attach
|
|
|
|
|
:type 'boolean)
|
2009-06-08 06:00:46 +00:00
|
|
|
|
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(defvar org-attach-inherited nil
|
|
|
|
|
"Indicates if the last access to the attachment directory was inherited.")
|
|
|
|
|
|
2011-03-03 10:17:55 +00:00
|
|
|
|
(defcustom org-attach-store-link-p nil
|
|
|
|
|
"Non-nil means store a link to a file when attaching it."
|
|
|
|
|
:group 'org-attach
|
2012-03-19 20:38:12 +00:00
|
|
|
|
:version "24.1"
|
2011-03-10 10:18:40 +00:00
|
|
|
|
:type '(choice
|
|
|
|
|
(const :tag "Don't store link" nil)
|
2011-03-10 10:22:33 +00:00
|
|
|
|
(const :tag "Link to origin location" t)
|
2012-03-14 05:17:25 +00:00
|
|
|
|
(const :tag "Link to the attach-dir location" attached)))
|
2011-03-03 10:17:55 +00:00
|
|
|
|
|
2014-10-14 01:51:01 +00:00
|
|
|
|
(defcustom org-attach-archive-delete nil
|
|
|
|
|
"Non-nil means attachments are deleted upon archiving a subtree.
|
|
|
|
|
When set to `query', ask the user instead."
|
|
|
|
|
:group 'org-attach
|
2017-01-26 04:39:18 +00:00
|
|
|
|
:version "26.1"
|
2014-10-14 01:51:01 +00:00
|
|
|
|
:package-version '(Org . "8.3")
|
|
|
|
|
:type '(choice
|
|
|
|
|
(const :tag "Never delete attachments" nil)
|
|
|
|
|
(const :tag "Always delete attachments" t)
|
|
|
|
|
(const :tag "Query the user" query)))
|
|
|
|
|
|
2016-02-06 12:16:52 +00:00
|
|
|
|
(defcustom org-attach-annex-auto-get 'ask
|
|
|
|
|
"Confirmation preference for automatically getting annex files.
|
|
|
|
|
If \\='ask, prompt using `y-or-n-p'. If t, always get. If nil, never get."
|
|
|
|
|
:group 'org-attach
|
2017-09-07 20:56:11 +00:00
|
|
|
|
:package-version '(Org . "9.0")
|
2017-01-26 04:39:18 +00:00
|
|
|
|
:version "26.1"
|
2016-02-06 12:16:52 +00:00
|
|
|
|
:type '(choice
|
|
|
|
|
(const :tag "confirm with `y-or-n-p'" ask)
|
|
|
|
|
(const :tag "always get from annex if necessary" t)
|
|
|
|
|
(const :tag "never get from annex" nil)))
|
|
|
|
|
|
2008-10-01 07:25:18 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun org-attach ()
|
|
|
|
|
"The dispatcher for attachment commands.
|
|
|
|
|
Shows a list of commands and prompts for another key to execute a command."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let (c marker)
|
|
|
|
|
(when (eq major-mode 'org-agenda-mode)
|
|
|
|
|
(setq marker (or (get-text-property (point) 'org-hd-marker)
|
|
|
|
|
(get-text-property (point) 'org-marker)))
|
|
|
|
|
(unless marker
|
|
|
|
|
(error "No task in current line")))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(when marker
|
|
|
|
|
(set-buffer (marker-buffer marker))
|
|
|
|
|
(goto-char marker))
|
|
|
|
|
(org-back-to-heading t)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-window-excursion
|
|
|
|
|
(unless org-attach-expert
|
|
|
|
|
(with-output-to-temp-buffer "*Org Attach*"
|
|
|
|
|
(princ "Select an Attachment Command:
|
|
|
|
|
|
2008-10-07 12:28:21 +00:00
|
|
|
|
a Select a file and attach it to the task, using `org-attach-method'.
|
2012-04-12 18:20:39 +00:00
|
|
|
|
c/m/l/y Attach a file using copy/move/link/symbolic-link method.
|
2017-03-11 00:54:05 +00:00
|
|
|
|
u Attach a file from URL (downloading it).
|
2018-11-02 01:04:38 +00:00
|
|
|
|
b Select a buffer and attach its contents to the task.
|
2008-10-07 12:28:21 +00:00
|
|
|
|
n Create a new attachment, as an Emacs buffer.
|
|
|
|
|
z Synchronize the current task with its attachment
|
|
|
|
|
directory, in case you added attachments yourself.
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
2008-10-07 12:28:21 +00:00
|
|
|
|
o Open current task's attachments.
|
|
|
|
|
O Like \"o\", but force opening in Emacs.
|
|
|
|
|
f Open current task's attachment directory.
|
|
|
|
|
F Like \"f\", but force using dired in Emacs.
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
2008-10-09 10:19:43 +00:00
|
|
|
|
d Delete one attachment, you will be prompted for a file name.
|
2008-10-07 12:28:21 +00:00
|
|
|
|
D Delete all of a task's attachments. A safer way is
|
2009-01-19 07:42:38 +00:00
|
|
|
|
to open the directory in dired and delete from there.
|
|
|
|
|
|
2017-07-09 15:16:24 +00:00
|
|
|
|
s Set a specific attachment directory for this entry or reset to default.
|
2009-01-19 07:42:38 +00:00
|
|
|
|
i Make children of the current entry inherit its attachment directory.")))
|
2008-11-03 12:38:25 +00:00
|
|
|
|
(org-fit-window-to-buffer (get-buffer-window "*Org Attach*"))
|
2018-11-02 01:04:38 +00:00
|
|
|
|
(message "Select command: [acmlyubnzoOfFdD]")
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(setq c (read-char-exclusive))
|
|
|
|
|
(and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*"))))
|
|
|
|
|
(cond
|
|
|
|
|
((memq c '(?a ?\C-a)) (call-interactively 'org-attach-attach))
|
2008-10-07 12:28:21 +00:00
|
|
|
|
((memq c '(?c ?\C-c))
|
|
|
|
|
(let ((org-attach-method 'cp)) (call-interactively 'org-attach-attach)))
|
|
|
|
|
((memq c '(?m ?\C-m))
|
|
|
|
|
(let ((org-attach-method 'mv)) (call-interactively 'org-attach-attach)))
|
|
|
|
|
((memq c '(?l ?\C-l))
|
|
|
|
|
(let ((org-attach-method 'ln)) (call-interactively 'org-attach-attach)))
|
2012-04-12 18:20:39 +00:00
|
|
|
|
((memq c '(?y ?\C-y))
|
2012-08-11 17:10:44 +00:00
|
|
|
|
(let ((org-attach-method 'lns)) (call-interactively 'org-attach-attach)))
|
2017-03-11 00:54:05 +00:00
|
|
|
|
((memq c '(?u ?\C-u))
|
|
|
|
|
(let ((org-attach-method 'url)) (call-interactively 'org-attach-url)))
|
2018-11-02 01:04:38 +00:00
|
|
|
|
((eq c ?b) (call-interactively 'org-attach-buffer))
|
2008-10-07 12:28:21 +00:00
|
|
|
|
((memq c '(?n ?\C-n)) (call-interactively 'org-attach-new))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
((memq c '(?z ?\C-z)) (call-interactively 'org-attach-sync))
|
|
|
|
|
((memq c '(?o ?\C-o)) (call-interactively 'org-attach-open))
|
|
|
|
|
((eq c ?O) (call-interactively 'org-attach-open-in-emacs))
|
|
|
|
|
((memq c '(?f ?\C-f)) (call-interactively 'org-attach-reveal))
|
|
|
|
|
((memq c '(?F)) (call-interactively 'org-attach-reveal-in-emacs))
|
2008-10-09 10:19:43 +00:00
|
|
|
|
((memq c '(?d ?\C-d)) (call-interactively
|
|
|
|
|
'org-attach-delete-one))
|
|
|
|
|
((eq c ?D) (call-interactively 'org-attach-delete-all))
|
|
|
|
|
((eq c ?q) (message "Abort"))
|
2009-01-19 07:42:38 +00:00
|
|
|
|
((memq c '(?s ?\C-s)) (call-interactively
|
|
|
|
|
'org-attach-set-directory))
|
|
|
|
|
((memq c '(?i ?\C-i)) (call-interactively
|
|
|
|
|
'org-attach-set-inherit))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(t (error "No such attachment command %c" c))))))
|
|
|
|
|
|
|
|
|
|
(defun org-attach-dir (&optional create-if-not-exists-p)
|
|
|
|
|
"Return the directory associated with the current entry.
|
2009-01-19 07:42:38 +00:00
|
|
|
|
This first checks for a local property ATTACH_DIR, and then for an inherited
|
|
|
|
|
property ATTACH_DIR_INHERIT. If neither exists, the default mechanism
|
|
|
|
|
using the entry ID will be invoked to access the unique directory for the
|
|
|
|
|
current entry.
|
2008-10-01 07:25:18 +00:00
|
|
|
|
If the directory does not exist and CREATE-IF-NOT-EXISTS-P is non-nil,
|
2009-01-19 07:42:38 +00:00
|
|
|
|
the directory and (if necessary) the corresponding ID will be created."
|
2015-11-13 22:51:28 +00:00
|
|
|
|
(let (attach-dir uuid)
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(setq org-attach-inherited (org-entry-get nil "ATTACH_DIR_INHERIT"))
|
|
|
|
|
(cond
|
|
|
|
|
((setq attach-dir (org-entry-get nil "ATTACH_DIR"))
|
|
|
|
|
(org-attach-check-absolute-path attach-dir))
|
|
|
|
|
((and org-attach-allow-inheritance
|
2015-11-13 22:51:28 +00:00
|
|
|
|
(org-entry-get nil "ATTACH_DIR_INHERIT" t))
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(setq attach-dir
|
2015-11-13 22:51:28 +00:00
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(if (marker-position org-entry-property-inherited-from)
|
|
|
|
|
(goto-char org-entry-property-inherited-from)
|
|
|
|
|
(org-back-to-heading t))
|
|
|
|
|
(let (org-attach-allow-inheritance)
|
|
|
|
|
(org-attach-dir create-if-not-exists-p))))
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(org-attach-check-absolute-path attach-dir)
|
|
|
|
|
(setq org-attach-inherited t))
|
2015-11-13 22:51:28 +00:00
|
|
|
|
(t ; use the ID
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(org-attach-check-absolute-path nil)
|
|
|
|
|
(setq uuid (org-id-get (point) create-if-not-exists-p))
|
|
|
|
|
(when (or uuid create-if-not-exists-p)
|
|
|
|
|
(unless uuid (error "ID retrieval/creation failed"))
|
|
|
|
|
(setq attach-dir (expand-file-name
|
|
|
|
|
(format "%s/%s"
|
|
|
|
|
(substring uuid 0 2)
|
|
|
|
|
(substring uuid 2))
|
|
|
|
|
(expand-file-name org-attach-directory))))))
|
|
|
|
|
(when attach-dir
|
|
|
|
|
(if (and create-if-not-exists-p
|
|
|
|
|
(not (file-directory-p attach-dir)))
|
|
|
|
|
(make-directory attach-dir t))
|
|
|
|
|
(and (file-exists-p attach-dir)
|
|
|
|
|
attach-dir))))
|
|
|
|
|
|
|
|
|
|
(defun org-attach-check-absolute-path (dir)
|
2009-11-12 12:39:29 +00:00
|
|
|
|
"Check if we have enough information to root the attachment directory.
|
2009-01-19 07:42:38 +00:00
|
|
|
|
When DIR is given, check also if it is already absolute. Otherwise,
|
|
|
|
|
assume that it will be relative, and check if `org-attach-directory' is
|
|
|
|
|
absolute, or if at least the current buffer has a file name.
|
|
|
|
|
Throw an error if we cannot root the directory."
|
|
|
|
|
(or (and dir (file-name-absolute-p dir))
|
|
|
|
|
(file-name-absolute-p org-attach-directory)
|
|
|
|
|
(buffer-file-name (buffer-base-buffer))
|
2009-09-24 08:09:33 +00:00
|
|
|
|
(error "Need absolute `org-attach-directory' to attach in buffers without filename")))
|
2009-01-19 07:42:38 +00:00
|
|
|
|
|
2017-07-09 15:16:24 +00:00
|
|
|
|
(defun org-attach-set-directory (&optional arg)
|
|
|
|
|
"Set the ATTACH_DIR node property and ask to move files there.
|
2009-01-19 07:42:38 +00:00
|
|
|
|
The property defines the directory that is used for attachments
|
2017-07-09 15:16:24 +00:00
|
|
|
|
of the entry. When called with `\\[universal-argument]', reset \
|
|
|
|
|
the directory to
|
|
|
|
|
the default ID based one."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(let ((old (org-attach-dir))
|
|
|
|
|
(new
|
|
|
|
|
(progn
|
|
|
|
|
(if arg (org-entry-delete nil "ATTACH_DIR")
|
|
|
|
|
(let ((dir (read-directory-name
|
|
|
|
|
"Attachment directory: "
|
|
|
|
|
(org-entry-get nil
|
|
|
|
|
"ATTACH_DIR"
|
|
|
|
|
(and org-attach-allow-inheritance t)))))
|
|
|
|
|
(org-entry-put nil "ATTACH_DIR" dir)))
|
|
|
|
|
(org-attach-dir t))))
|
|
|
|
|
(unless (or (string= old new)
|
|
|
|
|
(not old))
|
|
|
|
|
(when (yes-or-no-p "Copy over attachments from old directory? ")
|
|
|
|
|
(copy-directory old new t nil t))
|
|
|
|
|
(when (yes-or-no-p (concat "Delete " old))
|
|
|
|
|
(delete-directory old t)))))
|
2009-01-19 07:42:38 +00:00
|
|
|
|
|
|
|
|
|
(defun org-attach-set-inherit ()
|
|
|
|
|
"Set the ATTACH_DIR_INHERIT property of the current entry.
|
|
|
|
|
The property defines the directory that is used for attachments
|
|
|
|
|
of the entry and any children that do not explicitly define (by setting
|
|
|
|
|
the ATTACH_DIR property) their own attachment directory."
|
|
|
|
|
(interactive)
|
|
|
|
|
(org-entry-put nil "ATTACH_DIR_INHERIT" "t")
|
|
|
|
|
(message "Children will inherit attachment directory"))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
2016-02-06 12:16:52 +00:00
|
|
|
|
(defun org-attach-use-annex ()
|
|
|
|
|
"Return non-nil if git annex can be used."
|
|
|
|
|
(let ((git-dir (vc-git-root (expand-file-name org-attach-directory))))
|
|
|
|
|
(and org-attach-git-annex-cutoff
|
|
|
|
|
(or (file-exists-p (expand-file-name "annex" git-dir))
|
|
|
|
|
(file-exists-p (expand-file-name ".git/annex" git-dir))))))
|
|
|
|
|
|
|
|
|
|
(defun org-attach-annex-get-maybe (path)
|
|
|
|
|
"Call git annex get PATH (via shell) if using git annex.
|
|
|
|
|
Signals an error if the file content is not available and it was not retrieved."
|
2018-03-26 03:11:09 +00:00
|
|
|
|
(let* ((default-directory (expand-file-name org-attach-directory))
|
|
|
|
|
(path-relative (file-relative-name path)))
|
2016-02-26 20:44:46 +00:00
|
|
|
|
(when (and (org-attach-use-annex)
|
|
|
|
|
(not
|
|
|
|
|
(string-equal
|
|
|
|
|
"found"
|
|
|
|
|
(shell-command-to-string
|
|
|
|
|
(format "git annex find --format=found --in=here %s"
|
|
|
|
|
(shell-quote-argument path-relative))))))
|
|
|
|
|
(let ((should-get
|
|
|
|
|
(if (eq org-attach-annex-auto-get 'ask)
|
|
|
|
|
(y-or-n-p (format "Run git annex get %s? " path-relative))
|
|
|
|
|
org-attach-annex-auto-get)))
|
|
|
|
|
(if should-get
|
|
|
|
|
(progn (message "Running git annex get \"%s\"." path-relative)
|
|
|
|
|
(call-process "git" nil nil nil "annex" "get" path-relative))
|
|
|
|
|
(error "File %s stored in git annex but it is not available, and was not retrieved"
|
|
|
|
|
path))))))
|
2016-02-06 12:16:52 +00:00
|
|
|
|
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(defun org-attach-commit ()
|
2008-10-09 10:19:43 +00:00
|
|
|
|
"Commit changes to git if `org-attach-directory' is properly initialized.
|
|
|
|
|
This checks for the existence of a \".git\" directory in that directory."
|
2013-08-31 13:58:12 +00:00
|
|
|
|
(let* ((dir (expand-file-name org-attach-directory))
|
|
|
|
|
(git-dir (vc-git-root dir))
|
2016-02-06 12:16:52 +00:00
|
|
|
|
(use-annex (org-attach-use-annex))
|
2013-08-31 13:58:12 +00:00
|
|
|
|
(changes 0))
|
2013-12-06 14:22:50 +00:00
|
|
|
|
(when (and git-dir (executable-find "git"))
|
2010-03-24 21:17:28 +00:00
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(cd dir)
|
2016-02-06 12:16:52 +00:00
|
|
|
|
(dolist (new-or-modified
|
|
|
|
|
(split-string
|
|
|
|
|
(shell-command-to-string
|
|
|
|
|
"git ls-files -zmo --exclude-standard") "\0" t))
|
|
|
|
|
(if (and use-annex
|
2018-09-24 01:30:46 +00:00
|
|
|
|
(>= (file-attribute-size (file-attributes new-or-modified))
|
2016-02-06 12:16:52 +00:00
|
|
|
|
org-attach-git-annex-cutoff))
|
|
|
|
|
(call-process "git" nil nil nil "annex" "add" new-or-modified)
|
|
|
|
|
(call-process "git" nil nil nil "add" new-or-modified))
|
2016-07-25 13:54:06 +00:00
|
|
|
|
(cl-incf changes))
|
2012-10-20 14:47:01 +00:00
|
|
|
|
(dolist (deleted
|
|
|
|
|
(split-string
|
|
|
|
|
(shell-command-to-string "git ls-files -z --deleted") "\0" t))
|
|
|
|
|
(call-process "git" nil nil nil "rm" deleted)
|
2016-07-25 13:54:06 +00:00
|
|
|
|
(cl-incf changes))
|
2012-10-20 14:47:01 +00:00
|
|
|
|
(when (> changes 0)
|
|
|
|
|
(shell-command "git commit -m 'Synchronized attachments'"))))))
|
2008-12-04 14:33:43 +00:00
|
|
|
|
|
2008-10-06 07:38:50 +00:00
|
|
|
|
(defun org-attach-tag (&optional off)
|
2008-10-09 10:19:43 +00:00
|
|
|
|
"Turn the autotag on or (if OFF is set) off."
|
2008-10-06 07:38:50 +00:00
|
|
|
|
(when org-attach-auto-tag
|
|
|
|
|
(save-excursion
|
|
|
|
|
(org-back-to-heading t)
|
|
|
|
|
(org-toggle-tag org-attach-auto-tag (if off 'off 'on)))))
|
|
|
|
|
|
|
|
|
|
(defun org-attach-untag ()
|
|
|
|
|
"Turn the autotag off."
|
|
|
|
|
(org-attach-tag 'off))
|
|
|
|
|
|
2011-03-03 10:17:55 +00:00
|
|
|
|
(defun org-attach-store-link (file)
|
|
|
|
|
"Add a link to `org-stored-link' when attaching a file.
|
|
|
|
|
Only do this when `org-attach-store-link-p' is non-nil."
|
|
|
|
|
(setq org-stored-links
|
|
|
|
|
(cons (list (org-attach-expand-link file)
|
|
|
|
|
(file-name-nondirectory file))
|
|
|
|
|
org-stored-links)))
|
|
|
|
|
|
2017-03-11 00:54:05 +00:00
|
|
|
|
(defun org-attach-url (url)
|
|
|
|
|
(interactive "MURL of the file to attach: \n")
|
|
|
|
|
(org-attach-attach url))
|
|
|
|
|
|
2018-11-02 01:04:38 +00:00
|
|
|
|
(defun org-attach-buffer (buffer-name)
|
|
|
|
|
"Attach BUFFER-NAME's contents to current task.
|
|
|
|
|
BUFFER-NAME is a string. Signals a `file-already-exists' error
|
|
|
|
|
if it would overwrite an existing filename."
|
|
|
|
|
(interactive "bBuffer whose contents should be attached: ")
|
|
|
|
|
(let ((output (expand-file-name buffer-name (org-attach-dir t))))
|
|
|
|
|
(when (file-exists-p output)
|
|
|
|
|
(signal 'file-already-exists (list "File exists" output)))
|
|
|
|
|
(when (and org-attach-file-list-property (not org-attach-inherited))
|
|
|
|
|
(org-entry-add-to-multivalued-property
|
|
|
|
|
(point) org-attach-file-list-property buffer-name))
|
|
|
|
|
(org-attach-tag)
|
|
|
|
|
(with-temp-file output
|
|
|
|
|
(insert-buffer-substring buffer-name))))
|
|
|
|
|
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(defun org-attach-attach (file &optional visit-dir method)
|
2008-10-09 10:19:43 +00:00
|
|
|
|
"Move/copy/link FILE into the attachment directory of the current task.
|
|
|
|
|
If VISIT-DIR is non-nil, visit the directory with dired.
|
2017-03-11 00:54:05 +00:00
|
|
|
|
METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
|
2012-04-12 18:20:39 +00:00
|
|
|
|
`org-attach-method'."
|
2017-05-09 15:30:18 +00:00
|
|
|
|
(interactive
|
|
|
|
|
(list
|
|
|
|
|
(read-file-name "File to keep as an attachment:"
|
|
|
|
|
(or (progn
|
|
|
|
|
(require 'dired-aux)
|
|
|
|
|
(dired-dwim-target-directory))
|
|
|
|
|
default-directory))
|
|
|
|
|
current-prefix-arg
|
|
|
|
|
nil))
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(setq method (or method org-attach-method))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(let ((basename (file-name-nondirectory file)))
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(when (and org-attach-file-list-property (not org-attach-inherited))
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(org-entry-add-to-multivalued-property
|
|
|
|
|
(point) org-attach-file-list-property basename))
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(let* ((attach-dir (org-attach-dir t))
|
2017-05-09 15:30:18 +00:00
|
|
|
|
(fname (expand-file-name basename attach-dir)))
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(cond
|
2017-05-09 15:30:18 +00:00
|
|
|
|
((eq method 'mv) (rename-file file fname))
|
|
|
|
|
((eq method 'cp) (copy-file file fname))
|
2012-04-12 18:20:39 +00:00
|
|
|
|
((eq method 'ln) (add-name-to-file file fname))
|
2017-03-11 00:54:05 +00:00
|
|
|
|
((eq method 'lns) (make-symbolic-link file fname))
|
|
|
|
|
((eq method 'url) (url-copy-file file fname)))
|
2016-02-10 22:37:03 +00:00
|
|
|
|
(when org-attach-commit
|
2017-05-09 15:30:18 +00:00
|
|
|
|
(org-attach-commit))
|
2008-10-06 07:38:50 +00:00
|
|
|
|
(org-attach-tag)
|
2011-03-10 10:25:17 +00:00
|
|
|
|
(cond ((eq org-attach-store-link-p 'attached)
|
2017-05-09 15:30:18 +00:00
|
|
|
|
(org-attach-store-link fname))
|
|
|
|
|
((eq org-attach-store-link-p t)
|
|
|
|
|
(org-attach-store-link file)))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(if visit-dir
|
2017-05-09 15:30:18 +00:00
|
|
|
|
(dired attach-dir)
|
2017-05-09 15:51:32 +00:00
|
|
|
|
(message "File %S is now a task attachment." basename)))))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(defun org-attach-attach-cp ()
|
2008-10-09 10:19:43 +00:00
|
|
|
|
"Attach a file by copying it."
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(let ((org-attach-method 'cp)) (call-interactively 'org-attach-attach)))
|
|
|
|
|
(defun org-attach-attach-mv ()
|
2008-10-09 10:19:43 +00:00
|
|
|
|
"Attach a file by moving (renaming) it."
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(let ((org-attach-method 'mv)) (call-interactively 'org-attach-attach)))
|
|
|
|
|
(defun org-attach-attach-ln ()
|
2008-10-09 10:19:43 +00:00
|
|
|
|
"Attach a file by creating a hard link to it.
|
|
|
|
|
Beware that this does not work on systems that do not support hard links.
|
|
|
|
|
On some systems, this apparently does copy the file instead."
|
|
|
|
|
(interactive)
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(let ((org-attach-method 'ln)) (call-interactively 'org-attach-attach)))
|
2012-04-12 18:20:39 +00:00
|
|
|
|
(defun org-attach-attach-lns ()
|
|
|
|
|
"Attach a file by creating a symbolic link to it.
|
|
|
|
|
|
|
|
|
|
Beware that this does not work on systems that do not support symbolic links.
|
|
|
|
|
On some systems, this apparently does copy the file instead."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((org-attach-method 'lns)) (call-interactively 'org-attach-attach)))
|
2008-10-07 12:28:21 +00:00
|
|
|
|
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(defun org-attach-new (file)
|
|
|
|
|
"Create a new attachment FILE for the current task.
|
|
|
|
|
The attachment is created as an Emacs buffer."
|
|
|
|
|
(interactive "sCreate attachment named: ")
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(when (and org-attach-file-list-property (not org-attach-inherited))
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(org-entry-add-to-multivalued-property
|
|
|
|
|
(point) org-attach-file-list-property file))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(let ((attach-dir (org-attach-dir t)))
|
2008-10-06 07:38:50 +00:00
|
|
|
|
(org-attach-tag)
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(find-file (expand-file-name file attach-dir))
|
|
|
|
|
(message "New attachment %s" file)))
|
|
|
|
|
|
2008-10-09 10:19:43 +00:00
|
|
|
|
(defun org-attach-delete-one (&optional file)
|
|
|
|
|
"Delete a single attachment."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let* ((attach-dir (org-attach-dir t))
|
|
|
|
|
(files (org-attach-file-list attach-dir))
|
|
|
|
|
(file (or file
|
2015-12-22 13:49:23 +00:00
|
|
|
|
(completing-read
|
2008-10-09 10:19:43 +00:00
|
|
|
|
"Delete attachment: "
|
|
|
|
|
(mapcar (lambda (f)
|
|
|
|
|
(list (file-name-nondirectory f)))
|
|
|
|
|
files)))))
|
|
|
|
|
(setq file (expand-file-name file attach-dir))
|
|
|
|
|
(unless (file-exists-p file)
|
|
|
|
|
(error "No such attachment: %s" file))
|
2010-03-24 21:19:55 +00:00
|
|
|
|
(delete-file file)
|
2017-06-17 09:34:02 +00:00
|
|
|
|
(when org-attach-commit
|
|
|
|
|
(org-attach-commit))))
|
2008-10-09 10:19:43 +00:00
|
|
|
|
|
|
|
|
|
(defun org-attach-delete-all (&optional force)
|
2008-10-01 07:25:18 +00:00
|
|
|
|
"Delete all attachments from the current task.
|
2008-10-09 10:19:43 +00:00
|
|
|
|
This actually deletes the entire attachment directory.
|
2008-10-01 07:25:18 +00:00
|
|
|
|
A safer way is to open the directory in dired and delete from there."
|
2008-10-09 10:19:43 +00:00
|
|
|
|
(interactive "P")
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(when (and org-attach-file-list-property (not org-attach-inherited))
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(org-entry-delete (point) org-attach-file-list-property))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(let ((attach-dir (org-attach-dir)))
|
2008-12-04 14:33:43 +00:00
|
|
|
|
(when
|
2008-10-09 10:19:43 +00:00
|
|
|
|
(and attach-dir
|
|
|
|
|
(or force
|
|
|
|
|
(y-or-n-p "Are you sure you want to remove all attachments of this entry? ")))
|
|
|
|
|
(shell-command (format "rm -fr %s" attach-dir))
|
|
|
|
|
(message "Attachment directory removed")
|
2017-06-17 09:34:02 +00:00
|
|
|
|
(when org-attach-commit
|
|
|
|
|
(org-attach-commit))
|
2008-10-09 10:19:43 +00:00
|
|
|
|
(org-attach-untag))))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
|
|
|
|
(defun org-attach-sync ()
|
2008-10-09 10:19:43 +00:00
|
|
|
|
"Synchronize the current tasks with its attachments.
|
2008-10-01 07:25:18 +00:00
|
|
|
|
This can be used after files have been added externally."
|
|
|
|
|
(interactive)
|
2017-06-17 09:34:02 +00:00
|
|
|
|
(when org-attach-commit
|
|
|
|
|
(org-attach-commit))
|
2009-01-19 07:42:38 +00:00
|
|
|
|
(when (and org-attach-file-list-property (not org-attach-inherited))
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(org-entry-delete (point) org-attach-file-list-property))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(let ((attach-dir (org-attach-dir)))
|
|
|
|
|
(when attach-dir
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(let ((files (org-attach-file-list attach-dir)))
|
2017-11-10 18:35:35 +00:00
|
|
|
|
(org-attach-tag (not files))
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(when org-attach-file-list-property
|
|
|
|
|
(dolist (file files)
|
2014-03-18 16:17:41 +00:00
|
|
|
|
(unless (string-match "^\\.\\.?\\'" file)
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(org-entry-add-to-multivalued-property
|
|
|
|
|
(point) org-attach-file-list-property file))))))))
|
|
|
|
|
|
|
|
|
|
(defun org-attach-file-list (dir)
|
|
|
|
|
"Return a list of files in the attachment directory.
|
2014-03-18 16:17:41 +00:00
|
|
|
|
This ignores files ending in \"~\"."
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(delq nil
|
2014-03-18 16:17:41 +00:00
|
|
|
|
(mapcar (lambda (x) (if (string-match "^\\.\\.?\\'" x) nil x))
|
2008-10-08 12:59:14 +00:00
|
|
|
|
(directory-files dir nil "[^~]\\'"))))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
2009-10-30 08:08:50 +00:00
|
|
|
|
(defun org-attach-reveal (&optional if-exists)
|
2012-12-12 18:09:58 +00:00
|
|
|
|
"Show the attachment directory of the current task.
|
|
|
|
|
This will attempt to use an external program to show the directory."
|
2009-10-30 08:08:50 +00:00
|
|
|
|
(interactive "P")
|
|
|
|
|
(let ((attach-dir (org-attach-dir (not if-exists))))
|
|
|
|
|
(and attach-dir (org-open-file attach-dir))))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
|
|
|
|
(defun org-attach-reveal-in-emacs ()
|
2012-12-12 18:09:58 +00:00
|
|
|
|
"Show the attachment directory of the current task in dired."
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(let ((attach-dir (org-attach-dir t)))
|
|
|
|
|
(dired attach-dir)))
|
|
|
|
|
|
|
|
|
|
(defun org-attach-open (&optional in-emacs)
|
|
|
|
|
"Open an attachment of the current task.
|
|
|
|
|
If there are more than one attachment, you will be prompted for the file name.
|
|
|
|
|
This command will open the file using the settings in `org-file-apps'
|
|
|
|
|
and in the system-specific variants of this variable.
|
|
|
|
|
If IN-EMACS is non-nil, force opening in Emacs."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(let* ((attach-dir (org-attach-dir t))
|
2008-10-08 10:46:40 +00:00
|
|
|
|
(files (org-attach-file-list attach-dir))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(file (if (= (length files) 1)
|
|
|
|
|
(car files)
|
2015-12-22 13:49:23 +00:00
|
|
|
|
(completing-read "Open attachment: "
|
2016-02-06 12:16:52 +00:00
|
|
|
|
(mapcar #'list files) nil t)))
|
|
|
|
|
(path (expand-file-name file attach-dir)))
|
|
|
|
|
(org-attach-annex-get-maybe path)
|
|
|
|
|
(org-open-file path in-emacs)))
|
2008-10-01 07:25:18 +00:00
|
|
|
|
|
|
|
|
|
(defun org-attach-open-in-emacs ()
|
|
|
|
|
"Open attachment, force opening in Emacs.
|
|
|
|
|
See `org-attach-open'."
|
2008-10-07 12:28:21 +00:00
|
|
|
|
(interactive)
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(org-attach-open 'in-emacs))
|
|
|
|
|
|
2008-11-05 16:54:59 +00:00
|
|
|
|
(defun org-attach-expand (file)
|
|
|
|
|
"Return the full path to the current entry's attachment file FILE.
|
|
|
|
|
Basically, this adds the path to the attachment directory."
|
|
|
|
|
(expand-file-name file (org-attach-dir)))
|
|
|
|
|
|
|
|
|
|
(defun org-attach-expand-link (file)
|
|
|
|
|
"Return a file link pointing to the current entry's attachment file FILE.
|
|
|
|
|
Basically, this adds the path to the attachment directory, and a \"file:\"
|
|
|
|
|
prefix."
|
|
|
|
|
(concat "file:" (org-attach-expand file)))
|
|
|
|
|
|
2014-10-14 01:51:01 +00:00
|
|
|
|
(defun org-attach-archive-delete-maybe ()
|
|
|
|
|
"Maybe delete subtree attachments when archiving.
|
|
|
|
|
This function is called by `org-archive-hook'. The option
|
|
|
|
|
`org-attach-archive-delete' controls its behavior."
|
2018-08-11 01:22:10 +00:00
|
|
|
|
(when org-attach-archive-delete
|
|
|
|
|
(org-attach-delete-all (not (eq org-attach-archive-delete 'query)))))
|
2014-10-14 01:51:01 +00:00
|
|
|
|
|
2017-11-15 10:25:51 +00:00
|
|
|
|
|
|
|
|
|
;; Attach from dired.
|
|
|
|
|
|
2017-11-15 13:39:26 +00:00
|
|
|
|
;; Add the following lines to the config file to get a binding for
|
|
|
|
|
;; dired-mode.
|
2017-11-15 10:25:51 +00:00
|
|
|
|
|
|
|
|
|
;; (add-hook
|
|
|
|
|
;; 'dired-mode-hook
|
|
|
|
|
;; (lambda ()
|
2017-11-15 13:39:26 +00:00
|
|
|
|
;; (define-key dired-mode-map (kbd "C-c C-x a") #'org-attach-dired-to-subtree))))
|
2017-11-15 10:25:51 +00:00
|
|
|
|
|
2019-02-03 17:00:21 +00:00
|
|
|
|
;;;###autoload
|
2017-11-15 13:39:26 +00:00
|
|
|
|
(defun org-attach-dired-to-subtree (files)
|
2017-11-15 10:25:51 +00:00
|
|
|
|
"Attach FILES marked or current file in dired to subtree in other window.
|
2017-11-15 13:39:26 +00:00
|
|
|
|
Takes the method given in `org-attach-method' for the attach action.
|
2017-11-15 10:25:51 +00:00
|
|
|
|
Precondition: Point must be in a dired buffer.
|
|
|
|
|
Idea taken from `gnus-dired-attach'."
|
|
|
|
|
(interactive
|
2017-11-15 11:21:18 +00:00
|
|
|
|
(list (dired-get-marked-files)))
|
2017-11-15 10:25:51 +00:00
|
|
|
|
(unless (eq major-mode 'dired-mode)
|
|
|
|
|
(user-error "This command must be triggered in a dired buffer."))
|
|
|
|
|
(let ((start-win (selected-window))
|
|
|
|
|
(other-win
|
|
|
|
|
(get-window-with-predicate
|
|
|
|
|
(lambda (window)
|
|
|
|
|
(with-current-buffer (window-buffer window)
|
|
|
|
|
(eq major-mode 'org-mode))))))
|
|
|
|
|
(unless other-win
|
|
|
|
|
(user-error
|
2017-11-15 13:39:26 +00:00
|
|
|
|
"Can't attach to subtree. No window displaying an Org buffer"))
|
2017-11-15 10:25:51 +00:00
|
|
|
|
(select-window other-win)
|
2017-11-15 13:39:26 +00:00
|
|
|
|
(dolist (file files)
|
|
|
|
|
(org-attach-attach file))
|
2019-01-28 08:26:18 +00:00
|
|
|
|
(select-window start-win)
|
|
|
|
|
(when (eq 'mv org-attach-method)
|
|
|
|
|
(revert-buffer))))
|
2017-11-15 10:25:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-14 01:51:01 +00:00
|
|
|
|
(add-hook 'org-archive-hook 'org-attach-archive-delete-maybe)
|
|
|
|
|
|
2008-10-01 07:25:18 +00:00
|
|
|
|
(provide 'org-attach)
|
|
|
|
|
|
2012-10-02 06:50:46 +00:00
|
|
|
|
;; Local variables:
|
|
|
|
|
;; generated-autoload-file: "org-loaddefs.el"
|
|
|
|
|
;; End:
|
|
|
|
|
|
2008-10-01 07:25:18 +00:00
|
|
|
|
;;; org-attach.el ends here
|