Q:

Calling interactive functions sequentially in Emacs

My init.el is dynamically generated from init.org. I also generate init.html documentation from the init.org file.
I can manually call M-x org-babel-tangle and M-x org-export-as-html without problem, but I'd like a single function that does both.
I wrote the following function:
(defun export-init-org ()
  "Generate init.html and init.html from the current init.org file."
  (interactive)
  (call-interactively 'org-export-as-html)
  (call-interactively 'org-babel-tangle))

This doesn't work. It creates the init.html file, but not the init.el file. I tried reordering the calls:
(defun export-init-org ()
  "Generate init.html and init.html from the current init.org file."
  (interactive)
  (call-interactively 'org-babel-tangle)
  (call-interactively 'org-export-as-html))

This works as expected, both init.el and init.html are created. Why is this? What was wrong with my first function?

A:

I don't have org-export-as-html in my org installation. I suspect you're using an older version. However, I think what you're seeing is a consequence of the side effects the org-export-as-html file. If this function causes Emacs to switch buffers, you'll end up calling org-babel-tangle on the html result, and not the org source. This of course does not work. Try this instead to confirm:
(defun export-init-org ()
  "Generate init.html and init.html from the current init.org file."
  (interactive)
  (save-excursion ;; restores original buffer after running
    (call-interactively 'org-export-as-html))
  (call-interactively 'org-babel-tangle))

