;; 07-html-sy.el --- HTML settings -*- Emacs-Lisp -*- ;; Copyright (C) 2007 - 2013 Steve Youngs ;; Author: Steve Youngs ;; Maintainer: Steve Youngs ;; Created: <2007-12-02> ;; Time-stamp: ;; Download: ;; HTMLised: ;; Git Repo: git clone http://git.sxemacs.org/syinit ;; Keywords: init, compile ;; This file is part of SYinit ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; 1. Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; ;; 2. Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; ;; 3. Neither the name of the author nor the names of any contributors ;; may be used to endorse or promote products derived from this ;; software without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; Commentary: ;; ;; Sets up things for writing HTML. ;;; Credits: ;; ;; The HTML version of this file was created with Hrvoje Niksic's ;; htmlize.el which is part of the XEmacs "text-modes" package. ;; ;;; Todo: ;; ;; ;;; Code: ;:*======================= ;:* General HTML settings. (setq html-helper-htmldtd-version " \n" html-helper-use-expert-menu t hm--html-automatic-create-modified-line t hm--html-automatic-update-modified-line t hm--html-changed-comment-prefix "Changed with SXEmacs, by: " hm--html-created-comment-prefix "Created with SXEmacs, by: " hm--html-expert t hm--html-html-doctype-version "\"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"" hm--html-log-date-format "%y-%m-%d" hm--html-template-dir (file-name-as-directory (expand-file-name "templates" (locate-data-directory "hm--html-menus"))) hm--html-frame-template-file (expand-file-name "frame.html.tmpl" hm--html-template-dir) hm--html-title-date-format "%y-%m-%d" hm--html-username "Steve Youngs" html-sigusr1-signal-value 10) ;; SGML stuff. (setq sgml-auto-activate-dtd t sgml-live-element-indicator t sgml-validate-command "onsgmls -s -m %s %s") (defvar sy-sgml-dirs (directory-files-recur "/usr/share/sgml" 'full nil nil 'subdir) "List of directories for `sgml-system-path'.") (setq sgml-system-path (append '("." "/usr/share/sxemacs/xemacs-packages/etc/psgml-dtds/") sy-sgml-dirs)) (autoload 'html-mode "psgml-html" "Load psgml-html-mode" t) (autoload 'css-mode "css-mode") (add-hook 'html-mode-hook #'hm--html-minor-mode) (eval-when-compile (defvar ispell-extra-args)) (add-hook 'html-mode-hook #'(lambda () (make-local-variable 'ispell-extra-args) (push "-H" ispell-extra-args))) (add-hook 'html-helper-timestamp-hook #'html-helper-default-insert-timestamp) ;:*======================= ;:* Hrvoje Niksic's htmlize ;; ;; `htmlize.el' comes with the "text-modes" XEmacs package, or you ;; can get the latest version from: ;; ;; . ;; ;; `htmlize.el' is a lovely piece of code for converting Emacs buffers ;; into HTML. The default settings should be fine for most people most ;; of the time in most situations. But, by now, I'm sure that you've ;; come to the realisation that I don't fit into that category. So ;; lets hack... :-) (eval-and-compile (require 'htmlize)) ;; Those "local-variables" declarations you sometimes see at the bottom ;; of source files can cause quite a bit of havoc when it comes to ;; "htmlize'ing" them. Basically what happens is that when you go to ;; save the resulting HTML buffer XEmacs goes into an infinite loop ;; complaining about bad local vars. I get around it with this next ;; function which just a simple wrapper for `htmlize-buffer'. (defun sy-htmlize-buffer (&optional buffer) "This is just a simple wrapper for `htmlize-buffer'. All it does is scan the buffer to be converted for any local variable declarations and replaces them with a place holder. This prevents an infloop when you go to save the resulting HTML buffer. Original `htmlize-buffer' doc string: Convert buffer to HTML, preserving the font-lock colorization. The generated HTML is available in a new buffer, which is returned. When invoked interactively, the new buffer is selected in the current window." (interactive) (let ((htmlbuf (with-current-buffer (or buffer (current-buffer)) (goto-char (point-min)) (while (re-search-forward ;; This concat is deliberately split accross ;; 4 lines for a reason. Don't change it! (concat "^" comment-start "Local" " Variables:$") nil t) (replace-match (concat comment-start " Put the normal local variables declaration here"))) (htmlize-buffer-1) ;; Undo that replace-match. (when (buffer-modified-p) (undo))))) (when (interactive-p) (switch-to-buffer htmlbuf)) htmlbuf)) ;; Use my function by default. (defalias 'htmlize-buffer 'sy-htmlize-buffer) ;; This function, run from `htmlize-after-hook' lets me embed HTML ;; comments inside normal source comments and also allows me to set up ;; relative hyperlinks. It has been hand-massaged after htmlizing to ;; get the desired results for its doc string. (defun sy-htmlize-after-hook () "Function run from `htmlize-after-hook'. It takes care of any relative hyperlinks and also dequotes any HTML comments that were incorrectly quoted. Relative hyperlinks need to be prepared in a particular way in the file that is to be converted to HTML. For example, in an emacs lisp file you might see: Get the latest rls=/src/foo.el;rld=version here;rle. Which would be converted to: Get the latest version here." (save-excursion (goto-char (point-min)) (mapcar '(lambda (x) (save-excursion (eval x))) '((replace-string "rls=" "") (replace-string ";rle" "") (replace-string "<!--" ""))))) ;; I know that the pages generated by `htmlize.el' are valid HTML/CSS and ;; are created by SXEmacs. So I announce the fact by adding the appropriate ;; logos to the bottom of the page, together with a copyright notice. This ;; is the raw HTML for that. (defconst sy-htmlize-appendix "


\"Created \"Valid \"Valid

Copyright © 2012 Steve Youngs
Verbatim copying and distribution is permitted in any medium, providing this notice is preserved.
") ;; Appends the above to each page. Run from `htmlize-after-hook'. (defun sy-htmlize-append () "Append some things to the end of files produced by `htmlize.el'." (goto-char (point-max)) (re-search-backward "" nil t) (insert sy-htmlize-appendix)) ;; Set a couple of basic things. (setq htmlize-html-charset "UTF-8" htmlize-html-major-mode 'html-mode htmlize-head-tags " ") ;; Hooks (add-hook 'htmlize-before-hook 'font-lock-fontify-buffer) (add-hook 'htmlize-after-hook #'(lambda () (sy-htmlize-after-hook) (sy-htmlize-append) (font-lock-fontify-buffer))) ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::* (message "hm--html-mode initialised")