Post by Henry LawIf I should post this in an emacs group please say so. I tossed a coin
to decide ...
I think you've come to the right place :-)
Post by Henry LawI'm following a very good article at
http://www.ibm.com/developerworks/xml/library/x-emacs/ which steps one
through installing psgml as an emacs mode and then setting catalogs and
all that. It's all fine until I come to actually do something with the
psgml mode. The screenshot in the Developerworks article (direct link
at
http://www.ibm.com/developerworks/xml/library/x-emacs/emacspsgmlcallout.gif)
shows a whole list of menu items - SGML, Modify, Move, Markup, View and
DTD, but all I have is "SGML". I've checked through all the menus and
the "DTD" menu - which is the next one I want in order to validate
what's going on - isn't there anywhere. So when the article author says
"click on the menu item DTD->Info->General DTD Info ..." I'm a bit stuck.
The primary thing is to make sure that your .emacs file contains a line
telling Emacs where to find add-one like psgml. This file ought to have
been installed when you installed Emacs, but under Windows I beliee it
doesn't get put in the right place, which is C:\
You also have to install SP, which contains the onsgmls parser, so that
you can validate documents. Without this, psgml makes a good shot at
guiding your editing, but won't be able to do a formal validation.
I don't know where you have installed psgml, but in Unix-like systems it
would typically go in /usr/local/share/emacs/site-lisp, in a
subsirectory called psgml. If it's installed via a system-controlled
package installer (perhaps along with Emacs itself), then it may go in
/usr/share/emacs/site-lisp instead.
The site-lisp directory is traditionally THE place where add-on Emacs
packages go (that is, the ones installed by you for your system, as
opposed to the ones installed automatically along with Emacs itself).
On a Windows machine I have no idea where this is, perhaps C:\Program
Files\NTEmacs\site-lisp or something like. And I have no idea if spaces
in the path will break it or not.
Either way, you must have a .emacs file in your home directory. On a
Unix-like system this is /home/hlaw (or whatever your login name is) or
on a shared system perhaps /usr/users/hlaw. On a Windows box, it's C:\
The filename must be .emacs, not anything else. On Windows you may have
to fiddle with your settings in My Computer under View to UNcheck the
option "Hide file extensions for well-known types" or soemthing, so that
you can actually see the .emacs name. And if you create it with Notepad,
make sure it doesn't add .txt to the end of the name :-)
Then the top line of your .emacs file must say
Post by Henry Law(setq load-path (cons (expand-file-name "/usr/local/share/emacs/site-lisp") load-path))
Change the path in quotes to the site-lisp directory you use. In
Windows, use forward slashes rather than backslashes for safety
(although I think modern versions of NTEmacs understand backslashes in
filepaths). Now add
Post by Henry Law(autoload 'sgml-mode "psgml" "Major mode to edit SGML files." t )
to .emacs. This makes Emacs find and load psgml when you start up.
Post by Henry Law(setq auto-mode-alist (cons '("\\.[Ss][Gg][Mm][Ll]*$" . sgml-mode) auto-mode-alist))
which invokes psgml for .sgm and .sgml files. You can change the RE to
Post by Henry Law(setq auto-mode-alist (cons '("\\.[EeMmSs][GgNnOo][DdMmTt][Ll]*$" . sgml-mode) auto-mode-alist))
(The Windows file system is case-insensitive, so you probably don't need
to double up the letters if you use Windows).
To enable psgml to find your Catalog file, add a line saying where it
Post by Henry Law(setq sgml-catalog-files '("catalog" "/usr/local/lib/sgml/CATALOG"))
Finally, having installed SP, you need to tell psgml where to find your
Post by Henry Law(setq sgml-declaration "/usr/local/lib/sgml/teisgml.dec")
You may have several SGML Declarations for different document types. I
believe using the Catalog to resolve these on a per-DTD basis will work,
but I have never done so.
Post by Henry Law(setq sgml-validate-command "/usr/bin/onsgmls -s -c/usr/local/lib/sgml/CATALOG %s %s")
The onsgmls parser uses the -s option to suppress the ESIS output, which
you don't normally want for a validation. There is no space between the
-c option and the path to the catalog. The first %s will be replaced by
the value of sgml-declaration, and the second %s will be replaced by the
name of your current SGML document.
HOWEVER...
Are you really using SGML, or are you using XML?
Psgmls contains a derived mode called xml-mode, so you may want to add
Post by Henry Law(autoload 'xml-mode "psgml" "Major mode to edit XML files." t )
(setq auto-mode-alist (cons '("\\.[XxRrMmDdTt][TtMmDdSsNnEe][AaMmLlFfSsIi]?[Pp]*$" . xml-mode) auto-mode-alist))
This invokes xml-mode for .xml, .rdf, and a whole bunch of others.
Personally, I recommend using François Pinard's xxml-mode in addition to
psgml, as it does re-indentation better, and the syntactic colorization
is nicer. You used to be able to download it from
http://www.iro.umontreal.ca/~pinard/fp-etc/dist/xxml/xxml.el but it's
disappeared. My own copy is at http://xml.silmaril.ie/software/xxml.el
To get it working, just add
Post by Henry Law(autoload 'xxml-mode-routine "xxml")
(add-hook 'sgml-mode-hook 'xxml-mode-routine)
to your .emacs. To make onsgmls work with XML files, you must have a
copy of the XML Declaration for SGML, then add these two lines to .emacs
Post by Henry Law(setq sgml-xml-declaration "/usr/share/xml/declaration/xml.dcl")
(setq sgml-xml-validate-command "/usr/bin/onsgmls -wxml -s %s %s")
Tony Graham's dtd-mode (tdtd.el) is a mode for editing DTD files.
Recommended if you want to start writing your own, or modifying other
people's.
Post by Henry Law(autoload 'dtd-mode "tdtd" "Major mode for SGML and XML DTDs.")
;; Turn on font lock when in DTD mode
(add-hook 'dtd-mode-hooks 'turn-on-font-lock)
(setq auto-mode-alist (cons '("\\.[EeMmDd][CcEeTtNnOo][LlCcDdTt]$" . dtd-mode) auto-mode-alist)
I found that psgml wouldn't recognise the underscore or colon in Names
Post by Henry Law;; ----------------------------------------
;; Add '_' as a legal name character for PSGML
(defun my-psgml-hook ()
(require 'psgml-parse)
(modify-syntax-entry ?_ "w" sgml-parser-syntax))
(add-hook 'sgml-mode-hook 'my-psgml-hook)
;; Try the same again: add ':' as a legal name character for PSGML
(defun her-psgml-hook ()
(require 'psgml-parse)
(modify-syntax-entry ?: "w" sgml-parser-syntax))
(add-hook 'sgml-mode-hook 'her-psgml-hook)
This works, but a more recent version of psgml-mode may have added this
itself, making the above unnecessary.
Two more: if you want Unicode support, add
Post by Henry Law(load-file "/usr/local/share/emacs/site-lisp/xmlunicode.el")
The files xmlunicode.el and unichars.el (which it calls) are in
http://xml.silmaril.ie/software if you can't find them anywhere else.
And if you want to write and process XSL[T], then you need Tony's XSL
IDE (xsl-mode) and an XSL processor like Saxon. This works the same way
Post by Henry Law;; XSL mode
(autoload 'xsl-mode "xslide" "Major mode for XSL stylesheets." t)
;; Turn on font lock when in XSL mode
(add-hook 'xsl-mode-hook 'turn-on-font-lock)
(setq auto-mode-alist (cons '("\\.[Xx][Ss][Ll]$" . xsl-mode) auto-mode-alist)
///Peter
--
XML FAQ: http://xml.silmaril.ie/