;; The following lines are useful for DocBook Mode
;; They are from Bob DuCharme bob@snee.com

(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)))

(autoload 'sgml-mode "psgml" "Major mode to edit SGML files." t)
(autoload 'xml-mode "psgml" "Major mode to edit XML files." t)

;; set the default SGML declaration. docbook.dcl should work for most DTDs
(setq sgml-declaration "/usr/lib/sgml/docbook.dcl")

; here we set the syntax color information for psgml
(setq-default sgml-set-face t)

(defun sgml-lt ()
  "Insert ISO entity reference for less-than."
  (interactive)
  (insert "<"))

(defun sgml-para ()
  "Insert para tags and position cursor."
  (interactive)
  (sgml-insert-element 'para))

(defun index-tag ()
  "Copy marked section to a primary index tag for it."
  (interactive)
  (kill-ring-save (point)(mark))
  (sgml-insert-element 'indexterm)
  (yank))

(defun index-tag-sec ()
  "Add secondary index element. Assumes cursor at end of primary element content."
  (interactive)
  (sgml-next-data-field)
  (sgml-insert-element 'secondary))

(defun sgml-comment ()
  "Insert SGML comment and position cursor."
  (interactive)
  (insert "<!--  -->")
  (backward-char 4));; PSGML menus for creating new documents

;; PSGML menus for creating new documents
(setq sgml-custom-dtd
'(
   ( "HTML 4"
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">")
   ( "DocBook 4.1"
   "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\">")
   )
)

(defun psgml-ext ()
"Useful set of keystrokes for sgml mode"
;;Define some keys for customizing sgml mode
(define-key sgml-mode-map "\C-c<" 'sgml-lt)
(define-key sgml-mode-map "\C-c&" 'sgml-amp)
(define-key sgml-mode-map "\C-cp" 'sgml-para)
(define-key sgml-mode-map "\C-cx" 'index-tag)
(define-key sgml-mode-map "\C-cy" 'index-tag-sec)
;;  right-click selected element for edit attributes popup
(define-key sgml-mode-map [mouse-3] 'sgml-attrib-menu)
(define-key sgml-mode-map "\C-co" 'sgml-comment)
(setq sgml-set-face t)  ; without this, all SGML text is in same color
(setq sgml-markup-faces
      '((comment   . font-lock-comment-face)
        (start-tag . font-lock-keyword-face)
        (end-tag   . font-lock-keyword-face)
        (doctype   . font-lock-builtin-face)
        (entity    . font-lock-constant-face)))
;;Use the spanish dictionary
(ispell-change-dictionary "castellano8")
(setq ispell-personal-dictionary "~/.ispell-esp")
)

(add-hook 'sgml-mode-hook 'psgml-ext)
(add-hook 'xml-mode-hook  'psgml-ext)

;;For setting the auto fill mode
(setq text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))

;; For omitting the insertion of comments
;; (setq sgml-insert-missing-element-comment nil)
;; in sgml documents, parse dtd immediately to allow immediate
;; syntax coloring
;;(setq sgml-auto-activate-dtd t)