1
;;; rst-mode.el --- Goodies to automate converting reST documents to HTML.
3
;; Copyright 2003 Martin Blais <blais@iro.umontreal.ca>
5
;; This program is free software; you can redistribute it and/or modify
6
;; it under the terms of the GNU General Public License as published by
7
;; the Free Software Foundation; either version 2 of the License, or
8
;; (at your option) any later version.
10
;; This program is distributed in the hope that it will be useful,
11
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
;; GNU General Public License for more details.
15
;; You should have received a copy of the GNU General Public License
16
;; along with this program; if not, write to the Free Software
17
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
;; This package provides a few functions and variables that can help in
22
;; automating converting reST documents to HTML from within emacs. You could
23
;; use a makefile to do this, of use the compile command that this package
26
;; You can also bind a command to automate converting to HTML:
27
;; (defun user-rst-mode-hook ()
28
;; (local-set-key [(control c)(?9)] 'rst-html-compile))
29
;; (add-hook 'rst-mode-hook 'user-rst-mode-hook)
33
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38
(defgroup rst-html nil
39
"Settings for conversion to HTML available by \\[rst-html-compile]. Use of
40
this functionality is discouraged. Get a proper `Makefile' instead."
44
(defcustom rst-html-command "docutils-html"
45
"Command to convert an reST file to HTML."
49
(defcustom rst-html-stylesheet ""
50
"Stylesheet for reST to HTML conversion. Empty for no special stylesheet."
54
(defcustom rst-html-options ""
55
"Local file options for reST to HTML conversion.
56
Stylesheets are set by an own option."
60
(defcustom rst-html-extension ".html"
61
"Extension for HTML output file."
65
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68
(defun rst-html-compile ()
69
"Compile command to convert reST document into HTML."
71
(let* ((bufname (file-name-nondirectory buffer-file-name))
72
(outname (file-name-sans-extension bufname))
74
(or (and (not (zerop (length rst-html-stylesheet)))
75
(concat "--stylesheet=\"" rst-html-stylesheet "\""))
77
(set (make-local-variable 'compile-command)
79
(list rst-html-command
80
ssheet rst-html-options
81
bufname (concat outname rst-html-extension))
83
(if (or compilation-read-command current-prefix-arg)
84
(call-interactively 'compile)
85
(compile compile-command))
88
(defun rst-html-compile-with-conf ()
89
"Compile command to convert reST document into HTML. Attempts to find
90
configuration file, if it can, overrides the options."
92
(let ((conffile (rst-html-find-conf)))
94
(let* ((bufname (file-name-nondirectory buffer-file-name))
95
(outname (file-name-sans-extension bufname)))
96
(set (make-local-variable 'compile-command)
98
(list rst-html-command
99
(concat "--config=\"" conffile "\"")
100
bufname (concat outname rst-html-extension))
102
(if (or compilation-read-command current-prefix-arg)
103
(call-interactively 'compile)
104
(compile compile-command)))
105
(call-interactively 'rst-html-compile)
108
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109
;; Find the configuration file in the parents.
111
(defun rst-html-find-conf ()
112
"Look for the configuration file in the parents of the current path."
114
(let ((file-name "docutils.conf")
115
(buffer-file (buffer-file-name)))
116
;; Move up in the dir hierarchy till we find a change log file.
117
(let ((dir (file-name-directory buffer-file)))
118
(while (and (or (not (string= "/" dir)) (setq dir nil) nil)
119
(not (file-exists-p (concat dir file-name))))
120
;; Move up to the parent dir and try again.
121
(setq dir (expand-file-name (file-name-directory
123
(file-name-directory dir))))) )
124
(or (and dir (concat dir file-name)) nil)
127
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129
;;; rst-mode.el ends here