From aa34ad1176f4599c5a3c2678806644f16a3d22a2 Mon Sep 17 00:00:00 2001 From: fpi Date: Tue, 23 Jun 2020 15:59:28 +0200 Subject: [PATCH] org.el: Persistently save downloaded inline remote images * lisp/org.el (org--create-inline-image): Save downloaded inline remote images to temporary directory to persist them for future `org-display-inline-images' calls. --- lisp/org.el | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 4d46b4173..7b649d6d0 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16277,10 +16277,22 @@ according to the value of `org-display-remote-inline-images'." (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))) + (`download (let ((new (concat temporary-file-directory + "tramp/" + (file-remote-p file 'host) + (file-local-name file)))) + ;; dont download file if local copy exists & is newer than remote + (if (and (file-exists-p new) + (file-newer-than-file-p new file)) + (with-temp-buffer + (set-buffer-multibyte nil) + (insert-file-contents-literally new) + (buffer-string)) + (with-temp-file new + (make-directory (file-name-directory new) t) + (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)))) -- 2.20.1