Browse Source

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.
TEC 4 years ago
parent
commit
dadbd025fa
1 changed files with 11 additions and 1 deletions
  1. 11 1
      lisp/org-plot.el

+ 11 - 1
lisp/org-plot.el

@@ -616,6 +616,13 @@ manner suitable for prepending to a user-specified script."
 				    ",\\\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
@@ -703,7 +710,10 @@ line directly before or after the table."
 	(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)