summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Kamm <jackkamm@gmail.com>2020-02-01 11:50:08 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2020-02-01 11:50:08 +0100
commitdcdb470177661b0fda96b853c4cc3efdb851704d (patch)
tree0ef5df18f03c968c68c2f12c40c884e9b0b4a2b4
parentf704904737150b4f6ea201caefe42a9d04c234d4 (diff)
downloadorg-mode-dcdb470177661b0fda96b853c4cc3efdb851704d.tar.gz
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'.
-rw-r--r--etc/ORG-NEWS6
-rw-r--r--lisp/org.el51
2 files changed, 52 insertions, 5 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index d4505fe..6518c31 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -49,6 +49,12 @@ things in a property drawer before the first headline will make them
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~.
+
*** Babel: new header argument to pass Java command line arguments
Babel Java blocks recognize header argument =:cmdargs= and pass its
diff --git a/lisp/org.el b/lisp/org.el
index 059ca3c..3605460 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16781,6 +16781,51 @@ 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 download and display remote images.
+cache 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 :tag "Ignore remote images" skip)
+ (const :tag "Always display remote images" download)
+ (const :tag "Display and silently update remote images" cache))
+ :safe #'symbolp)
+
+(defun org--create-inline-image (file width)
+ "Create image located at FILE, or return nil.
+WIDTH is the width of the image. The image may not be created
+according to the value of `org-display-remote-inline-images'."
+ (let* ((remote? (file-remote-p file))
+ (file-or-data
+ (pcase org-display-remote-inline-images
+ ((guard (not remote?)) file)
+ (`download (with-temp-buffer
+ (set-buffer-multibyte nil)
+ (insert-file-contents-literally file)
+ (buffer-string)))
+ (`cache (let ((revert-without-query '(".")))
+ (with-current-buffer (find-file-noselect file)
+ (buffer-string))))
+ (`skip nil)
+ (other
+ (message "Invalid value of `org-display-remote-inline-images': %S"
+ other)
+ nil))))
+ (when file-or-data
+ (create-image file-or-data
+ (and (image-type-available-p 'imagemagick)
+ width
+ 'imagemagick)
+ remote?
+ :width width))))
+
(defun org-display-inline-images (&optional include-linked refresh beg end)
"Display inline images.
@@ -16899,11 +16944,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)