How to export org file to HTML file when saving?

I want to export my org files to HTML files in a specific directory when saving. I can use Emacs and Org-mode, but I do not know Elisp.

+7
emacs org-mode
source share
3 answers

Emacs has several hooks that are triggered in certain events. The hook you are looking for is probably an after-save-hook . Just set it to the function you want to run every time you save the file. In your case, it will be org-html-export-to-html .

There are many ways to do this, but the following method is probably the fastest and does not contain any โ€œrealโ€ elisp. Put the following lines in your org file:

 # Local variables: # after-save-hook: org-html-export-to-html # end: 

The next time you open this file, you will get a warning and ask if a local variable should be set (as it is potentially dangerous, but not a problem here). Press y and everything should work.

+5
source share

With Org-Mode 8.3 and Emacs 24.5.1, the accepted answer creates the *Org HTML Export* pseudo-buffer, which you must save manually, and the Cc Ce hh key saves the file more conveniently directly.

To really auto-expose in the background, try the following code:

 # Local variables: # eval: (add-hook 'after-save-hook 'org-html-export-to-html tt) # end: 

You can combine this solution with the following function in .emacs :

 (defun toggle-html-export-on-save () "Enable or disable export HTML when saving current buffer." (interactive) (when (not (eq major-mode 'org-mode)) (error "Not an org-mode file!")) (if (memq 'org-html-export-to-html after-save-hook) (progn (remove-hook 'after-save-hook 'org-html-export-to-html t) (message "Disabled org html export on save")) (add-hook 'after-save-hook 'org-html-export-to-html nil t) (set-buffer-modified-p t) (message "Enabled org html export on save"))) 
+5
source share

Team for this

 Cc Ce hh (org-html-export-to-html) 

Export as HTML file. For the Org file myfile.org, the HTML file will be myfile.html. The file will be overwritten without warning. Cc Ce ho Export as an HTML file and open it immediately using a browser.

Link

+2
source share

All Articles