4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

orgファイルを更新すると出力ファイルも自動更新されるようにする

Posted at

はじめに

Emacsのorg-modeで文章を書くと, C-c C-e(org-export-dipatch) で,
様々なファイル形式 (Markdown, HTML, PDF, LaTeXなど) に出力できます.
しかし, orgファイルを更新するたびに, 手動で出力を更新するのは面倒です.

設定

そこで以下のように設定すると, orgファイル保存時に自動で出力ファイルも更新されるようにできます.
ただし, すでに出力ファイルが存在する場合にのみ自動出力するようにしています.
(例として, HTMLやMarkdownの設定のみ書いてますが, 必要に応じて他ファイル形式も追加したり, 削除したりしてください.)

~/.emacs.d/init.el
(add-hook 'org-mode-hook
          (lambda ()
            (add-hook 'after-save-hook
                      (lambda ()
                        (when (file-exists-p (concat (file-name-sans-extension (buffer-file-name)) ".html"))
                          (org-html-export-to-html)
                          )
                        (when (file-exists-p (concat (file-name-sans-extension (buffer-file-name)) ".md"))
                          (org-md-export-to-markdown)
                          )
                        )
                      nil t))
          )

この設定により, 1度HTMLやMarkdownファイルを手動で出力すると, 以降はorgファイル更新時に自動でHTMLやMarkdownファイルも更新されるようになります.

バージョン情報

  • Emacs 28.2
  • org-mode 9.6

関連記事

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?