2019-06-28 16:53:26 +02:00
|
|
|
;;; lang/org/contrib/dragndrop.el -*- lexical-binding: t; -*-
|
2019-07-09 22:44:51 +02:00
|
|
|
;;;###if (featurep! +dragndrop)
|
2019-06-28 16:53:26 +02:00
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! org-download
|
2019-06-28 16:53:26 +02:00
|
|
|
:commands (org-download-dnd org-download-dnd-base64)
|
|
|
|
:init
|
2019-07-21 23:31:42 +02:00
|
|
|
;; HACK We add these manually so that org-download is truly lazy-loaded
|
2019-07-22 04:27:01 +02:00
|
|
|
(nconcq! dnd-protocol-alist
|
|
|
|
'(("^\\(?:https?\\|ftp\\|file\\|nfs\\):" . +org-dragndrop-download-dnd)
|
|
|
|
("^data:" . org-download-dnd-base64)))
|
2019-06-28 16:53:26 +02:00
|
|
|
(advice-add #'org-download-enable :override #'ignore)
|
|
|
|
:config
|
|
|
|
(setq org-download-image-dir org-attach-directory
|
|
|
|
org-download-heading-lvl nil
|
|
|
|
org-download-timestamp "_%Y%m%d_%H%M%S"
|
|
|
|
org-download-screenshot-method
|
|
|
|
(cond (IS-MAC "screencapture -i %s")
|
|
|
|
(IS-LINUX
|
|
|
|
(cond ((executable-find "maim") "maim -s %s")
|
|
|
|
((executable-find "scrot") "scrot -s %s")))))
|
|
|
|
|
|
|
|
;; Handle non-image files a little differently. Images should be inserted
|
|
|
|
;; as-is, as image previews. Other files, like pdfs or zips, should be linked
|
|
|
|
;; to, with an icon indicating the type of file.
|
2019-07-21 02:38:42 +02:00
|
|
|
(def-advice! +org-dragndrop-insert-link-a (_link filename)
|
|
|
|
"Produces and inserts a link to FILENAME into the document.
|
2019-06-28 16:53:26 +02:00
|
|
|
|
2019-07-21 02:38:42 +02:00
|
|
|
If FILENAME is an image, produce an attach:%s path, otherwise use file:%s (with
|
|
|
|
an file icon produced by `+org-attach--icon')."
|
|
|
|
:override #'org-download-insert-link
|
|
|
|
(if (looking-back "^[ \t]+" (line-beginning-position))
|
|
|
|
(delete-region (match-beginning 0) (match-end 0))
|
|
|
|
(newline))
|
|
|
|
(cond ((image-type-from-file-name filename)
|
|
|
|
(insert
|
|
|
|
(concat (if (= org-download-image-html-width 0) ""
|
|
|
|
(format "#+attr_html: :width %dpx\n" org-download-image-html-width))
|
|
|
|
(if (= org-download-image-latex-width 0) ""
|
|
|
|
(format "#+attr_latex: :width %dcm\n" org-download-image-latex-width))
|
|
|
|
(cond ((file-in-directory-p filename org-attach-directory)
|
|
|
|
(format "[[attach:%s]]" (file-relative-name filename org-attach-directory)))
|
|
|
|
((file-in-directory-p filename org-directory)
|
|
|
|
(format org-download-link-format (file-relative-name filename org-directory)))
|
|
|
|
((format org-download-link-format filename)))))
|
|
|
|
(org-display-inline-images))
|
|
|
|
((insert
|
|
|
|
(format "%s [[./%s][%s]] "
|
|
|
|
(+org-attach--icon filename)
|
|
|
|
(file-relative-name filename (file-name-directory buffer-file-name))
|
|
|
|
(file-name-nondirectory (directory-file-name filename)))))))
|
|
|
|
|
|
|
|
(advice-add #'org-download--dir-2 :override #'ignore)
|
|
|
|
(def-advice! +org-dragndrop-download-fullname-a (path)
|
2019-06-28 16:53:26 +02:00
|
|
|
"Write PATH relative to current file."
|
2019-07-21 02:38:42 +02:00
|
|
|
:filter-return #'org-download--fullname
|
2019-06-28 16:53:26 +02:00
|
|
|
(let ((dir (or (if buffer-file-name (file-name-directory buffer-file-name))
|
|
|
|
default-directory)))
|
|
|
|
(if (file-in-directory-p dir org-directory)
|
|
|
|
(file-relative-name path dir)
|
2019-07-21 02:38:42 +02:00
|
|
|
path))))
|