Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical split preview #134

Closed
matthjes opened this issue Nov 9, 2020 · 5 comments
Closed

Vertical split preview #134

matthjes opened this issue Nov 9, 2020 · 5 comments
Labels

Comments

@matthjes
Copy link

matthjes commented Nov 9, 2020

Hi,

I'm using Doom Emacs and whenever I'm opening the preview window it is shown with a horizontal split. Is it possible to configure the preview to open in a vertical split (side-by-side)? I've tried C-u C-c C-c to no avail, it always opens in a horizontal split.

@mcraveiro
Copy link

mcraveiro commented Dec 30, 2020

I have a somewhat similar problem, in that I want to have a the preview always displaying on an existing dedicated frame. I thought one way to achieve this would be to avoid the deletion and recreation of the preview buffer, but sadly I could not get it to work:

(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
        (let ((inhibit-read-only t))
          (erase-buffer)))))

  (let* ((imagep (and (display-images-p)
                      (plantuml-is-image-output-p)))
         (buf (get-buffer-create plantuml-preview-buffer))
         (coding-system-for-read (and imagep 'binary))
         (coding-system-for-write (and imagep 'binary)))
    (plantuml-exec-mode-preview-string prefix (plantuml-get-exec-mode) string buf)))

I end up with a blank buffer the second time round. If this worked, we could at least manually determine the screen arrangement and then keep it that way for the duration of the session... I'll keep hacking when I get more time, but any suggestions are welcome.

@mcraveiro
Copy link

Actually, I just bumped into something which could almost solve my problems, but unfortunately does not: previewing on another frame. This is great in that it does make the PlantUML preview go into a different frame, but the trouble is it recreates the frame every time you redo the preview. If only there was a way to keep the frame it would solve my problem.

@mcraveiro
Copy link

mcraveiro commented Feb 5, 2021

OK wow, this was rather painful but I finally got a setup that does what I want it to do. So first I applied the patch you see above [1]. This does the right thing in that it does not kill the preview buffer but instead erases its contents. However, for some reason (which may or may not be a bug in image-mode), once you do that the buffer will not display the SVG image. The contents of the buffer look perfectly fine, but it appears to render as a blank buffer. I think its just that you are not in the right position in the buffer, so I changed this method:

(defun plantuml-update-preview-buffer (prefix buf)
  "Show the preview in the preview buffer BUF.
Window is selected according to PREFIX:
- 4  (when prefixing the command with C-u) -> new window
- 16 (when prefixing the command with C-u C-u) -> new frame.
- else -> new buffer"
  (let ((imagep (and (display-images-p)
                     (plantuml-is-image-output-p))))
    (cond
     ((= prefix 16) (switch-to-buffer-other-frame buf))
     ((= prefix 4)  (switch-to-buffer-other-window buf))
     (t             (display-buffer buf)))
    (when imagep
      (with-current-buffer buf
        (image-mode)
        (goto-char (point-min))
        (set-buffer-multibyte t)))))

Note the (goto-char (point-min)) after calling image-mode. In addition, I also disabled the automatic image resizing on my config:

(setq image-auto-resize nil)

With all of this I now have an updating diagram. To scroll, I am using the horizontal keys [2]. I'm sure there is a "proper" way of solving this problem, but at least it solves my immediate needs.

HTH.

[1] #134 (comment)
[2] https://www.gnu.org/software/emacs/manual/html_node/emacs/Horizontal-Scrolling.html

@mcraveiro
Copy link

Turns out I'm not the first person trying to solve this problem. Looking through the network graph, found the following solution by @mrtimdog, which may be better:

(defun plantuml-preview-string (prefix string)
  "Preview diagram from PlantUML sources (as STRING), using prefix (as PREFIX)
to choose where to display it."
  (let* ((imagep (and (display-images-p)
                      (plantuml-is-image-output-p)))
         (buf (get-buffer-create plantuml-preview-buffer))
         (coding-system-for-read (and imagep 'binary))
         (coding-system-for-write (and imagep 'binary)))
    (with-current-buffer buf
      (image-toggle-display-text)
      (erase-buffer))
    (plantuml-exec-mode-preview-string prefix (plantuml-get-exec-mode) string buf)))

I tested it locally and it seems to work. @skuro if I raise a PR for this change, would you accept it?

Thanks very much for your time, and thanks for a great package.

[1] https://github.com/mrtimdog/plantuml-mode/commit/ce4e3feaa8bf5a3c0771c6004a4c60d0d55a0aab

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 2, 2021
@stale stale bot closed this as completed Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants