summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleh Krehel <ohwoeowho@gmail.com>2017-05-09 17:30:18 +0200
committerOleh Krehel <ohwoeowho@gmail.com>2017-05-09 17:30:18 +0200
commite23b806bd867a053e3d0ce26a7bcba6b54dae0e9 (patch)
tree7ea0566bda74fa4ce96b9d078fb5ef149400ebfe
parentc801ef032889ddd282f889606d2df59483ec5bdf (diff)
downloadorg-mode-e23b806bd867a053e3d0ce26a7bcba6b54dae0e9.tar.gz
lisp/org-attach.el (org-attach-attach): Add dired-dwim-target-directory
Use case: have two windows open side-by-side. One has an Org-mode file, the other - a Dired buffer with a file we want to attach. With this change, and user's `dired-dwim-target' setting, the prompt for file to attach will start in the Dired buffer's directory.
-rw-r--r--lisp/org-attach.el28
1 files changed, 18 insertions, 10 deletions
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index da2bd0e..9fad1c3 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -375,30 +375,38 @@ Only do this when `org-attach-store-link-p' is non-nil."
If VISIT-DIR is non-nil, visit the directory with dired.
METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
`org-attach-method'."
- (interactive "fFile to keep as an attachment: \nP")
+ (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))
(setq method (or method org-attach-method))
(let ((basename (file-name-nondirectory file)))
(when (and org-attach-file-list-property (not org-attach-inherited))
(org-entry-add-to-multivalued-property
(point) org-attach-file-list-property basename))
(let* ((attach-dir (org-attach-dir t))
- (fname (expand-file-name basename attach-dir)))
+ (fname (expand-file-name basename attach-dir)))
(cond
- ((eq method 'mv) (rename-file file fname))
- ((eq method 'cp) (copy-file file fname))
+ ((eq method 'mv) (rename-file file fname))
+ ((eq method 'cp) (copy-file file fname))
((eq method 'ln) (add-name-to-file file fname))
((eq method 'lns) (make-symbolic-link file fname))
((eq method 'url) (url-copy-file file fname)))
(when org-attach-commit
- (org-attach-commit))
+ (org-attach-commit))
(org-attach-tag)
(cond ((eq org-attach-store-link-p 'attached)
- (org-attach-store-link fname))
- ((eq org-attach-store-link-p t)
- (org-attach-store-link file)))
+ (org-attach-store-link fname))
+ ((eq org-attach-store-link-p t)
+ (org-attach-store-link file)))
(if visit-dir
- (dired attach-dir)
- (message "File \"%s\" is now a task attachment." basename)))))
+ (dired attach-dir)
+ (message "File \"%s\" is now a task attachment." basename)))))
(defun org-attach-attach-cp ()
"Attach a file by copying it."