[emacs-berlin] SVG+

Felix E. Klee felix.klee at inka.de
Fri Jun 28 13:24:23 UTC 2019


This is the sane solution, thanks for the example!

However, what we want for fun is to render the image directly,
i.e. without a temporary file.  What works is to do `(goto-char
(point-max))` followed by a call to `svg+-insert-image`.  The latter
function is simply a renamed `svg-insert-image`, and that calls
`insert-image`.  Looking at the source code of `insert-image` one can
see how to make Emacs display an inline image:

  1. Insert a simple space at point.

  2. Use `add-text-properties` to change the text properties of that
     space to display an image.

I stripped `insert-image` from all code that’s not needed and inlined it
into an example:

    #+BEGIN_SRC emacs-lisp -n
      (require 'svg+)
      (setq svg (svg+-create 800 800 :stroke "orange" :stroke-width 5))
      (svg+-insert-image svg)
      (svg+-rectangle svg 100 100 500 500 :stroke "green")
      (goto-char (point-max))
      (let ((start (point)))
         (insert " ")
         (add-text-properties
         start
         (point)
         (list 'display (svg+-image svg) 'rear-nonsticky '(display))))
    #+END_SRC

    #+RESULTS:
    : t

When executed using C-c C-c, at the end of the buffer an image is
inserted.  The next improvement would be to get the image inserted
directly into `#+RESULTS:`.  However I doubt that it’s possible to
change text properties in `#+RESULTS:` without over-the-top parsing.


More information about the emacs-berlin mailing list