Chapter 3. Emacs and PSGML Mode

3.1. Setting Up Your .emacs File
3.2. Customizing Emacs
3.3. Create Recompiled DTD Subset
3.4. Load the Parsed DTD
3.5. Basic Emacs Commands
3.6. Examples
3.6.1. Tag Completion
3.6.2. Tag Closure
3.6.3. Other Emacs Tasks
3.7. Additional Resources

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.

3.1. Setting Up Your .emacs File

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)