%FEDORA-ENTITIES-EN; ]> Emacs and PSGML Mode PSGML Emacs Emacs PSGML mode You can use the PSGML mode available for Emacs to make it easier to write in XML format. PSGML mode provides syntax-highlighting, tag completion, and more.
Setting Up Your <filename>.emacs</filename> File Emacs configuration file .emacs For Emacs to parse your DocBook documents correctly, you must have a .emacs file. Cut and paste the following into your existing .emacs file or create a new one that contains the following lines: ;; turn on auto-fill in `text-mode' and derived modes ;;(mail, news, etc) (add-hook 'text-mode-hook 'turn-on-auto-fill) ;; ;;MODES ;; (setq auto-mode-alist (cons '("\\.sgml$" . sgml-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.sgm$" . sgml-mode) auto-mode-alist)) ;; ;;XML!! ;; ;;############################################################# ;; ;;PSGML mode stuff ;; (autoload 'sgml-mode "psgml" "My Most Major Mode" t) (setq sgml-mode-hook '(lambda () "Defaults for XML mode." (turn-on-auto-fill) (setq fill-column 80))) (defun My-XML-keymap () (local-set-key [(alt i)] '(lambda () (interactive) (sgml-indent-line) (sgml-insert-element 'item) (sgml-indent-line))) (local-set-key [(alt l)] '(lambda () (interactive) (sgml-insert-element 'list) (sgml-insert-element 'item) (sgml-indent-line))) (local-set-key [(alt p)] '(lambda () (interactive) (sgml-indent-line) (sgml-insert-element 'para) (sgml-indent-line))) (local-set-key [(alt -)] '(lambda () (interactive) (insert "—")))) (add-hook 'sgml-mode-hook 'My-XML-keymap) ;; ;; Fix up indentation of data... ;; (setq-default sgml-indent-data t) ;; ;; XML markup faces. ;; (setq-default sgml-set-face t) (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 "maroon") (set-face-foreground 'sgml-doctype-face "dark green") (set-face-foreground 'sgml-end-tag-face "blue2") (set-face-foreground 'sgml-entity-face "red2") (set-face-foreground 'sgml-ignored-face "maroon") (set-face-background 'sgml-ignored-face "gray90") (set-face-foreground 'sgml-ms-end-face "maroon") (set-face-foreground 'sgml-ms-start-face "maroon") (set-face-foreground 'sgml-pi-face "maroon") (set-face-foreground 'sgml-sgml-face "maroon") (set-face-foreground 'sgml-short-ref-face "goldenrod") (set-face-foreground 'sgml-start-tag-face "blue2") (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))) (defun docbook-mode () (sgml-mode) ) ;; ;;END XML STUFF ;; ;;################################################################## ;PO mode stuff (setq auto-mode-alist (cons '("\\.pox?\\'" . po-mode) auto-mode-alist)) (autoload 'po-mode "po-mode") (global-set-key [(f1)] (lambda () (interactive) (manual- entry (current-word)))) Do you have a cool wheel mouse? If so, you can add the following to your .emacs file so your wheel will work in Emacs (must be Emacs version 21): ;; Enable wheelmouse support by default for emacs 21 (cond (window-system (mwheel-install) )) If you are using the older version 20 of Emacs, add the following instead: ;; Enable wheelmouse support by default (require 'mwheel)
Customizing Emacs Emacs customizing .Xresources Emacs colors Emacs font Emacs geometry The colors, font, and geometry (default size of window) for Emacs in your ~/.Xresources file. The format for the settings is emacs.keyword:value The following is a sample ~/.Xresources file. Note If you have other settings in your ~/.Xresources, add the following to the end of the file. emacs.background: light gray emacs.foreground: black emacs.pointerColor: blue emacs.cursorColor: blue emacs.bitmapIcon: on emacs.font: fixed emacs.geometry: 90x25 After modifying this file, you must execute the command xrdb -merge ~/.Xresources and restart Emacs for the changes to take place.
Create Recompiled DTD Subset Emacs will perform syntax highlighting and indent correctly on DocBook XML files if you provide it with the proper Document Type Declarations (DTD) file. These two features will make your XML file look pretty and help you spot errors. To create a loadable Parsed DTD file: Find the parent file for the group of DocBook files. You will recognize this file by the header <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.1//EN". An easy way to find this parent file is to use the command grep DocBook *.xml. Once you find the parent file, open it in Emacs with the command emacs <parentfile>.xml (where <parentfile>.xml is the parent file you found. Choose DTD -> Parse DTD from the pulldown menu. You will know the parsing is finished when you see the message Fontifying...done at the bottom of your screen. Save the parsed DTD to a file by choosing DTD -> Save Parsed DTD from the pulldown menu. Press Enter to save the file to the default filename or rename the file keeping the .ced extension. It can be useful to name it something generic such as docbook.ced so you can refer to it when opening all DocBook files. This file can also be copied from directory to directory to be loaded. Tip You can also use the Emacs command Meta-x sgml-parse-prolog to parse the file, and then use the command Meta-x sgml-save-dtd to save the parsed DTD to a .ced file.
Load the Parsed DTD Now that you have saved the DTD settings, you can load the .ced file and see the syntax highlighting for your .sgml files. To load a parsed DTD file: Open an XML file in Emacs. Choose DTD -> Load DTD from the pulldown menu and choose the file you saved from the previous step. For instance, choose docbook.ced. You will know it is finished when you see the message Fontifying...done at the bottom of your screen. Loading the parsed DTD might take a long time. You can start editing the file before it finishes. Tip You can also use the Emacs command Meta-x sgml-load-dtd to load the parsed DTD.
Basic Emacs Commands The Meta key is usually the Alt key. Emacs Commands Shortcut Description Metax sgml-parse-prolog, Enter Parse DTD Metax sgml-save-dtd, Enter Save the Parse DTD Metax sgml-load-dtd, Enter Load DTD Ctrl c , Shift , Tab Display list of valid tags Ctrl c , Shift , type beginning of tag, Tab Complete the tag Ctrl g Cancel a command in the minibuffer Ctrl c , / Close tag Ctrl a Move cursor to beginning of line Ctrle Move cursor to the end of the line CtrlHome Move cursor to the beginning of the file CtrlEnd Move cursor to the end of the file Ctrlk Cut line Ctrl y Paste line Ctrl s Search forward in the file Ctrlr Search backwards in the file Meta$ Check spelling of current word Metax ispell-word, Enter Check spelling of current word Metax ispell-buffer, Enter Check spelling of current buffer Ctrlx , Ctrlf Open file Ctrlx , Ctrls Save file Ctrlx , Ctrlc Exit Emacs and prompt to save files if necessary Meta q Fill paragraph Ctrlc , Ctrla Edit attributes for a tag (for example, you can edit the url attribute of the ulink tag) Ctrl c , Ctrlc Exit edit attributes
Examples The table or reference card of Emacs and PSGML commands can be confusing for beginners. This section provides some examples of how to use them.
Tag Completion Note This section assumes that you have already loaded the DTD file (.ced). Instead of typing a tag each time you need to use it, use the key combination Ctrl-c, followed by <. At the bottom of the Emacs window, you will see: Tag: < To view a list of available tags, use either the Tab or ?. Or, if you know the first few letters of a tag, you can enter them followed by Tab for a complete list of available tags beginning with those letters or for a tag completion. Try the following: Type Ctrl-c followed by <. Then enter the letter k, followed by Tab. You may have to use the Tab key several times to get a complete list. The output should look similar to the example below: Click mouse-2 on a completion to select it. In this buffer, type RET to select the completion near point. Possible completions are: <keycap> <keycode> <keycombo> <keysym>
Tag Closure Once you have started the tag of choice, you must close it. The easiest way to close an open tag is to use the keycombo Ctrl-c, followed by /. This will close the closest open tag you have.
Other Emacs Tasks Working with one window: Sometimes in Emacs the window becomes split (with tags completions or other text in the bottom window). The easiest way to get it back so that only your XML and text appear on one screen is to use the keycombo Ctrl-x, followed by 1. Saving your work: To save your work, use the following keycombo, Ctrl-x followed by Ctrl-s. The "clear/quit" command: I have found on some occasions that I have gotten too far into the tag completion process and need to just exit back out to my text. The easiest way to do this is the keycombo Ctrl-g. This command quits what you have been doing within the file, without quitting the file itself. Opening a new file: To open a new file, use the keycombo Ctrl-x followed by Ctrl-f. At the bottom of the emacs window, you will be able to enter in the file name (using Tab completion if needed) of the file you wish to open. Closing emacs: The easiest way to close emacs is to use the keycombo Ctrl-x followed by Ctrl-c. If you have not saved your work, it will prompt you to save the file, otherwise it will just quit the current emacs session you have been working with.
Additional Resources Additional Emacs and PSGML references are available at the following locations: http://wks.uts.ohio-state.edu/unix_course/intro-135.htmlEmacs Quick Reference Guide Emacs reference card that comes with the emacs package. You can print it out as a reference. — /usr/share/emacs/<version>/etc/refcard.ps Read Editing XML with Emacs and PSGML in /usr/share/doc/psgml-<version>/psgml.ps. http://www.snee.com/bob/sgmlfree/psgmqref.htmlEmacs/PSGML Quick Reference is a reference table of Emacs commands for PSGML mode. http://www.snee.com/bob/sgmlfree/emcspsgm.htmlPSGML Tricks