 
     (message "Exporting to %s ..." export-file-name)
 
-    (let ((target-buffer (generate-new-buffer " *temp*")))
+    ;; If there's already a buffer visiting that file, use that for the export;
+    ;; otherwise create a new buffer.
+    (let ((target-buffer (or (find-buffer-visiting export-file-name)
+                             (generate-new-buffer " *temp*"))))
+      ;; When the buffer is in image-mode, erasing it's contents is not
+      ;; possible, even when disabling `read-only-mode' explicitly.  Let's just
+      ;; switch to `fundamental-mode' to keep things simple.
+      (with-current-buffer target-buffer
+        (fundamental-mode))
       ;; We do not use `with-temp-buffer' here, as we want to stay in the
       ;; current buffer containing the plantuml diagram.  The reason for this is
       ;; that `planumlt-output-type' is local to the current buffer, and

      ;; format bit by bit.
      (with-current-buffer target-buffer
        (let ((coding-system-for-write 'binary))
          (write-file export-file-name))))

    (if errors-during-export
        (message "Exporting to %s ... failed (see file for details)" export-file-name)

(cl-defgeneric plantuml-export-string-to-buffer (exec-mode string buffer)
  "Export STRING to plantuml diagram using the given EXEC-MODE.
Use BUFFER to write the diagram to, clearing it first.  This
buffer can be written to a file or be displayed directly."
  (ignore string buffer)
  (user-error "Exporting with exec-mode %s is not supported (yet)" exec-mode))

