Emacsist RSS --- If never, make it ever: C-h C-h

How to auto export html when saving in org-mode?


这里 查看更多 Emacs 相关推荐文章最新 Emacs 圈的动态. 欢迎关注微信公众账号: Emacsist

Hick 叽喳:

     原是个 reddit 上的问题, 下面给出的事答案.

I added the following to my .emacs

;; Auto-export org files to html when saved
(defun org-mode-export-hook ()
  (when (equal major-mode 'org-mode)
    (add-hook 'after-save-hook 'org-html-export-to-html h h)

However, when I open org file, make some changes, and save, the corresponding html file does not get updated. What's wrong here?

Edit. The problem was my org version. This works as intended:

;; Auto-export org files to html when saved 
(defun org-mode-export-hook()
  "Auto export html"
  (when (eq major-mode 'org-mode)
    (org-export-as-html t)))

(add-hook 'after-save-hook 'org-mode-export-hook)


(defun toggle-org-html-export-on-save ()
  (if (memq 'org-html-export-to-html after-save-hook)
        (remove-hook 'after-save-hook 'org-html-export-to-html t)
        (message "Disabled org html export on save for current buffer..."))
    (add-hook 'after-save-hook 'org-html-export-to-html nil t)
    (message "Enabled org html export on save for current buffer...")))

You can run this on your org buffers to toggle export-on-save for the buffer.

原文出处: aaptel
原文地址: http://www.reddit.com/r/emacs/comments/4golh1/how_to_auto_export_html_when_saving_in_orgmode/
原文时间: 2016-04-27 22:02
本文地址: http://emacsist.com/10874
整理时间: 2016-06-05 21:14

本文由 Hick 整理,转载请保留以上信息;
COPYLEFTThe articles on this site come from Internet, thanks to all the original authors.
      If anything about COPYRIGHT, or LEFT, please contact Emacsist at gmail dot com .