>From 88c37616fc7b910deec34f3013af36ceca8cde9b 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 | 53 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 67c3ca2ed..d219ff16a 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..383c9ccaf 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16739,6 +16739,53 @@ 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-warn + "How to display remote inline images. +Possible values of this option are: + +skip-warn Don't display, and emit a message about it. +skip-silent Don't display, and don't warn about it. +download-always Always download and display remote images. +cache-in-buffer Display remote images, and open them in separate buffers for + cache'ing. Silently update the image buffer when a file + change is detected." + :type '(choice + (const skip-warn) + (const skip-silent) + (const download-always) + (const cache-in-buffers)) + :group 'org-appearance) + +(defun org-inline-image--buffer-unibyte () + (string-make-unibyte (buffer-substring-no-properties + (point-min) (point-max)))) + +(defun org-inline-image--create (file width) + (let* ((remote-p (file-remote-p file)) + (file-or-data + (if remote-p + (pcase org-display-remote-inline-images + (`download-always (with-temp-buffer (insert-file-contents file) + (org-inline-image--buffer-unibyte))) + (`cache-in-buffers (let ((revert-without-query '(".*"))) + (with-current-buffer + (find-file-noselect file) + (org-inline-image--buffer-unibyte)))) + (`skip-warn (message + (concat "Set `org-display-remote-inline-images'" + " to display remote images.")) + nil) + (`skip-silent nil) + (_ (message (concat "Invalid value of " + "`org-display-remote-inline-images'")) + nil)) + file))) + (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 +16904,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-inline-image--create file width))) (when image (let ((ov (make-overlay (org-element-property :begin link) -- 2.25.0