20

For below org mode code example:

#+BEGIN_SRC plantuml :file test.png
Alice -> Bob: synchronous call
Alice ->> Bob: asynchronous call
#+END_SRC

#+RESULTS:
[[file:test.png]]

After press C-c C-c, the result is as above. If I need to show it as image, I have to run "M-x org-display-inline-image" command.

Is it possible to combine the "C-c C-c" and "M-x org-display-inline-image" together? It's better to still use "C-c C-c" shortcut.

3
  • 1
    If you are just looking to always have the image inlined, you can put #+STARTUP: inlineimages somewhere in your org file. (And C-c C-c that so you don't need to reopen your buffer)
    – Archenoth
    Commented Feb 7, 2017 at 17:19
  • 2
    @Archenoth Actually my cause is: 1. Update source code. 2. Press C-c C-c to execute the code. 3. Output is text but not image. I wish everytime after press C-c C-c, I can get the image displayed inline. Your suggestion works if user didn't change the code.
    – beetlej
    Commented Feb 7, 2017 at 17:56
  • Thank you for reminding me! I had forgotten I had already done something about this.
    – Archenoth
    Commented Feb 7, 2017 at 22:06

2 Answers 2

5

Why not redefine C-c C-c in Org mode then? Use this keybinding. Put it in your emacs init.el file and restart emacs:

(define-key org-mode-map (kbd "C-c C-c")
  (lambda () (interactive) (org-ctrl-c-ctrl-c)
                           (org-display-inline-image)))

addendum: is this global or local?

Local to org-mode only.

4
  • Sounds like return a error: Wrong type argument: listp, t. BTW, will this redefine globally or just for org mode?
    – beetlej
    Commented Feb 7, 2017 at 19:42
  • @beetlej try tweak it as below: (define-key org-mode-map (kbd "C-c C-c") (lambda () (interactive) (org-ctrl-c-ctrl-c) (org-display-inline-images)))
    – lucky1928
    Commented Feb 7, 2017 at 20:49
  • local only, also fixed the error typo in the answer above
    – Emacs User
    Commented Feb 7, 2017 at 20:53
  • For me it's working with org-display-inline-images. Commented Apr 2, 2020 at 17:22
27

There is both a hook for evaluating code blocks (org-babel-after-execute-hook), and a function for updating inline images. (org-redisplay-inline-images)

Combine these two and you should be good to go!

(add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)

C-c C-c updating inline images

3
  • 1
    Great, it works also. BTW, is org-babel-after-execute-hook for all org command or just for this command? maybe I only wish to hook C-c C-c command but not others!
    – beetlej
    Commented Feb 8, 2017 at 16:21
  • 3
    This hook will only affect code blocks in Org buffers. Actually, if you wanted to do more then that, you would need to do a bit of extra work.
    – Archenoth
    Commented Feb 8, 2017 at 16:56
  • 4
    WOW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! THANK YOU! Commented Aug 2, 2019 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.