Quick docfix
[syinit] / 07-html-sy.el
1 ;; 07-html-sy.el --- HTML settings   -*- Emacs-Lisp -*-
2
3 ;; Copyright (C) 2007 - 2013 Steve Youngs
4
5 ;;     Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;;    Created: <2007-12-02>
8 ;; Time-stamp: <Friday May 15, 2015 22:21:58 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
13
14 ;; This file is part of SYinit
15
16 ;; Redistribution and use in source and binary forms, with or without
17 ;; modification, are permitted provided that the following conditions
18 ;; are met:
19 ;;
20 ;; 1. Redistributions of source code must retain the above copyright
21 ;;    notice, this list of conditions and the following disclaimer.
22 ;;
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.
26 ;;
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.
30 ;;
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.
42
43 ;;; Commentary:
44 ;;
45 ;;   Sets up things for writing HTML.
46
47 ;;; Credits:
48 ;;
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.
51 ;;
52
53 ;;; Todo:
54 ;;
55 ;;     
56
57 ;;; Code:
58 ;:*=======================
59 ;:* General HTML settings.
60 (setq
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: "
70  hm--html-expert t
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"
75  hm--html-template-dir 
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)
84
85 ;; SGML stuff.
86 (setq
87  sgml-auto-activate-dtd t
88  sgml-live-element-indicator t
89  sgml-validate-command "onsgmls -s -m  %s %s")
90
91 (defvar sy-sgml-dirs
92   (directory-files-recur "/usr/share/sgml" 'full nil nil 'subdir)
93   "List of directories for `sgml-system-path'.")
94
95 (setq sgml-system-path
96       (append '("." 
97                 "/usr/share/sxemacs/xemacs-packages/etc/psgml-dtds/")
98               sy-sgml-dirs))
99
100 (autoload 'html-mode "psgml-html" "Load psgml-html-mode" t)
101 (autoload 'css-mode "css-mode")
102
103 (add-hook 'html-mode-hook #'hm--html-minor-mode)
104 (eval-when-compile (defvar ispell-extra-args))
105 (add-hook 'html-mode-hook
106           #'(lambda ()
107               (make-local-variable 'ispell-extra-args)
108               (push "-H" ispell-extra-args)))
109 (add-hook 'html-helper-timestamp-hook #'html-helper-default-insert-timestamp)
110
111 ;:*=======================
112 ;:* Hrvoje Niksic's htmlize
113 ;;
114 ;;  `htmlize.el' comes with the "text-modes" XEmacs package, or you
115 ;;  can get the latest version from:
116 ;;
117 ;;      <http://fly.srk.fer.hr/~hniksic/emacs/htmlize.el>.
118 ;;
119 ;;  `htmlize.el' is a lovely piece of code for converting Emacs buffers
120 ;;  into HTML.  The default settings should be fine for most people most
121 ;;  of the time in most situations.  But, by now, I'm sure that you've
122 ;;  come to the realisation that I don't fit into that category.  So
123 ;;  lets hack... :-)
124 (eval-and-compile
125   (require 'htmlize))
126
127 ;; Those "local-variables" declarations you sometimes see at the bottom
128 ;; of source files can cause quite a bit of havoc when it comes to
129 ;; "htmlize'ing" them.  Basically what happens is that when you go to
130 ;; save the resulting HTML buffer XEmacs goes into an infinite loop
131 ;; complaining about bad local vars.  I get around it with this next
132 ;; function which just a simple wrapper for `htmlize-buffer'.
133 (defun sy-htmlize-buffer (&optional buffer)
134   "This is just a simple wrapper for `htmlize-buffer'.
135
136 All it does is scan the buffer to be converted for any local variable
137 declarations and replaces them with a place holder.  This prevents an
138 infloop when you go to save the resulting HTML buffer.
139
140 Original `htmlize-buffer' doc string:
141
142 Convert buffer to HTML, preserving the font-lock colorization.
143 The generated HTML is available in a new buffer, which is returned.
144 When invoked interactively, the new buffer is selected in the
145 current window."
146   (interactive)
147   (let ((htmlbuf (with-current-buffer (or buffer (current-buffer))
148                    (goto-char (point-min))
149                    (while (re-search-forward
150                            ;; This concat is deliberately split accross
151                            ;; 4 lines for a reason.  Don't change it!
152                            (concat "^" 
153                                    comment-start 
154                                    "Local"
155                                    " Variables:$") nil t)
156                      (replace-match 
157                       (concat comment-start
158                               " Put the normal local variables declaration here")))
159                    (htmlize-buffer-1)
160                    ;; Undo that replace-match.
161                    (when (buffer-modified-p)
162                      (undo)))))
163     (when (interactive-p)
164       (switch-to-buffer htmlbuf))
165     htmlbuf))
166
167 ;; Use my function by default.
168 (defalias 'htmlize-buffer 'sy-htmlize-buffer)
169
170 ;; This function, run from `htmlize-after-hook' lets me embed HTML
171 ;; comments inside normal source comments and also allows me to set up
172 ;; relative hyperlinks.  It has been hand-massaged after htmlizing to
173 ;; get the desired results for its doc string.
174 (defun sy-htmlize-after-hook ()
175   "Function run from `htmlize-after-hook'.
176
177 It takes care of any relative hyperlinks and also dequotes any HTML
178 comments that were incorrectly quoted.
179
180 Relative hyperlinks need to be prepared in a particular way in the
181 file that is to be converted to HTML.  For example, in an emacs lisp
182 file you might see:
183
184 Get the latest rls=/src/foo.el;rld=version here;rle.
185
186 Which would be converted to:
187
188 Get the latest <a href=\"/src/foo.el\">version here</a>."
189   (save-excursion
190     (goto-char (point-min))
191     (mapcar
192      '(lambda (x) (save-excursion (eval x)))
193      '((replace-string "rls=" "<a href=\"")
194        (replace-string ";rld=" "\">")
195        (replace-string ";rle" "</a>")
196        (replace-string "&lt;!--" "<!--")
197        (replace-string "--&gt;" "-->")))))
198
199 ;; I know that the pages generated by `htmlize.el' are valid HTML/CSS and
200 ;; are created by SXEmacs.  So I announce the fact by adding the appropriate
201 ;; logos to the bottom of the page, together with a copyright notice.  This
202 ;; is the raw HTML for that.
203 (defconst sy-htmlize-appendix
204   "<!--  Logos -->
205 <p>
206 <br>
207 <!--  SXEmacs Logo -->
208     <a href=\"http://www.sxemacs.org/\">
209 <img style=\"border:0;width:88px;height:31px\"
210      src=\"/~steve/images/cbsx.png\" 
211      alt=\"Created with SXEmacs\"></a>
212 <!--  End SXEmacs Logo -->
213
214 <!--  Valid XHTML 1.0 / CSS -->
215       <a href=\"http://validator.w3.org/check/referer\">
216         <img style=\"border:0;width:88px;height:31px\"
217           src=\"/~steve/images/valid-html401.png\"
218           alt=\"Valid HTML 4.01 Strict!\"></a>
219  <a href=\"http://jigsaw.w3.org/css-validator/check/referer\">
220   <img style=\"border:0;width:88px;height:31px\"
221        src=\"/~steve/images/vcss.png\" 
222        alt=\"Valid CSS!\">
223  </a>
224 </p>
225 <!--  End Valid HTML / CSS-->
226
227     <h6>Copyright &#169; 2015 Steve Youngs<br>
228      Verbatim copying and distribution is permitted in any medium,
229     providing this notice is preserved.<br>
230 <!-- hhmts start -->
231 <!-- hhmts end -->
232    </h6>
233
234 ")
235
236 ;; Appends the above to each page.  Run from `htmlize-after-hook'.
237 (defun sy-htmlize-append ()
238   "Append some things to the end of files produced by `htmlize.el'."
239   (goto-char (point-max))
240   (re-search-backward "</body>" nil t)
241   (insert sy-htmlize-appendix))
242
243 ;; Set a couple of basic things.
244 (setq
245  htmlize-html-charset "UTF-8"
246  htmlize-html-major-mode 'html-mode
247  htmlize-head-tags
248  "<meta name=\"author\" content=\"Steve Youngs\">
249 <meta name=\"owner\" content=\"steve@sxemacs.org\">
250 ")
251
252 ;; Hooks
253 (add-hook 'htmlize-before-hook 'font-lock-fontify-buffer)
254 (add-hook 'htmlize-after-hook 
255           #'(lambda ()
256               (sy-htmlize-after-hook)
257               (sy-htmlize-append)
258               (font-lock-fontify-buffer)))
259 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
260 (message "hm--html-mode initialised")