Respect org-display-remote-inline-images

Don't download inline previews of URLs if
org-display-remote-inline-images is set to 'skip (its default).
This commit is contained in:
Henrik Lissner 2020-06-28 01:02:55 -04:00
parent 87336c405b
commit 25b240b9b0
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 6 additions and 3 deletions

View file

@ -74,8 +74,9 @@ exist, and `org-link' otherwise."
;;;###autoload ;;;###autoload
(defun +org-http-image-data-fn (protocol link _description) (defun +org-http-image-data-fn (protocol link _description)
"Interpret LINK as an URL to an image file." "Interpret LINK as an URL to an image file."
(when (image-type-from-file-name link) (when (and (image-type-from-file-name link)
(if-let* ((buf (url-retrieve-synchronously (concat protocol ":" link)))) (not (eq org-display-remote-inline-images 'skip)))
(if-let (buf (url-retrieve-synchronously (concat protocol ":" link)))
(with-current-buffer buf (with-current-buffer buf
(goto-char (point-min)) (goto-char (point-min))
(re-search-forward "\r?\n\r?\n" nil t) (re-search-forward "\r?\n\r?\n" nil t)

View file

@ -413,7 +413,9 @@ relative to `org-directory', unless it is an absolute path."
(+org-define-basic-link "doom-docs" 'doom-docs-dir) (+org-define-basic-link "doom-docs" 'doom-docs-dir)
(+org-define-basic-link "doom-modules" 'doom-modules-dir) (+org-define-basic-link "doom-modules" 'doom-modules-dir)
;; Allow inline image previews of http(s)? urls or data uris ;; Allow inline image previews of http(s)? urls or data uris.
;; `+org-http-image-data-fn' will respect `org-display-remote-inline-images'.
(setq org-display-remote-inline-images 'download) ; TRAMP urls
(org-link-set-parameters "http" :image-data-fun #'+org-http-image-data-fn) (org-link-set-parameters "http" :image-data-fun #'+org-http-image-data-fn)
(org-link-set-parameters "https" :image-data-fun #'+org-http-image-data-fn) (org-link-set-parameters "https" :image-data-fun #'+org-http-image-data-fn)
(org-link-set-parameters "img" :image-data-fun #'+org-inline-image-data-fn) (org-link-set-parameters "img" :image-data-fun #'+org-inline-image-data-fn)