From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Kamm Subject: Re: Displaying remote images Date: Sun, 19 Jan 2020 14:17:26 -0800 Message-ID: <87blqz5bwp.fsf@gmail.com> References: <8736e8sza3.fsf@gmail.com> <87tv6nsaqh.fsf@gmail.com> <871rtmbhia.fsf@alphaville.usersys.redhat.com> <87immsdwpf.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:50107) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itIti-0003Px-Hg for emacs-orgmode@gnu.org; Sun, 19 Jan 2020 17:18:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itIth-0002yo-8u for emacs-orgmode@gnu.org; Sun, 19 Jan 2020 17:18:22 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:43691) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1itIth-0002y9-1l for emacs-orgmode@gnu.org; Sun, 19 Jan 2020 17:18:21 -0500 Received: by mail-pf1-x432.google.com with SMTP id x6so14802904pfo.10 for ; Sun, 19 Jan 2020 14:18:20 -0800 (PST) In-Reply-To: <87immsdwpf.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane-mx.org@gnu.org Sender: "Emacs-orgmode" To: Nick Dokos , emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi there, Apologies for the delay on this. I've now got a more complete patch for displaying remote images inline. Since downloading many remote images could potentially hang Emacs on a slow connection, I've added an option to control whether remote images are displayed. I've also added an option to cache the remote images by visiting them in Emacs buffers. The default behavior is not to display remote images, but to issue a message that references the option that controls remote image display. Best, Jack --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-Add-inline-remote-image-display.patch >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 --=-=-=--