Re: [PATCH] Refresh inline plotted images

2021-04-26 Thread Timothy


Applied in dadbd025f.*

Timothy  writes:

> Hi All,
>
> This patch improves the result of running org-plot in the following
> situation
>
> #+plot: ... file:"somefile.png"
>
> [[file:somefile.png]]
>
> Previously, when somefile.png is re-plotted the [[file:]] inline image
> did not refresh. With this patch, after plotting, overlays of the
> replotted image are refreshed.

* As Bastien pointed out to me, I /am/ the org-plot maintainer...



Re: [PATCH] Refresh inline plotted images

2021-04-26 Thread Bastien
Hi Timothy,

Timothy  writes:

> +(defun org-plot/redisplay-img-in-buffer (img-file)
> +  "Find any overlays for IMG-FILE in the current Org buffer, and refresh 
> them."

I guess M-x eldoc RET will choke because the first line of a docstring
should shorter.  Other than this nitpick, please feel free to commit,
as you are org-plot.el maintainer.

Thanks




[PATCH] Refresh inline plotted images

2021-04-23 Thread Timothy
Hi All,

This patch improves the result of running org-plot in the following
situation

#+plot: ... file:"somefile.png"

[[file:somefile.png]]

Previously, when somefile.png is re-plotted the [[file:]] inline image
did not refresh. With this patch, after plotting, overlays of the
replotted image are refreshed.

--
Timothy

>From 5c848c186f2dd4d77b0dcc1035b3c889a4b023a2 Mon Sep 17 00:00:00 2001
From: TEC 
Date: Sat, 24 Apr 2021 12:49:26 +0800
Subject: [PATCH] org-plot: Refresh inline images after plotting

* lisp/org-plot.el (org-plot/redisplay-img-in-buffer): New function
which searches the current Org buffer for overlays of a certain image,
and refreshes those overlays.
(org-plot/gnuplot): Use `org-plot/redisplay-img-in-buffer' after
plotting to redisplay any associated inline images.
---
 lisp/org-plot.el | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 28cff94f2..65bc71074 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -610,6 +610,13 @@ (defun org-plot/gnuplot-script (table data-file num-cols params  prefac
 ",\\\n"
   script)))
 
+(defun org-plot/redisplay-img-in-buffer (img-file)
+  "Find any overlays for IMG-FILE in the current Org buffer, and refresh them."
+  (dolist (img-overlay org-inline-image-overlays)
+(when (string= img-file (plist-get (cdr (overlay-get img-overlay 'display)) :file))
+  (when (file-exists-p img-file)
+(image-refresh (overlay-get img-overlay 'display))
+
 ;;-
 ;; facade functions
 ;;;###autoload
@@ -697,7 +704,10 @@ (defun org-plot/gnuplot ( params)
 	(gnuplot-mode)
 	(gnuplot-send-buffer-to-gnuplot))
   ;; Cleanup.
-  (bury-buffer (get-buffer "*gnuplot*")
+  (bury-buffer (get-buffer "*gnuplot*"))
+  ;; Refresh any displayed images
+  (when (plist-get params :file)
+(org-plot/redisplay-img-in-buffer (expand-file-name (plist-get params :file)))
 
 (provide 'org-plot)
 
-- 
2.31.1