Add (provide ...) forms.
[org-mode.git] / contrib / oldexp / org-xoxo.el
bloba9cfc6b6c4597ee235387a1cd64bae56e01af133
1 ;;; org-xoxo.el --- XOXO export for Org-mode
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
26 ;; XOXO export
28 ;;; Code:
30 (require 'org-exp)
32 (defvar org-export-xoxo-final-hook nil
33 "Hook run after XOXO export, in the new buffer.")
35 (defun org-export-as-xoxo-insert-into (buffer &rest output)
36 (with-current-buffer buffer
37 (apply 'insert output)))
38 (put 'org-export-as-xoxo-insert-into 'lisp-indent-function 1)
40 (defun org-export-as-xoxo (&optional buffer)
41 "Export the org buffer as XOXO.
42 The XOXO buffer is named *xoxo-<source buffer name>*"
43 (interactive (list (current-buffer)))
44 (run-hooks 'org-export-first-hook)
45 ;; A quickie abstraction
47 ;; Output everything as XOXO
48 (with-current-buffer (get-buffer buffer)
49 (let* ((pos (point))
50 (opt-plist (org-combine-plists (org-default-export-plist)
51 (org-infile-export-plist)))
52 (filename (concat (file-name-as-directory
53 (org-export-directory :xoxo opt-plist))
54 (file-name-sans-extension
55 (file-name-nondirectory buffer-file-name))
56 ".html"))
57 (out (find-file-noselect filename))
58 (last-level 1)
59 (hanging-li nil))
60 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
61 ;; Check the output buffer is empty.
62 (with-current-buffer out (erase-buffer))
63 ;; Kick off the output
64 (org-export-as-xoxo-insert-into out "<ol class='xoxo'>\n")
65 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't)
66 (let* ((hd (match-string-no-properties 1))
67 (level (length hd))
68 (text (concat
69 (match-string-no-properties 2)
70 (save-excursion
71 (goto-char (match-end 0))
72 (let ((str ""))
73 (catch 'loop
74 (while 't
75 (forward-line)
76 (if (looking-at "^[ \t]\\(.*\\)")
77 (setq str (concat str (match-string-no-properties 1)))
78 (throw 'loop str)))))))))
80 ;; Handle level rendering
81 (cond
82 ((> level last-level)
83 (org-export-as-xoxo-insert-into out "\n<ol>\n"))
85 ((< level last-level)
86 (dotimes (- (- last-level level) 1)
87 (if hanging-li
88 (org-export-as-xoxo-insert-into out "</li>\n"))
89 (org-export-as-xoxo-insert-into out "</ol>\n"))
90 (when hanging-li
91 (org-export-as-xoxo-insert-into out "</li>\n")
92 (setq hanging-li nil)))
94 ((equal level last-level)
95 (if hanging-li
96 (org-export-as-xoxo-insert-into out "</li>\n")))
99 (setq last-level level)
101 ;; And output the new li
102 (setq hanging-li 't)
103 (if (equal ?+ (elt text 0))
104 (org-export-as-xoxo-insert-into out "<li class='" (substring text 1) "'>")
105 (org-export-as-xoxo-insert-into out "<li>" text))))
107 ;; Finally finish off the ol
108 (dotimes (- last-level 1)
109 (if hanging-li
110 (org-export-as-xoxo-insert-into out "</li>\n"))
111 (org-export-as-xoxo-insert-into out "</ol>\n"))
113 (goto-char pos)
114 ;; Finish the buffer off and clean it up.
115 (switch-to-buffer-other-window out)
116 (indent-region (point-min) (point-max) nil)
117 (run-hooks 'org-export-xoxo-final-hook)
118 (save-buffer)
119 (goto-char (point-min))
122 (provide 'org-xoxo)
124 ;; Local variables:
125 ;; generated-autoload-file: "org-loaddefs.el"
126 ;; End:
128 ;;; org-xoxo.el ends here