0

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?

  • 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 -`) – NickD Aug 20 '23 at 18:46
  • Ok, thanks that is helpful. Now I will go look for imageMagick and how to install it.... – Christopher Clark Aug 20 '23 at 19:00
  • Check whatever image display program you have available first: `display` is just one example that should work. – NickD Aug 20 '23 at 20:05

1 Answers1

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.

dalanicolai
  • 6,108
  • 7
  • 23