From e0f61b9043de88161752f34d449ec173e7540202 Mon Sep 17 00:00:00 2001 From: Jack Kamm Date: Sun, 19 Jan 2020 14:08:01 -0800 Subject: [PATCH] org.el: Add inline remote image display * lisp/org.el (org-display-inline-images): Add inline remote image display. Remote image display is controlled by the new option `org-display-remote-inline-images'. --- etc/ORG-NEWS | 6 ++++++ lisp/org.el | 45 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 90e612529..e2c53d043 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -35,6 +35,12 @@ value in call to =java=. After editing a source block, Org will restore the window layout when ~org-src-window-setup~ is set to a value that modifies the layout. +*** Display remote inline images + +Added the capability to display remote images inline. Whether the +images are actually displayed are controlled by the new option +~org-display-remote-inline-images~. + ** New functions *** ~org-columns-toggle-or-columns-quit~ == bound to ~org-columns-toggle-or-columns-quit~ replaces the diff --git a/lisp/org.el b/lisp/org.el index e011ff61e..d6a591a6a 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16739,6 +16739,45 @@ INCLUDE-LINKED is passed to `org-display-inline-images'." ;; For without-x builds. (declare-function image-refresh "image" (spec &optional frame)) +(defcustom org-display-remote-inline-images 'skip + "How to display remote inline images. +Possible values of this option are: + +skip Don't display remote images. +download-always Always download and display remote images. +cache-buffer Display remote images, and open them in separate buffers for + cacheing. Silently update the image buffer when a file + change is detected." + :group 'org-appearance + :package-version '(Org . "9.4") + :type '(choice + (const skip) + (const download-always) + (const cache-buffer)) + :safe #'symbolp) + +(defun org--create-inline-image (file width) + (let* ((remote-p (file-remote-p file)) + (file-or-data + (pcase org-display-remote-inline-images + ((guard (not remote-p)) file) + (`download-always (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-literally file) + (buffer-string))) + (`cache-buffer (let ((revert-without-query '(".*"))) + (with-current-buffer + (find-file-noselect file) + (buffer-string)))) + (`skip nil) + (_ (message "Invalid value of `org-display-remote-inline-images'") + nil)))) + (when file-or-data + (create-image file-or-data + (and (image-type-available-p 'imagemagick) + width 'imagemagick) + remote-p :width width)))) + (defun org-display-inline-images (&optional include-linked refresh beg end) "Display inline images. @@ -16857,11 +16896,7 @@ buffer boundaries with possible narrowing." 'org-image-overlay))) (if (and (car-safe old) refresh) (image-refresh (overlay-get (cdr old) 'display)) - (let ((image (create-image file - (and (image-type-available-p 'imagemagick) - width 'imagemagick) - nil - :width width))) + (let ((image (org--create-inline-image file width))) (when image (let ((ov (make-overlay (org-element-property :begin link) -- 2.25.0