1

I have a python program that uses graphviz to generate an svg image that it prints out. When I run that in a shell buffer I see a textual representation of the svg image. I'd like to see instead the generated image. How do I take that text in emacs and get something that shows me the image?

4
  • Pipe the output of the python program into the standard input of an image display program that can read from stdin (e.g. display which is part of ImageMagick, can read stdin: cat foo.svg | display -) Commented Aug 20, 2023 at 18:46
  • Ok, thanks that is helpful. Now I will go look for imageMagick and how to install it.... Commented Aug 20, 2023 at 19:00
  • Check whatever image display program you have available first: display is just one example that should work. Commented Aug 20, 2023 at 20:05
  • Yes, it turns out that graphviz writes that image to a file and if I simply open a buffer to that file, emacs displays it (in that buffer). It's not quite as magic as what Jupyter notebooks do, as I have to manually open the file (or fix my comint-send-command to do that for me). If this comment was an answer, I would have accepted it. Commented Sep 9, 2023 at 10:13

1 Answer 1

0

I am not sure where and how you are running Emacs, but I think graphical Emacs can show the svg image itself also in most cases. Then the following answer is an alternative to the answer by @NickD in the comments.

I am not sure if you need to run the command in a shell buffer per se, but otherwise you could also use the following command (via M-x or create a keybinding):

(defun display-output-as-image (command) (interactive (list (read-shell-command (if shell-command-prompt-show-cwd (format-message "Shell command in `%s': " (abbreviate-file-name default-directory)) "Shell command: ") nil nil (let ((filename (cond (buffer-file-name) ((eq major-mode 'dired-mode) (dired-get-filename nil t))))) (and filename (file-relative-name filename)))))) (shell-command command (pop-to-buffer "output.svg")) (image-mode)) 

Then, after calling this command, you can simply type in the command and the image will show in an Emacs buffer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.