emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jack Kamm <jackkamm@gmail.com>
To: Nick Dokos <ndokos@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: Displaying remote images
Date: Sun, 19 Jan 2020 14:17:26 -0800	[thread overview]
Message-ID: <87blqz5bwp.fsf@gmail.com> (raw)
In-Reply-To: <87immsdwpf.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 515 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org.el-Add-inline-remote-image-display.patch --]
[-- Type: text/x-patch, Size: 3769 bytes --]

From 88c37616fc7b910deec34f3013af36ceca8cde9b Mon Sep 17 00:00:00 2001
From: Jack Kamm <jackkamm@gmail.com>
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~
 =<C-c C-c>= 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


  reply	other threads:[~2020-01-19 22:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28 17:09 Displaying remote images Jack Kamm
2019-11-28 21:50 ` briangpowell .
2019-11-29  1:39   ` Jack Kamm
2019-11-29  2:00 ` Jack Kamm
2019-11-29  5:36   ` briangpowell .
2019-12-02 20:27   ` Nick Dokos
2019-12-02 22:39     ` briangpowell .
2019-12-07 14:41     ` Jack Kamm
2020-01-19 22:17       ` Jack Kamm [this message]
2020-01-21 16:39         ` Nicolas Goaziou
2020-01-22 15:31           ` stardiviner
2020-01-25  0:28           ` Jack Kamm
2020-02-01 10:51             ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87blqz5bwp.fsf@gmail.com \
    --to=jackkamm@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=ndokos@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).