org-mime: adding format specific pre-export hooks

Thanks to Niels Giesen for suggesting this change.

* contrib/lisp/org-mime.el (lambda): Adding format specific pre-export
  hooks.
  (org-mime-compose): Call pre-export hooks before export.
This commit is contained in:
Eric Schulte 2010-12-19 16:30:36 -07:00
parent d6fefb406e
commit 76661a853a

View file

@ -85,6 +85,15 @@
:group 'org-mime
:type 'hook)
(mapc (lambda (fmt)
(eval `(defcustom
,(intern (concat "org-mime-pre-" fmt "-hook"))
nil
(concat "Hook to run before " fmt " export.\nFunctions "
"should take no arguments and will be run in a "
"buffer holding\nthe text to be exported."))))
'("ascii" "org" "html" "html-ascii"))
;; example hook, for setting a dark background in <pre style="background-color: #EEE;"> elements
(defun org-mime-change-element-style (element style)
"Set new default htlm style for <ELEMENT> elements in exported html."
@ -245,7 +254,15 @@ export that region, otherwise export the entire body."
(require 'message)
(message-mail to subject headers nil)
(message-goto-body)
(let ((fmt (if (symbolp fmt) fmt (intern fmt))))
(let* ((fmt (if (symbolp fmt) fmt (intern fmt)))
(hook (intern (concat "org-mime-pre-" (symbol-name fmt) "-hook")))
(body (if (> (eval `(length ,hook)) 0)
(with-temp-buffer
(insert body)
(goto-char (point-min))
(eval `(run-hooks ',hook))
(buffer-string))
body)))
(cond
((eq fmt 'org)
(insert (org-export-string (org-babel-trim body) 'org)))