emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Refresh inline plotted images
@ 2021-04-24  4:59 Timothy
  2021-04-26  6:54 ` Bastien
  2021-04-26 14:54 ` Timothy
  0 siblings, 2 replies; 3+ messages in thread
From: Timothy @ 2021-04-24  4:59 UTC (permalink / raw)
  To: org-mode-email

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

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-plot-Refresh-inline-images-after-plotting.patch --]
[-- Type: text/x-patch, Size: 1786 bytes --]

From 5c848c186f2dd4d77b0dcc1035b3c889a4b023a2 Mon Sep 17 00:00:00 2001
From: TEC <tec@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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Refresh inline plotted images
  2021-04-24  4:59 [PATCH] Refresh inline plotted images Timothy
@ 2021-04-26  6:54 ` Bastien
  2021-04-26 14:54 ` Timothy
  1 sibling, 0 replies; 3+ messages in thread
From: Bastien @ 2021-04-26  6:54 UTC (permalink / raw)
  To: Timothy; +Cc: org-mode-email

Hi Timothy,

Timothy <tecosaur@gmail.com> 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Refresh inline plotted images
  2021-04-24  4:59 [PATCH] Refresh inline plotted images Timothy
  2021-04-26  6:54 ` Bastien
@ 2021-04-26 14:54 ` Timothy
  1 sibling, 0 replies; 3+ messages in thread
From: Timothy @ 2021-04-26 14:54 UTC (permalink / raw)
  To: org-mode-email


Applied in dadbd025f.*

Timothy <tecosaur@gmail.com> 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...


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-26 14:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-24  4:59 [PATCH] Refresh inline plotted images Timothy
2021-04-26  6:54 ` Bastien
2021-04-26 14:54 ` Timothy

Code repositories for project(s) associated with this 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).