1 ;; 07-html-sy.el --- HTML settings -*- Emacs-Lisp -*-
3 ;; Copyright (C) 2007 - 2012 Steve Youngs
5 ;; Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;; Created: <2007-12-02>
8 ;; Time-stamp: <Sunday Jun 10, 2012 10:56:40 steve>
9 ;; Download: <http://bastard.steveyoungs.com/~steve/SXEmacs/inits/>
10 ;; HTMLised: <http://bastard.steveyoungs.com/~steve/SXEmacs/htmlinits/07-html-sy.html>
11 ;; Git Repo: git clone http://git.sxemacs.org/syinit
12 ;; Keywords: init, compile
14 ;; This file is part of SYinit
16 ;; Redistribution and use in source and binary forms, with or without
17 ;; modification, are permitted provided that the following conditions
20 ;; 1. Redistributions of source code must retain the above copyright
21 ;; notice, this list of conditions and the following disclaimer.
23 ;; 2. Redistributions in binary form must reproduce the above copyright
24 ;; notice, this list of conditions and the following disclaimer in the
25 ;; documentation and/or other materials provided with the distribution.
27 ;; 3. Neither the name of the author nor the names of any contributors
28 ;; may be used to endorse or promote products derived from this
29 ;; software without specific prior written permission.
31 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
32 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
40 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
41 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 ;; Sets up things for writing HTML.
49 ;; The HTML version of this file was created with Hrvoje Niksic's
50 ;; htmlize.el which is part of the XEmacs "text-modes" package.
58 ;:*=======================
59 ;:* General HTML settings.
61 html-helper-htmldtd-version
62 "<?xml version=\"1.0\" encoding=\"utf-8\"?>
63 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
64 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
65 html-helper-use-expert-menu t
66 hm--html-automatic-create-modified-line t
67 hm--html-automatic-update-modified-line t
68 hm--html-changed-comment-prefix "Changed with SXEmacs, by: "
69 hm--html-created-comment-prefix "Created with SXEmacs, by: "
71 hm--html-html-doctype-version
72 "\"-//W3C//DTD XHTML 1.0 Transitional//EN\"
73 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""
74 hm--html-log-date-format "%y-%m-%d"
76 (file-name-as-directory
77 (expand-file-name "templates"
78 (locate-data-directory "hm--html-menus")))
79 hm--html-frame-template-file
80 (expand-file-name "frame.html.tmpl" hm--html-template-dir)
81 hm--html-title-date-format "%y-%m-%d"
82 hm--html-username "Steve Youngs"
83 html-sigusr1-signal-value 10)
87 sgml-auto-activate-dtd t
88 sgml-live-element-indicator t
89 sgml-validate-command "onsgmls -s -m %s %s")
92 (directory-files-recur "/usr/share/sgml" 'full nil nil 'subdir)
93 "List of directories for `sgml-system-path'.")
95 (setq sgml-system-path
97 "/usr/share/sxemacs/xemacs-packages/etc/psgml-dtds/")
100 ;; Run HTML Tidy over the current buffer. I don't use this yet, I've
101 ;; only just installed HTML Tidy and haven't yet figured out how to
102 ;; use it properly. I snarfed this function from:
104 ;; <http://www.hollenback.net/index.php/EmacsTidy>
105 (defun tidy-buffer ()
106 "Run Tidy HTML parser on current buffer."
108 (if (get-buffer "tidy-errs")
109 (kill-buffer "tidy-errs"))
110 (shell-command-on-region (point-min) (point-max)
111 "tidy -f /tmp/tidy-errs -q -i -wrap 72 -c" t)
112 (find-file-other-window "/tmp/tidy-errs")
114 (delete-file "/tmp/tidy-errs")
115 (message "buffer tidy'ed"))
117 (autoload 'html-mode "psgml-html" "Load psgml-html-mode" t)
118 (autoload 'css-mode "css-mode")
120 (add-hook 'html-mode-hook #'hm--html-minor-mode)
121 (eval-when-compile (defvar ispell-extra-args))
122 (add-hook 'html-mode-hook
124 (make-local-variable 'ispell-extra-args)
125 (push "-H" ispell-extra-args)))
126 (add-hook 'html-helper-timestamp-hook #'html-helper-default-insert-timestamp)
128 ;:*=======================
129 ;:* Hrvoje Niksic's htmlize
131 ;; `htmlize.el' comes with the "text-modes" XEmacs package, or you
132 ;; can get the latest version from:
134 ;; <http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el>.
136 ;; `htmlize.el' is a lovely piece of code for converting Emacs buffers
137 ;; into HTML. The default settings should be fine for most people most
138 ;; of the time in most situations. But, by now, I'm sure that you've
139 ;; come to the realisation that I don't fit into that category. So
144 ;; Those "local-variables" declarations you sometimes see at the bottom
145 ;; of source files can cause quite a bit of havoc when it comes to
146 ;; "htmlize'ing" them. Basically what happens is that when you go to
147 ;; save the resulting HTML buffer XEmacs goes into an infinite loop
148 ;; complaining about bad local vars. I get around it with this next
149 ;; function which just a simple wrapper for `htmlize-buffer'.
150 (defun sy-htmlize-buffer (&optional buffer)
151 "This is just a simple wrapper for `htmlize-buffer'.
153 All it does is scan the buffer to be converted for any local variable
154 declarations and replaces them with a place holder. This prevents an
155 infloop when you go to save the resulting HTML buffer.
157 Original `htmlize-buffer' doc string:
159 Convert buffer to HTML, preserving the font-lock colorization.
160 The generated HTML is available in a new buffer, which is returned.
161 When invoked interactively, the new buffer is selected in the
164 (let ((htmlbuf (with-current-buffer (or buffer (current-buffer))
165 (goto-char (point-min))
166 (while (re-search-forward
167 ;; This concat is deliberately split accross
168 ;; 4 lines for a reason. Don't change it!
172 " Variables:$") nil t)
174 (concat comment-start
175 " Put the normal local variables declaration here")))
177 ;; Undo that replace-match.
178 (when (buffer-modified-p)
180 (when (interactive-p)
181 (switch-to-buffer htmlbuf))
184 ;; Use my function by default.
185 (defalias 'htmlize-buffer 'sy-htmlize-buffer)
187 ;; This function, run from `htmlize-after-hook' lets me embed HTML
188 ;; comments inside normal source comments and also allows me to set up
189 ;; relative hyperlinks. It has been hand-massaged after htmlizing to
190 ;; get the desired results for its doc string.
191 (defun sy-htmlize-after-hook ()
192 "Function run from `htmlize-after-hook'.
194 It takes care of any relative hyperlinks and also dequotes any HTML
195 comments that were incorrectly quoted.
197 Relative hyperlinks need to be prepared in a particular way in the
198 file that is to be converted to HTML. For example, in an emacs lisp
201 Get the latest rls=/src/foo.el;rld=version here;rle.
203 Which would be converted to:
205 Get the latest <a href=\"/src/foo.el\">version here</a>."
207 (goto-char (point-min))
209 '(lambda (x) (save-excursion (eval x)))
210 '((replace-string "rls=" "<a href=\"")
211 (replace-string ";rld=" "\">")
212 (replace-string ";rle" "</a>")
213 (replace-string "<!--" "<!--")
214 (replace-string "-->" "-->")))))
216 ;; I know that the pages generated by `htmlize.el' are valid HTML/CSS and
217 ;; are created by SXEmacs. So I announce the fact by adding the appropriate
218 ;; logos to the bottom of the page, together with a copyright notice. This
219 ;; is the raw HTML for that.
220 (defconst sy-htmlize-appendix
224 <!-- SXEmacs Logo -->
225 <a href=\"http://www.sxemacs.org/\">
226 <img style=\"border:0;width:88px;height:31px\"
227 src=\"/~steve/images/cbsx.png\"
228 alt=\"Created with SXEmacs\"></a>
229 <!-- End SXEmacs Logo -->
231 <!-- Valid XHTML 1.0 / CSS -->
232 <a href=\"http://validator.w3.org/check/referer\">
233 <img style=\"border:0;width:88px;height:31px\"
234 src=\"/~steve/images/valid-html401.png\"
235 alt=\"Valid HTML 4.01 Strict!\"></a>
236 <a href=\"http://jigsaw.w3.org/css-validator/check/referer\">
237 <img style=\"border:0;width:88px;height:31px\"
238 src=\"/~steve/images/vcss.png\"
242 <!-- End Valid HTML / CSS-->
244 <h6>Copyright © 2012 Steve Youngs<br>
245 Verbatim copying and distribution is permitted in any medium,
246 providing this notice is preserved.<br>
253 ;; Appends the above to each page. Run from `htmlize-after-hook'.
254 (defun sy-htmlize-append ()
255 "Append some things to the end of files produced by `htmlize.el'."
256 (goto-char (point-max))
257 (re-search-backward "</body>" nil t)
258 (insert sy-htmlize-appendix))
260 ;; Set a couple of basic things.
262 htmlize-html-charset "UTF-8"
263 htmlize-html-major-mode 'html-mode
265 "<meta name=\"author\" content=\"Steve Youngs\">
266 <meta name=\"owner\" content=\"steve@sxemacs.org\">
270 (add-hook 'htmlize-before-hook 'font-lock-fontify-buffer)
271 (add-hook 'htmlize-after-hook
273 (sy-htmlize-after-hook)
275 (font-lock-fontify-buffer)))
276 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
277 (message "hm--html-mode initialised")