If I place
(insert-image (create-image "/tmp/test.png"))
in a buffer, place the cursor after the last parenthesis and evaluate it with C-x C-e
, then the image /tmp/test.png
is displayed in the buffer:
Pretty neat. But,
- I had to put the final parenthesis on a separate line, so the image
is close to the left-hand side of the buffer. Is there a way to hide
the
(insert-image ...)
text altogether? - The text file contains the
(insert-image ...)
text only, not the image. I'm happy with that, but is there a way to tell emacs to automatically replace all the(insert-image ...)
expressions by their corresponding images (after the file is opened) without me having to typeC-x C-e
after each one?
Depending on exactly what you want to achieve, you might try one the the following ideas:
1. use
org-mode
as your buffer's major mode. You then have access to all the power oforg-mode
formatting, which includes linking to image files and displaying them:then you can call
org-toggle-inline-images
(C-c C-x C-v) to display images in the buffer (without a prefix argument, it will display only images without description; if you give a prefix argument, it will display all images)2. write your own elisp code to insert images where you want them, and put it in an
eval
local pseudo-variable so that it is called when opening the file. For example:You can of course wrap the elisp code into a neat function and simply call it from the
eval
local variable (which is cleaner, but forces you to have the function definition somewhere else, away from your file)If you don't want the text (actually lisp code) in the buffer, don't type it into the buffer in the first place. Try
M-x eval-expression
and enter your lisp code after the Eval prompt:Then the image is inserted at point in the buffer. You can define a function like this:
Either type
M-x eval-expression
and the above defun or type it into a buffer andC-x C-e
after it. Then you can insert the image usingM-x my-insert-image
.Take a look at
iimage-mode
, the inline image minor mode. It's included since Emacs-23, IIRC.M-x
iimage-mode