فهرست منبع

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.
Eric Schulte 15 سال پیش
والد
کامیت
76661a853a
1فایلهای تغییر یافته به همراه18 افزوده شده و 1 حذف شده
  1. 18 1
      contrib/lisp/org-mime.el

+ 18 - 1
contrib/lisp/org-mime.el

@@ -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)))