From d7b5c19daa4aece68c8ea97aa414fd4d4ec989df Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Thu, 13 Jun 2024 18:01:37 +0200 Subject: [PATCH] DnD: Create directory when `org-yank-image-save-method' is a directory * lisp/org.el (org--dnd-attach-file): Make sure that target directory is created before copying file when `org-yank-image-save-method' is set to specific directory (not 'attach). Reported-by: ISouthRain Link: https://orgmode.org/list/tencent_AABB2DEBF7ABFBC795348C288E0EBFCFDD0A@qq.com --- lisp/org.el | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 1698399c4..795a4d51b 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20941,15 +20941,18 @@ SEPARATOR is the string to insert after each link." ('private (or org-yank-dnd-default-attach-method org-attach-method))))) (if separatep - (funcall - (pcase method - ('cp #'copy-file) - ('mv #'rename-file) - ('ln #'add-name-to-file) - ('lns #'make-symbolic-link)) - filename - (expand-file-name (file-name-nondirectory filename) - org-yank-image-save-method)) + (progn + (unless (file-directory-p org-yank-image-save-method) + (make-directory org-yank-image-save-method t)) + (funcall + (pcase method + ('cp #'copy-file) + ('mv #'rename-file) + ('ln #'add-name-to-file) + ('lns #'make-symbolic-link)) + filename + (expand-file-name (file-name-nondirectory filename) + org-yank-image-save-method))) (org-attach-attach filename nil method)) (insert (org-link-make-string