insert image into text buffer

后端 未结 3 1348
醉酒成梦
醉酒成梦 2021-01-31 10:40

If I place

(insert-image (create-image \"/tmp/test.png\"))

in a buffer, place the cursor after the last parenthesis and evaluate it with

3条回答
  •  梦如初夏
    2021-01-31 11:13

    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 of org-mode formatting, which includes linking to image files and displaying them:

    an image without description
    [[file:/tmp/image.png]]
    
    an image with description
    [[file:/tmp/image.png][my description]]
    

    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:

    foo
    
    bar
    
    # Local Variables:
    #   eval: (progn (beginning-of-buffer)(search-forward "")(insert-image (create-image "/tmp/image.png")))
    # End:
    

    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)

提交回复
热议问题