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?
1 Answer
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.
displaywhich is part of ImageMagick, can read stdin:cat foo.svg | display -)displayis just one example that should work.