From mboxrd@z Thu Jan 1 00:00:00 1970 From: "briangpowell ." Subject: Re: Displaying remote images Date: Mon, 2 Dec 2019 17:39:31 -0500 Message-ID: References: <8736e8sza3.fsf@gmail.com> <87tv6nsaqh.fsf@gmail.com> <871rtmbhia.fsf@alphaville.usersys.redhat.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000746c510598c041bb" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:47784) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibuMC-0007bK-C3 for emacs-orgmode@gnu.org; Mon, 02 Dec 2019 17:39:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibuM8-0000zq-RI for emacs-orgmode@gnu.org; Mon, 02 Dec 2019 17:39:51 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:39201) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ibuM7-0000xI-0K for emacs-orgmode@gnu.org; Mon, 02 Dec 2019 17:39:47 -0500 Received: by mail-wm1-x332.google.com with SMTP id s14so1342479wmh.4 for ; Mon, 02 Dec 2019 14:39:44 -0800 (PST) In-Reply-To: <871rtmbhia.fsf@alphaville.usersys.redhat.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.org@gnu.org Sender: "Emacs-orgmode" To: Nick Dokos Cc: emacs-orgmode --000000000000746c510598c041bb Content-Type: text/plain; charset="UTF-8" * As always I much agree with Nick, looks like a great patch ** Meanwhile, this will read your R output and stick it at the end of the line & and show it all-at-once elisp:(progn (shell-command "rsync -a BlahRemoteHost:/blah-R-output.png /tmp")(sleep-for 3)(iimage-mode))]] /tmp/blah-R-output.png <-[The .png file showed up right here--no brackets necessary--but name of the file is] *** RSync may be replaced by SCP for sure On Mon, Dec 2, 2019 at 3:29 PM Nick Dokos wrote: > Jack Kamm writes: > > > I've attached a patch which implements displaying remote images. > > > >> This is a longstanding problem, and there was an attempt to patch it in > >> 2014, but the patch was never accepted: > >> https://lists.gnu.org/archive/html/emacs-orgmode/2014-11/msg00583.html > > > > Compared to the previous attempt from 2014, I think my patch is simpler > > -- it doesn't require creating any temp files. > > > >> The fault might be with image.el rather than with org-mode itself -- > >> for example, when I execute the following elisp, I get the same blank > >> box: > > > > After doing some reading, I learned that image.el doesn't really create > > the image. Instead, create-image simply creates a blank string with a > > text property pointing to the image file location, and the rendering of > > the image gets handled later by the C code (for example, png_load_body() > > in image.c), which doesn't know how to read remote image files. > > > > Since I wasn't comfortable trying to get the C code to read the remote > > file, I instead took the approach used by image-mode.el, which reads the > > remote image file and passes its contents directly to create-image, > > instead of just passing the filename. > > > > From 47120666dad6eb0b6ca716325d7de86924e1d28e Mon Sep 17 00:00:00 2001 > > From: Jack Kamm > > Date: Thu, 28 Nov 2019 17:45:56 -0800 > > Subject: [PATCH] org: display remote images > > > > --- > > lisp/org.el | 13 ++++++++++--- > > 1 file changed, 10 insertions(+), 3 deletions(-) > > > > diff --git a/lisp/org.el b/lisp/org.el > > index 90f222c8b..dc7bcc7aa 100644 > > --- a/lisp/org.el > > +++ b/lisp/org.el > > @@ -16754,13 +16754,20 @@ buffer boundaries with possible narrowing." > > (t nil))) > > (old (get-char-property-and-overlay > > (org-element-property :begin link) > > - 'org-image-overlay))) > > + 'org-image-overlay)) > > + (remote-p (file-remote-p file))) > > (if (and (car-safe old) refresh) > > (image-refresh (overlay-get (cdr old) 'display)) > > - (let ((image (create-image file > > + (let ((image (create-image (if (not remote-p) > > + file > > + (with-temp-buffer > > + > (insert-file-contents file) > > + (string-make-unibyte > > + > (buffer-substring-no-properties > > + (point-min) > (point-max))))) > > (and > (image-type-available-p 'imagemagick) > > width 'imagemagick) > > - nil > > + remote-p > > :width width))) > > (when image > > (let ((ov (make-overlay > > FWIW, looks good to me, but I've only (carefully) read the patch: I have > not actually ran it. > > -- > Nick > > "There are only two hard problems in computer science: cache > invalidation, naming things, and off-by-one errors." -Martin Fowler > > > --000000000000746c510598c041bb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
* As always I much agree with Nick, looks like a grea= t patch

** Meanwhile, this will read your R output= and stick it at the end of the line & and show it all-at-once

elisp:(progn (shell-command "rsync -a BlahRemoteHost:/blah= -R-output.png /tmp")(sleep-for 3)(iimage-mode))]] /tmp/blah-R-output.p= ng <-[The .png file showed up right here--no brackets necessary--but nam= e of the file is]

*** RSync may be replaced by SCP f= or sure


On Mon, Dec 2, 2019 at 3:29 PM Nick Dokos <= ;ndokos@gmail.com> wrote:
Jack Kamm <jackkamm@gmail.com>= writes:

> I've attached a patch which implements displaying remote images. >
>> This is a longstanding problem, and there was an attempt to patch = it in
>> 2014, but the patch was never accepted:
>> https://lists.gnu.org= /archive/html/emacs-orgmode/2014-11/msg00583.html
>
> Compared to the previous attempt from 2014, I think my patch is simple= r
> -- it doesn't require creating any temp files.
>
>> The fault might be with image.el rather than with org-mode itself = --
>> for example, when I execute the following elisp, I get the same bl= ank
>> box:
>
> After doing some reading, I learned that image.el doesn't really c= reate
> the image. Instead, create-image simply creates a blank string with a<= br> > text property pointing to the image file location, and the rendering o= f
> the image gets handled later by the C code (for example, png_load_body= ()
> in image.c), which doesn't know how to read remote image files. >
> Since I wasn't comfortable trying to get the C code to read the re= mote
> file, I instead took the approach used by image-mode.el, which reads t= he
> remote image file and passes its contents directly to create-image, > instead of just passing the filename.
>
> From 47120666dad6eb0b6ca716325d7de86924e1d28e Mon Sep 17 00:00:00 2001=
> From: Jack Kamm <jackkamm@gmail.com>
> Date: Thu, 28 Nov 2019 17:45:56 -0800
> Subject: [PATCH] org: display remote images
>
> ---
>=C2=A0 lisp/org.el | 13 ++++++++++---
>=C2=A0 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/lisp/org.el b/lisp/org.el
> index 90f222c8b..dc7bcc7aa 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -16754,13 +16754,20 @@ buffer boundaries with possible narrowing.&q= uot;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(t nil)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(old (get-char-property-and-overlay
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-element-property :begin link)=
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'org-image-overlay)))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'org-image-overlay))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0(remote-p (file-remote-p file)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(if (and (car-safe old) refresh)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(image-refresh (overlay-get (cdr old) 'display)) > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0(let ((image (create-image file
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0(let ((image (create-image (if (not remote-p)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 file
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (with-temp-buffer
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (insert-file-contents file)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (string-make-unibyte
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0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remote-p
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :width width)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(when image
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(let ((ov (make-overlay

FWIW, looks good to me, but I've only (carefully) read the patch: I hav= e not actually ran it.

--
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler

--000000000000746c510598c041bb--