From 2134815c6c722e1607d93af500522ed5abb78cc1 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Thu, 8 Sep 2022 07:05:43 +0200 Subject: [PATCH 1/2] Reuse the old preview buffer/window such that display-buffer behaves Before, the buffer is killed and then recreated. This causes wrong behavior for display-buffer when display-buffer-reuse-window and display-buffer-same-window is used: the first one fails so the same window is used where the diagram source is situated. Instead, reuse the buffer and its window, so don't kill the buffer, erase it instead. --- plantuml-mode.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index e40ba0d..8014a5e 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -404,7 +404,8 @@ Window is selected according to PREFIX: (when imagep (with-current-buffer buf (image-mode) - (set-buffer-multibyte t))))) + (set-buffer-multibyte t))) + (set-window-point (get-buffer-window buf 'visible) (point-min)))) (defun plantuml-jar-preview-string (prefix string buf) "Preview the diagram from STRING by running the PlantUML JAR. @@ -484,7 +485,8 @@ Put the result into buffer BUF, selecting the window according to PREFIX: to choose where to display it." (let ((b (get-buffer plantuml-preview-buffer))) (when b - (kill-buffer b))) + (with-current-buffer b + (erase-buffer)))) (let* ((imagep (and (display-images-p) (plantuml-is-image-output-p))) From 40af3bde4f248866b1a423d21910c9810c7d96be Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Fri, 14 Oct 2022 16:23:57 +0200 Subject: [PATCH 2/2] Fix subsequent previews image-mode marks buffer parts as read-only, essentially disallowing (erase-buffer). --- plantuml-mode.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index 8014a5e..0f0670b 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -483,10 +483,10 @@ Put the result into buffer BUF, selecting the window according to PREFIX: (defun plantuml-preview-string (prefix string) "Preview diagram from PlantUML sources (as STRING), using prefix (as PREFIX) to choose where to display it." - (let ((b (get-buffer plantuml-preview-buffer))) - (when b - (with-current-buffer b - (erase-buffer)))) + (when-let ((b (get-buffer plantuml-preview-buffer)) + (inhibit-read-only t)) + (with-current-buffer b + (erase-buffer))) (let* ((imagep (and (display-images-p) (plantuml-is-image-output-p)))