0

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")
#+end_src

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?

Thanks!

1 Answer 1

3

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.")
#+END_SRC

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

Your Answer

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

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