summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Lindner <mailinglists@xgm.de>2017-07-09 17:16:24 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-07-09 17:16:24 +0200
commitda99ee0fa6b36ae7e7cff8bf02730fe0ce5a9846 (patch)
tree4c0a1d9a4725756f55ad940d3b9c788859c26a7d
parent360109e6c7038a548535bbd69154be67d229c1d1 (diff)
downloadorg-mode-da99ee0fa6b36ae7e7cff8bf02730fe0ce5a9846.tar.gz
org-attach: Make org-attach move directories, when attachment dir changes
* lisp/org-attach.el (org-attach-set-directory): Make org-attach move directories, when attachment dir changes. (org-attach): Update docstring.
-rw-r--r--etc/ORG-NEWS5
-rw-r--r--lisp/org-attach.el32
2 files changed, 29 insertions, 8 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 8875255..12f1635 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -88,6 +88,11 @@ See docstring for details.
*** Change signature for ~org-time-string-to-time~
See docstring for changes.
** New features
+*** ~org-attach~ can move directory contents
+When setting a new directory for an entry, org-attach offers to move
+files over from the old directory. Using a prefix arg will reset the
+directory to old, ID based one.
+
*** New Org duration library
This new library implements tools to read and print time durations in
various formats (e.g., "H:MM", or "1d 2h 3min"...).
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index bfd7106..1249de7 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -189,7 +189,7 @@ d Delete one attachment, you will be prompted for a file name.
D Delete all of a task's attachments. A safer way is
to open the directory in dired and delete from there.
-s Set a specific attachment directory for this entry.
+s Set a specific attachment directory for this entry or reset to default.
i Make children of the current entry inherit its attachment directory.")))
(org-fit-window-to-buffer (get-buffer-window "*Org Attach*"))
(message "Select command: [acmlzoOfFdD]")
@@ -275,14 +275,30 @@ Throw an error if we cannot root the directory."
(buffer-file-name (buffer-base-buffer))
(error "Need absolute `org-attach-directory' to attach in buffers without filename")))
-(defun org-attach-set-directory ()
- "Set the ATTACH_DIR property of the current entry.
+(defun org-attach-set-directory (&optional arg)
+ "Set the ATTACH_DIR node property and ask to move files there.
The property defines the directory that is used for attachments
-of the entry."
- (interactive)
- (let ((dir (org-entry-get nil "ATTACH_DIR")))
- (setq dir (read-directory-name "Attachment directory: " dir))
- (org-entry-put nil "ATTACH_DIR" dir)))
+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)))))
(defun org-attach-set-inherit ()
"Set the ATTACH_DIR_INHERIT property of the current entry.