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
|
2020-01-27 17:04:29 -05:00
|
|
|
:commands
|
|
|
|
org-download-dnd
|
|
|
|
org-download-yank
|
|
|
|
org-download-screenshot
|
|
|
|
org-download-dnd-base64
|
2019-06-28 16:53:26 +02:00
|
|
|
:init
|
2019-07-21 23:31:42 +02:00
|
|
|
;; HACK We add these manually so that org-download is truly lazy-loaded
|
2019-10-20 18:45:15 -04:00
|
|
|
(pushnew! dnd-protocol-alist
|
2020-05-07 15:59:26 -04:00
|
|
|
'("^\\(?:https?\\|ftp\\|file\\|nfs\\):" . org-download-dnd)
|
2019-10-20 18:45:15 -04:00
|
|
|
'("^data:" . org-download-dnd-base64))
|
2019-06-28 16:53:26 +02:00
|
|
|
(advice-add #'org-download-enable :override #'ignore)
|
2020-02-19 18:21:24 -05:00
|
|
|
|
|
|
|
(after! org
|
|
|
|
;; A shorter link to attachments
|
2020-04-25 01:23:55 -04:00
|
|
|
(+org-define-basic-link "download" (lambda () (or org-download-image-dir org-attach-id-dir "."))
|
2020-04-24 20:41:56 -04:00
|
|
|
:image-data-fun #'+org-image-file-data-fn
|
|
|
|
:requires 'org-download))
|
2019-06-28 16:53:26 +02:00
|
|
|
:config
|
2020-04-24 20:41:56 -04:00
|
|
|
(unless org-download-image-dir
|
2020-04-25 01:27:25 -04:00
|
|
|
(setq org-download-image-dir org-attach-id-dir))
|
|
|
|
(setq org-download-method 'attach
|
2019-06-28 16:53:26 +02:00
|
|
|
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")
|
2020-03-28 10:13:44 +00:00
|
|
|
((executable-find "scrot") "scrot -s %s")
|
2020-04-25 01:27:25 -04:00
|
|
|
((executable-find "gnome-screenshot") "gnome-screenshot -a -f %s"))))
|
2019-06-28 16:53:26 +02:00
|
|
|
|
2020-04-25 01:27:25 -04:00
|
|
|
org-download-heading-lvl nil
|
|
|
|
org-download-link-format "[[download:%s]]\n"
|
|
|
|
org-download-annotate-function (lambda (_link) "")
|
|
|
|
org-download-link-format-function
|
|
|
|
(lambda (filename)
|
|
|
|
(if (eq org-download-method 'attach)
|
|
|
|
(format "[[attachment:%s]]\n"
|
|
|
|
(org-link-escape
|
|
|
|
(file-relative-name filename (org-attach-dir))))
|
|
|
|
;; Handle non-image files a little differently. Images should be
|
|
|
|
;; inserted as normal with previews. Other files, like pdfs or zips,
|
|
|
|
;; should be linked to, with an icon indicating the type of file.
|
|
|
|
(format (concat (unless (image-type-from-file-name filename)
|
|
|
|
(concat (+org-attach-icon-for filename)
|
|
|
|
" "))
|
|
|
|
org-download-link-format)
|
|
|
|
(org-link-escape
|
|
|
|
(funcall org-download-abbreviate-filename-function filename)))))
|
|
|
|
org-download-abbreviate-filename-function
|
|
|
|
(lambda (path)
|
|
|
|
(if (file-in-directory-p path org-download-image-dir)
|
|
|
|
(file-relative-name path org-download-image-dir)
|
|
|
|
path)))
|
2019-07-21 02:38:42 +02:00
|
|
|
|
2020-04-25 01:27:25 -04:00
|
|
|
(defadvice! +org--dragndrop-then-display-inline-images-a (_link filename)
|
|
|
|
:after #'org-download-insert-link
|
|
|
|
(when (image-type-from-file-name filename)
|
|
|
|
(save-excursion
|
|
|
|
(org-display-inline-images
|
|
|
|
t t
|
|
|
|
(progn (org-back-to-heading t) (point))
|
|
|
|
(progn (org-end-of-subtree t t)
|
|
|
|
(when (and (org-at-heading-p) (not (eobp))) (backward-char 1))
|
|
|
|
(point)))))))
|