Skip to content

Commit

Permalink
fix(org): attachment image inline preview
Browse files Browse the repository at this point in the history
Fix originally proposed by Khoulaiz here:
doomemacs#7222 (comment)

Fix: doomemacs#7222 doomemacs#3185

Co-authored-by: Andreas Sahlbach <Khoulaiz>
  • Loading branch information
45mg authored and hlissner committed Jun 28, 2024
1 parent 42ae401 commit d2efb01
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions modules/lang/org/autoload/org-link.el
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,14 @@ exist, and `org-link' otherwise."
(defun +org-image-file-data-fn (protocol link _description)
"Intepret LINK as an image file path and return its data."
(setq
link (expand-file-name
link (pcase protocol
("download"
(or (if (require 'org-download nil t) org-download-image-dir)
(if (require 'org-attach) org-attach-id-dir)
default-directory))
("attachment"
(require 'org-attach)
org-attach-id-dir)
(_ default-directory))))
link (pcase protocol
("download"
(expand-file-name link (or (if (require 'org-download nil t) org-download-image-dir)
default-directory)))
("attachment"
(require 'org-attach)
(org-attach-expand link))
(_ (expand-file-name link default-directory))))
(when (and (file-exists-p link)
(image-type-from-file-name link))
(with-temp-buffer
Expand Down
2 changes: 1 addition & 1 deletion modules/lang/org/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ relative to `org-directory', unless it is an absolute path."
(add-to-list 'projectile-globally-ignored-directories org-attach-id-dir)))

;; Add inline image previews for attachment links
(org-link-set-parameters "attachment" :image-data-fun #'+org-inline-image-data-fn))
(org-link-set-parameters "attachment" :image-data-fun #'+org-image-file-data-fn))


(defun +org-init-custom-links-h ()
Expand Down

0 comments on commit d2efb01

Please sign in to comment.