| SGML for Windows NT: Setting up a free SGML/XML editing and publishing system on Windows/Cygwin | ||
|---|---|---|
| Prev | Chapter 6. PSGML and TDTD | Next |
Unpack the PSGML archive
Extract the PSGML archive to your common Emacs site-lisp directory, e.g. C:\Programs\emacsen\site-lisp. Be sure to keep the directory information and long filenames. This will create the subdirectory \psgml-1.2.4
Use onsgmls as an external validator
The following code snippet lets PSGML use onsgmls from the OpenJade distribution (which we will install later) to validate SGML or XML files . Append this to your _emacs file:
(setq sgml-validate-command "/usr/local/bin/onsgmls -s %s %s") |
Byte-compile the PSGML files
To byte-compile all .el files in the psgml-1.2.4 subdirectory, run the command (the "0" is a zero) Ctrl-u 0 Alt-x byte-recompile-directory [Return] psgml-path, where psgml-path is the path to your psgml-directory, e.g. C:/Programs/emacsen/site-lisp/psgml-1.2.4.
Note: If you get error messages like "cannot load file xyz" at this point, make sure that your Emacs load-path contains the PSGML directory. We already included this directory into the load-path when we installed Emacs.
Enable syntax coloring
Edit _emacs to enable syntax coloring. Copy the following lines to your _emacs file (syntax coloring code adapted from David Megginson):
;; Turn on syntax coloring
(cond ((fboundp 'global-font-lock-mode)
;; Turn on font-lock in all modes that support it
(global-font-lock-mode t)
;; maximum colors
(setq font-lock-maximum-decoration t)))
;; load sgml-mode
(autoload 'sgml-mode "psgml" "Major mode to edit SGML files." t )
;; in sgml documents, parse dtd immediately to allow immediate
;; syntax coloring
(setq sgml-auto-activate-dtd t)
;; set the default SGML declaration. docbook.dcl should work for most DTDs
(setq sgml-declaration "c:/cygwin/usr/local/lib/sgml/dtd/docbook41/docbook.dcl")
;; here we set the syntax color information for psgml
(setq-default sgml-set-face t)
;;
;; Faces.
;;
(make-face 'sgml-comment-face)
(make-face 'sgml-doctype-face)
(make-face 'sgml-end-tag-face)
(make-face 'sgml-entity-face)
(make-face 'sgml-ignored-face)
(make-face 'sgml-ms-end-face)
(make-face 'sgml-ms-start-face)
(make-face 'sgml-pi-face)
(make-face 'sgml-sgml-face)
(make-face 'sgml-short-ref-face)
(make-face 'sgml-start-tag-face)
(set-face-foreground 'sgml-comment-face "dark turquoise")
(set-face-foreground 'sgml-doctype-face "red")
(set-face-foreground 'sgml-end-tag-face "blue")
(set-face-foreground 'sgml-entity-face "magenta")
(set-face-foreground 'sgml-ignored-face "gray40")
(set-face-background 'sgml-ignored-face "gray60")
(set-face-foreground 'sgml-ms-end-face "green")
(set-face-foreground 'sgml-ms-start-face "yellow")
(set-face-foreground 'sgml-pi-face "lime green")
(set-face-foreground 'sgml-sgml-face "brown")
(set-face-foreground 'sgml-short-ref-face "deep sky blue")
(set-face-foreground 'sgml-start-tag-face "dark green")
(setq-default sgml-markup-faces
'((comment . sgml-comment-face)
(doctype . sgml-doctype-face)
(end-tag . sgml-end-tag-face)
(entity . sgml-entity-face)
(ignored . sgml-ignored-face)
(ms-end . sgml-ms-end-face)
(ms-start . sgml-ms-start-face)
(pi . sgml-pi-face)
(sgml . sgml-sgml-face)
(short-ref . sgml-short-ref-face)
(start-tag . sgml-start-tag-face)))
;; load xml-mode
(setq auto-mode-alist
(append (list (cons "\\.xml\\'" 'xml-mode))
auto-mode-alist))
(autoload 'xml-mode "psgml" nil t)
(setq sgml-xml-declaration "c:/cygwin/usr/local/lib/sgml/dtd/html/xml.dcl")
|
Use the Edit->Text Properties->Display Colors menu command in Emacs to see a list of supported color values if the colors in the above listing don't work on your system (or if you simply don't like them).
Derive a HTML mode
The following code derives a HTML mode from PSGML and was borrowed from the Debian Linux PSGML package. Insert the following lines into your _emacs file:
;; define html mode
(or (assoc "\\.html$" auto-mode-alist)
(setq auto-mode-alist (cons '("\\.html$" . sgml-html-mode)
auto-mode-alist)))
(or (assoc "\\.htm$" auto-mode-alist)
(setq auto-mode-alist (cons '("\\.htm$" . sgml-html-mode)
auto-mode-alist)))
(defun sgml-html-mode ()
"This version of html mode is just a wrapper around sgml mode."
(interactive)
(sgml-mode)
(make-local-variable 'sgml-declaration)
(make-local-variable 'sgml-default-doctype-name)
(setq
sgml-default-doctype-name "html"
sgml-declaration "c:/cygwin/usr/local/lib/sgml/dtd/html/html.dcl"
sgml-always-quote-attributes t
sgml-indent-step 2
sgml-indent-data t
sgml-minimize-attributes nil
sgml-omittag t
sgml-shorttag t
)
)
(setq-default sgml-indent-data t)
(setq
sgml-always-quote-attributes t
sgml-auto-insert-required-elements t
sgml-auto-activate-dtd t
sgml-indent-data t
sgml-indent-step 2
sgml-minimize-attributes nil
sgml-omittag nil
sgml-shorttag nil
)
|
The path in the variable sgml-declaration in the listing above is again a dummy at the moment. We will adjust this path as soon as all necessary files are installed.