~ubuntu-branches/ubuntu/hardy/python-docutils/hardy

« back to all changes in this revision

Viewing changes to tools/editors/emacs/rst-html.el

  • Committer: Bazaar Package Importer
  • Author(s): martin f. krafft
  • Date: 2006-07-10 11:45:05 UTC
  • mfrom: (2.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20060710114505-otkhqcslevewxmz5
Tags: 0.4-3
Added build dependency on python-central (closes: #377580).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
;;; rst-mode.el --- Goodies to automate converting reST documents to HTML.
2
 
 
3
 
;; Copyright 2003 Martin Blais <blais@iro.umontreal.ca>
4
 
;; 
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.
9
 
;; 
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.
14
 
;; 
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
18
 
 
19
 
;;; Commentary:
20
 
 
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
24
 
;; provides.
25
 
 
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)
30
 
 
31
 
;;; Code:
32
 
 
33
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34
 
;;; Customization:
35
 
 
36
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37
 
 
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."
41
 
  :group 'rst
42
 
  :version "21.1")
43
 
 
44
 
(defcustom rst-html-command "docutils-html"
45
 
  "Command to convert an reST file to HTML."
46
 
  :group 'rst-html
47
 
  :type '(string))
48
 
 
49
 
(defcustom rst-html-stylesheet ""
50
 
  "Stylesheet for reST to HTML conversion. Empty for no special stylesheet."
51
 
  :group 'rst-html
52
 
  :type '(string))
53
 
 
54
 
(defcustom rst-html-options ""
55
 
  "Local file options for reST to HTML conversion.
56
 
Stylesheets are set by an own option."
57
 
  :group 'rst-html
58
 
  :type '(string))
59
 
 
60
 
(defcustom rst-html-extension ".html"
61
 
  "Extension for HTML output file."
62
 
  :group 'rst-html
63
 
  :type '(string))
64
 
 
65
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66
 
;; Conversion to HTML
67
 
 
68
 
(defun rst-html-compile ()
69
 
  "Compile command to convert reST document into HTML."
70
 
  (interactive)
71
 
  (let* ((bufname (file-name-nondirectory buffer-file-name))
72
 
         (outname (file-name-sans-extension bufname))
73
 
         (ssheet
74
 
          (or (and (not (zerop (length rst-html-stylesheet)))
75
 
                   (concat "--stylesheet=\"" rst-html-stylesheet "\""))
76
 
              "")))
77
 
    (set (make-local-variable 'compile-command)
78
 
         (mapconcat 'identity
79
 
                    (list rst-html-command
80
 
                          ssheet rst-html-options
81
 
                          bufname (concat outname rst-html-extension))
82
 
                    " "))
83
 
    (if (or compilation-read-command current-prefix-arg)
84
 
        (call-interactively 'compile)
85
 
      (compile compile-command))
86
 
    ))
87
 
 
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."
91
 
  (interactive)
92
 
  (let ((conffile (rst-html-find-conf)))
93
 
    (if conffile
94
 
        (let* ((bufname (file-name-nondirectory buffer-file-name))
95
 
               (outname (file-name-sans-extension bufname)))
96
 
          (set (make-local-variable 'compile-command)
97
 
               (mapconcat 'identity
98
 
                          (list rst-html-command
99
 
                                (concat "--config=\"" conffile "\"")
100
 
                                bufname (concat outname rst-html-extension))
101
 
                          " "))
102
 
          (if (or compilation-read-command current-prefix-arg)
103
 
              (call-interactively 'compile)
104
 
            (compile compile-command)))
105
 
      (call-interactively 'rst-html-compile)
106
 
      )))
107
 
 
108
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109
 
;; Find the configuration file in the parents.
110
 
 
111
 
(defun rst-html-find-conf ()
112
 
  "Look for the configuration file in the parents of the current path."
113
 
  (interactive)
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 
122
 
                                     (directory-file-name
123
 
                                     (file-name-directory dir))))) )
124
 
      (or (and dir (concat dir file-name)) nil)
125
 
    )))
126
 
 
127
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128
 
 
129
 
;;; rst-mode.el ends here