From e23b806bd867a053e3d0ce26a7bcba6b54dae0e9 Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Tue, 9 May 2017 17:30:18 +0200 Subject: [PATCH] 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. --- lisp/org-attach.el | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lisp/org-attach.el b/lisp/org-attach.el index da2bd0e99..9fad1c39f 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."