Книга: Learning GNU Emacs, 3rd Edition

8.4.4 Using psgml Mode

8.4.4 Using psgml Mode

Lennart Stafflin's psgml mode has been around for a while. It is more robust than Emacs's own SGML mode, but, like any add-on, you have to install it in order to use it. Either install TEI Emacs as described earlier or download psgml mode from http://www.lysator.liu.se/projects/about_psgml.html and follow the installation instructions there. TEI Emacs includes a functioning psgml mode, so if you've installed TEI Emacs, your setup work is done.

psgml mode consists of two parts: sgml-mode for writing SGML and xml-mode for writing XML (and in our case XHTML).

To start psgml mode to edit our XHTML file, type M-x xml-mode.


XML appears on the mode line and an *SGML LOG* window opens. If you are using TEI Emacs, XSLT appears on the mode line along with XML.

The *SGML LOG* window displays messages about this session. (If it doesn't appear immediately, click on the first character in the file.) The log buffer complains that it could not find an external entity called html. This file has been changed to work with the XHTML RELAX NG schema. psgml mode expects it to conform to an XHTML DTD. To get started with the (minimal) work needed to undertake the transformation from a schema-based file to a DTD-based file, we ask psgml to normalize the buffer.

Type: M-x sgml-normalize or select Normalize from the Modify menu


psgml mode eliminates the namespace declaration in the <html> tag.

More needs to be done, however. The first statements in an XHTML file include an XML statement and a DOCTYPE entry that identifies the DTD this document should be validated against. One of the nice things about TEI Emacs is that it includes a variety of DTDs. (Users of standard psgml mode don't have this feature; sorry.[52])

At the beginning of the file, select DTD ? Insert DTD ? XHTML Transitional.


Emacs inserts the two required elements for us.

That's all it takes to make this file a well-formed XHTML file. psgml mode allows for validation against the DTD. Let's validate it using C-c C-v to make sure it's okay.

Type: C-c C-v


psgml mode inserts the default validate command in the minibuffer; press Enter to run it.

Press Enter and type y to save the buffer when prompted


The *compilation* buffer indicates (somewhat cryptically) that the document is valid.

Of course, typical documents are far more complex than this one. Options on the View menu provide selective hiding and showing of elements, including an option to hide all tags, allowing you to focus on the content of the file instead.

psgml mode also offers numerous options. If you are running TEI Emacs, you'll find the File Options and User Options submenus on the XML/SGML menu. If you've installed psgml mode standalone, you'll find them on the SGML menu. Table 8-8 summarizes some of the psgml commands.

Table 8-8. Bindings in psgml mode

Keystrokes Command name Action
C-M-Space sgml-mark-element Mark the current element.
M-Tab sgml-complete Complete the current tag.
C-M-t sgml-transpose-element Transpose two elements.
C-M-h sgml-mark-current-element Mark the current element.
C-M-k Modify ? Kill Element sgml-kill-element Delete the current element (and any child elements).
C-M-u Move ? Backward Up Element sgml-backward-up-element Move up to the parent element for this element.
C-M-d Move ? Down Element sgml-down-element Move down to the next child element.
C-M-b Move ? Backward Element sgml-backward-element Move to the previous element.
C-M-f Move ? Forward Element sgml-forward-element Move to the next element.
C-M-e Move ? End of Element sgml-end-of-element Move to the end of the current element.
C-M-a Move ? Beginning of Element sgml-beginning-of-element Move to the beginning of the current element.
C-c C-w SGML ? What Element sgml-what-element Similar to sgml-position but describes hierarchy in terms of tags versus content (for example, start-tag in title in head in html).
C-c C-v SGML ? Validate sgml-validate Insert validation command in the minibuffer so you can modify it if necessary before pressing Enter to execute it.
C-c C-t SGML ? List Valid Tags sgml-list-valid-tags List tags that are valid in the current context.
C-c C-q Modify ? Fill Element sgml-fill-element Fill element according to the mode's indentation rules.
C-c C-o Move ? Next Trouble Spot sgml-next-trouble-spot Find the next problem spot and display the problem in the minibuffer.
C-c C-n Move ? Up Element sgml-up-element Move to the parent element.
C-c Enter sgml-split-element Split current element.
C-c C-l SGML ? Show/Hide Warning Log sgml-show-or-clear-log Display or delete the SGML LOG buffer (menu option name is misleading).
C-c C-k Modify ? Kill Markup sgml-kill-markup Delete current tag.
C-c / Markup ? End Current Element sgml-insert-end-tag Insert closing tag for current tag.
C-c - Modify ? Untag Element sgml-untag-element Delete the current tag pair.
C-c # Modify ? Make Character Reference sgml-make-character-reference Change character under the cursor to the equivalent entity.
C-c C-f C-e View ? Fold Element sgml-fold-element Hide the current element and its children if any.
C-c C-u C-e View ? Unfold Element sgml-unfold-element Show the current element and its children if any.
C-c C-f C-s View ? Fold Subelement sgml-fold-subelement Hide subelements.
C-c C-f C-r View ? Fold Region sgml-fold-region Hide the region.
C-c C-u C-a View ? Unfold All sgml-unfold-all Show all hidden tags and text.

Оглавление книги


Генерация: 1.220. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз