For example, whenever I edit my config, I run this block to reload the config:

#+begin_src emacs-lisp :tangle no :var data=replace-symlink :results none
(org-babel-load-file (locate-user-emacs-file "/home/user/.emacs.d/config.org"))
(load-file "/home/user/.emacs.d/config.el")

Is there a way to have this run automatically every time I save the file C-x C-s?

I have another file with a src block that generates an xwiki file and updates a web wiki via an API. I'm trying to have org evaluate that block automatically on save as well.

Let me know if there's a straighforward way to do it. This would seem very useful functionality but I didn't come across anything in org docs. It might be solved already by creatively running #+CALL via some save hook?


1 Answer 1


You can use org-babel-ref-resolve to call named code blocks from one of the hooks before-save-hook or after-save-hook.

Example Orgmode-file:

#+NAME: myblock
#+BEGIN_SRC emacs-lisp
(message "Running myblock.")

Local Variables:
eval: (add-hook 'before-save-hook (lambda () (org-babel-ref-resolve "myblock")) nil t)
  • This is amazing. Thank you!
    – Gaurav
    Commented Apr 17, 2020 at 1:32

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.