From b4621122ccfdb962d7611e5c4a232f0080916f05 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 7 Aug 2021 17:31:27 +0200 Subject: [PATCH] Update local copy of plantuml-mode This is now at https://github.com/exot/plantuml-mode/blob/e7c08c588bb4fc4240b1f7556b11aff3bf814bd2/plantuml-mode.el. --- site-lisp/plantuml-mode.el | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/site-lisp/plantuml-mode.el b/site-lisp/plantuml-mode.el index f87a5f5..e02c900 100644 --- a/site-lisp/plantuml-mode.el +++ b/site-lisp/plantuml-mode.el @@ -552,11 +552,7 @@ Uses prefix (as PREFIX) to choose where to display it: (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.") - -(cl-defmethod plantuml-export-string-to-buffer (exec-mode string buffer) - "Fallback method when EXEC-MODE is unknown. -STRING and BUFFER are ignored." +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)) @@ -615,7 +611,15 @@ only the region will be exported." (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 @@ -632,7 +636,13 @@ only the region will be exported." ;; format bit by bit. (with-current-buffer target-buffer (let ((coding-system-for-write 'binary)) - (write-file export-file-name)))) + ;; When exporting, we do not want to display the image in Emacs + ;; itself; as rendering the image in Emacs may take a significant + ;; amount of time, we try to inhibit the automatic image display + ;; by binding `image-mode' to `image-mode-as-text' + (let ((auto-mode-alist nil) + (magic-fallback-mode-alist nil)) + (write-file export-file-name))))) (if errors-during-export (message "Exporting to %s ... failed (see file for details)" export-file-name)