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 <t...@tecosaur.com>
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 &optional 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 (&optional 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

Reply via email to