diff --git a/contrib/lisp/org-mime.el b/contrib/lisp/org-mime.el index 14a8ce3..8149c73 100644 --- a/contrib/lisp/org-mime.el +++ b/contrib/lisp/org-mime.el @@ -85,6 +85,10 @@ :group 'org-mime :type 'hook) +(defvar org-mime-htmlized nil + "List to be set locally for undoing/toggling htmlization.") +(make-variable-buffer-local 'org-columns-current-fmt) + ;; example hook, for setting a dark background in
 elements
 (defun org-mime-change-element-style (element style)
   "Set new default htlm style for  elements in exported html."
@@ -151,18 +155,18 @@
       str)
      html-images)))
 
-(defun org-mime-htmlize (arg)
+(defun org-mime-htmlize (arg &optional beg end)
   "Export a portion of an email body composed using `mml-mode' to
 html using `org-mode'.  If called with an active region only
 export that region, otherwise export the entire body."
   (interactive "P")
   (let* ((region-p (org-region-active-p))
-         (html-start (or (and region-p (region-beginning))
+         (html-start (or (and region-p (region-beginning)) beg
                          (save-excursion
                            (goto-char (point-min))
                            (search-forward mail-header-separator)
                            (+ (point) 1))))
-         (html-end (or (and region-p (region-end))
+         (html-end (or (and region-p (region-end)) end
                        ;; TODO: should catch signature...
                        (point-max)))
          (raw-body (buffer-substring html-start html-end))
@@ -188,7 +192,22 @@ export that region, otherwise export the entire body."
     (save-excursion
       (goto-char html-start)
       (insert (org-mime-multipart body html)
-              (mapconcat 'identity html-images "\n")))))
+              (mapconcat 'identity html-images "\n"))
+      (setq org-mime-htmlized (list html-start body (point))))))
+
+(defun org-mime-toggle (arg)
+  "Toggle htmlization according to the value of
+`org-mime-htmlized' using `org-mime-htmlize'."
+  (interactive "P")
+  (let ((beg   (car org-mime-htmlized))
+        (body (cadr org-mime-htmlized))
+        (end (caddr org-mime-htmlized)))
+    (if body
+        (save-excursion
+          (goto-char beg) (delete-region beg end)
+          (insert (second org-mime-htmlized))
+          (setq org-mime-htmlized (list beg nil (point))))
+      (org-mime-htmlize nil beg end))))
 
 (defun org-mime-org-export (fmt body tmp-file)
   "Org-Export BODY to format FMT with the file name set to