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.
This commit is contained in:
Oleh Krehel 2017-05-09 17:30:18 +02:00
parent c801ef0328
commit e23b806bd8
1 changed files with 18 additions and 10 deletions

View File

@ -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. If VISIT-DIR is non-nil, visit the directory with dired.
METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from METHOD may be `cp', `mv', `ln', `lns' or `url' default taken from
`org-attach-method'." `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)) (setq method (or method org-attach-method))
(let ((basename (file-name-nondirectory file))) (let ((basename (file-name-nondirectory file)))
(when (and org-attach-file-list-property (not org-attach-inherited)) (when (and org-attach-file-list-property (not org-attach-inherited))
(org-entry-add-to-multivalued-property (org-entry-add-to-multivalued-property
(point) org-attach-file-list-property basename)) (point) org-attach-file-list-property basename))
(let* ((attach-dir (org-attach-dir t)) (let* ((attach-dir (org-attach-dir t))
(fname (expand-file-name basename attach-dir))) (fname (expand-file-name basename attach-dir)))
(cond (cond
((eq method 'mv) (rename-file file fname)) ((eq method 'mv) (rename-file file fname))
((eq method 'cp) (copy-file file fname)) ((eq method 'cp) (copy-file file fname))
((eq method 'ln) (add-name-to-file file fname)) ((eq method 'ln) (add-name-to-file file fname))
((eq method 'lns) (make-symbolic-link file fname)) ((eq method 'lns) (make-symbolic-link file fname))
((eq method 'url) (url-copy-file file fname))) ((eq method 'url) (url-copy-file file fname)))
(when org-attach-commit (when org-attach-commit
(org-attach-commit)) (org-attach-commit))
(org-attach-tag) (org-attach-tag)
(cond ((eq org-attach-store-link-p 'attached) (cond ((eq org-attach-store-link-p 'attached)
(org-attach-store-link fname)) (org-attach-store-link fname))
((eq org-attach-store-link-p t) ((eq org-attach-store-link-p t)
(org-attach-store-link file))) (org-attach-store-link file)))
(if visit-dir (if visit-dir
(dired attach-dir) (dired attach-dir)
(message "File \"%s\" is now a task attachment." basename))))) (message "File \"%s\" is now a task attachment." basename)))))
(defun org-attach-attach-cp () (defun org-attach-attach-cp ()
"Attach a file by copying it." "Attach a file by copying it."