Fix inline previews for download:* links
This commit is contained in:
parent
efee633311
commit
adbe9041ce
2 changed files with 20 additions and 7 deletions
|
@ -19,16 +19,20 @@ links relative to. PLIST is passed to `org-link-set-parameters' verbatim.
|
||||||
Links defined with this will be rendered in the `error' face if the file doesn't
|
Links defined with this will be rendered in the `error' face if the file doesn't
|
||||||
exist, and `org-link' otherwise."
|
exist, and `org-link' otherwise."
|
||||||
(declare (indent 2))
|
(declare (indent 2))
|
||||||
(let ((requires (plist-get plist :requires)))
|
(let ((requires (plist-get plist :requires))
|
||||||
|
(dir-fn (if (functionp dir-var)
|
||||||
|
dir-var
|
||||||
|
(lambda () (symbol-value 'dir-var)))))
|
||||||
(apply #'org-link-set-parameters
|
(apply #'org-link-set-parameters
|
||||||
key
|
key
|
||||||
:complete (lambda ()
|
:complete (lambda ()
|
||||||
(if requires (mapc #'require (doom-enlist requires)))
|
(if requires (mapc #'require (doom-enlist requires)))
|
||||||
(+org--relative-path (+org--read-link-path key (symbol-value dir-var))
|
(+org--relative-path (+org--read-link-path key (funcall dir-fn))
|
||||||
(symbol-value dir-var)))
|
(funcall dir-fn)))
|
||||||
:follow (lambda (link) (find-file (expand-file-name link (symbol-value dir-var))))
|
:follow (lambda (link)
|
||||||
|
(org-link-open-as-file (expand-file-name link (funcall dir-fn)) nil))
|
||||||
:face (lambda (link)
|
:face (lambda (link)
|
||||||
(if (file-exists-p (expand-file-name link (symbol-value dir-var)))
|
(if (file-exists-p (expand-file-name link (funcall dir-fn)))
|
||||||
'org-link
|
'org-link
|
||||||
'error))
|
'error))
|
||||||
(doom-plist-delete plist :requires))))
|
(doom-plist-delete plist :requires))))
|
||||||
|
@ -40,11 +44,20 @@ exist, and `org-link' otherwise."
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +org-image-file-data-fn (protocol link _description)
|
(defun +org-image-file-data-fn (protocol link _description)
|
||||||
"Intepret LINK as an image file path and return its data."
|
"Intepret LINK as an image file path and return its data."
|
||||||
|
(setq
|
||||||
|
link (expand-file-name
|
||||||
|
link
|
||||||
|
(pcase protocol
|
||||||
|
("download" (or org-download-image-dir org-attach-id-dir default-directory))
|
||||||
|
("attachment" org-attach-id-dir)
|
||||||
|
(_ default-directory))))
|
||||||
(when (and (file-exists-p link)
|
(when (and (file-exists-p link)
|
||||||
(image-type-from-file-name link))
|
(image-type-from-file-name link))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
|
(set-buffer-multibyte nil)
|
||||||
|
(setq buffer-file-coding-system 'binary)
|
||||||
(insert-file-contents-literally link)
|
(insert-file-contents-literally link)
|
||||||
(buffer-string))))
|
(buffer-substring-no-properties (point-min) (point-max)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +org-inline-image-data-fn (_protocol link _description)
|
(defun +org-inline-image-data-fn (_protocol link _description)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
(after! org
|
(after! org
|
||||||
;; A shorter link to attachments
|
;; A shorter link to attachments
|
||||||
(+org-define-basic-link "download" 'org-download-image-dir
|
(+org-define-basic-link "download" (lambda () (or org-download-image-dir org-attach-id-dir "."))
|
||||||
:image-data-fun #'+org-image-file-data-fn
|
:image-data-fun #'+org-image-file-data-fn
|
||||||
:requires 'org-download))
|
:requires 'org-download))
|
||||||
:config
|
:config
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue