fix(org): org-download-delete and [[download:...]] links

org-download-delete doesn't accommodate a non-standard value for
org-download-link-format. Now it does.

Close: #6202
Co-authored-by: zrquan <zrquan@users.noreply.github.com>
This commit is contained in:
Henrik Lissner 2022-06-21 18:40:51 +02:00
parent 7ca50e0ce8
commit 1f4b9b73fc
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -56,6 +56,26 @@
(file-relative-name path org-download-image-dir)
path)))
(defadvice! +org--fix-org-download-delete-a (fn beg end &optional times)
"Fix `org-download-delete' for a non-standard `org-download-link-format'."
:around #'org-download--delete
(save-excursion
(save-match-data
(goto-char beg)
(let ((times (or times most-positive-fixnum))
(linkname
(or (and (string-match "\\[\\[\\(\\w+\\):" org-download-link-format)
(match-string 1 org-download-link-format))
"file")))
(while (and (>= (cl-decf times) 0)
(re-search-forward (format "\\[\\[%s:\\([^]]*\\)\\]\\]"
(regexp-quote linkname))
end t))
(let ((str (match-string-no-properties 2)))
(delete-region beg (match-end 0))
(when (file-exists-p str)
(delete-file str))))))))
(defadvice! +org--dragndrop-then-display-inline-images-a (_link filename)
:after #'org-download-insert-link
(when (image-type-from-file-name filename)