6.5 KB

org-watchdoc.el --- Watchdog for exported Org-mode trees

Copyright (C) from 2014 Thorsten Jolitz Author: Thorsten Jolitz Keywords: org-mode, exporter, propagate changes, documentation



This library implements functionality for keeping exported files associated with Org subtrees up-to-date.

Its principal use case is writing the comment-section of Emacs Lisp (or other) source-code files only once (and in full Org-mode using outorg.el), export it as README documentation from the *outorg-edit-buffer* to html, ascii, latex/pdf, markdown-github-flavor or whatever, and keep the exported doc files automatically up-to-date when the original comment-section of the source-buffer is edited explicitly with outorg (via M-x outorg-edit-comments-and-propagate-changes).


org-watchdoc is just a little toolbox that can be used independently from outorg too. All its functions are commands, so its functionality is available for interactive use too.

Put this line in your init file

  (require 'org-watchdoc)

and make sure Emacs can find the file org-watchdoc.el.


To take real advantage of org-watchdoc, outshine.el and outorg.el (and maybe navi-mode.el) should be installed and source-code buffers should be structured with outshine headers (outcommented Org-mode headers), taking care that the whole comment-section is one single outline tree that is the first headline in the source-code file. Use org-watchdoc.el itself as an example for this kind of file structuring.


Since org-watchdoc is a toolbox and not a mode, no menu or keymap is specified. However, its commands can be used interactively:

Interactive Use

M-x org-watchdoc- action
add-target add target-combination to watchlist
remove-target remove target-combination from watchlist
propagate-changes if md5 changed reexport all combinations
set-md5 set org-watchdoc-md5 to current md5

In interactive use, this would be the typical order of actions:

  1. Export first buffer tree to desired doc files (e.g.
  2. or README-WORG.html). Optional, since adding non-exiting target-files in step 2 will cause the exporter to write them the when exiting the edit-buffer.
  1. Add targets with point on first buffer headline.

Targets are combinations of files the exporter writes to, export-template files to be inserted before the exporter does its work, and backends the exporter should export to, e.g.

#+BEGIN_EXAMPLE "/home/me/proj/ /home/me/proj/ gfm" "/home/me/proj/README-WORG.html /home/me/proj/ html" #+END_EXAMPLE

The three elements of such a combination are prompted from the user.

  1. Save and set md5 variable.
  1. Edit the (narrowed) first buffer tree and save
  1. Propagate changes.

Use with Outorg

Since md5 has changed due to the edits, all registered target combinations are automatically re-exported.

Assuming outshine and outorg are installed and active, do once:

  • Edit as Org

In the outorg-edit-buffer do steps 1 and 2 described above for direct interactive use.

M-x outorg-edit-comments-and-propagate-changes

Then whenever you want to edit the source-buffer's comment-section and propagate the changes to the watched doc files, do:

M-x outorg-edit-comments-and-propagate-changes

instead of the usual

M-x outorg-edit-comment-as-org

This will

  • Offer the first buffer tree for editing in the
  • *outorg-edit-buffer*
  • Reset `org-watchdoc-md5' immediately after edit-buffer setup

Keybindings in Outshine

  • Check if buffer md5 has changed when editing is quitted. If so,
  • propagate the changes to the doc files registered in the subtrees watchlist.

Here are the keybindings I added to outshine.el:

;; edit comment-section with `outorg' and propagate changes

;; best used with prefix-key 'C-c' 
(define-key map "`" 'outorg-edit-comments-and-propagate-changes)

;; best used with prefix-key 'M-#'
(define-key map "\M-+" 'outorg-edit-comments-and-propagate-changes)
(define-key map "+" 'outorg-edit-comments-and-propagate-changes)


So just like editing e.g. an Emacs Lisp buffer or subtree (with outshine activated) in full Org-mode only involves pressing M-# M-# once to start editing, and then M-# to exit the edit-buffer, edting the comment-section of such a source-buffer and propagating the changes to several export-targets only involves pressing M-# M-+ once to start editing, and then M-# to exit the edit buffer (when M-# was set as outline-minor-mode prefix).

date author(s) version
<2014-04-09 Mi> Thorsten Jolitz 0.9