Jak je to s psgml modem [reseni]

Dan Ohnesorg dan na ohnesorg.cz
Sobota Únor 24 22:15:28 CET 2001


Takze jsem se ponoril hluboko do psgml modu a mam nasledujici poznatky. 

Pred pouzivanim psgml modu musite nastavit nasledujici promennnou:

SGML_CATALOG_FILES=/etc/sgml/catalog:/usr/share/sgml/catalog:....

na soubory, ktere se jmenuji catalog a jsou ruzne umisteny podle toho, kam
jste instalovali dtd definice. Do cesty se daji pridat i soubory s
priponou .cat. Jsou to vlastne stejne soubory, jen zrejme pouzivaji jiny
nazev. Tyto soubory obsahuji "ukazkove" hlavicky xml a sgml souboru a
nazvy souboru, kde se nachazi patricne definice.

Po otevreni souboru je nutne nejdrive provest prikaz Parse DTD. To nejakou
dobu trva, takze je lepsi potom definici ulozit pres Save Parsed
DTD. Teprve v teto chvili zacne psgml obarvovat. Nekdy se mu moc neche a
spravi to az klik strednim tlacitkem mysi na nejaky tag na konci
dokumentu.

Obarvovani je normalne definovano jen jako tucne pismo. Takze je lepsi
pridat si do .emacs neco takovehleho:

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

  (setq-default sgml-set-face t)
  ;;
  ;; Faces.
  ;;
  (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 "dark green")
  (set-face-foreground 'sgml-doctype-face "maroon")
  (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 "green")

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


(defvar sgml-font-lock-keywords
  '(; Highlight the text between these tags in SGML mode.
      ("<indexterm[^>]*>" . font-lock-comment-face)
      ("</indexterm>" . font-lock-comment-face)
      ("<primary[^<]+</primary>" . font-lock-comment-face)
      ("<secondary[^<]+</secondary>" . font-lock-comment-face)
      ("<see[^<]+</see>" . font-lock-comment-face)
      ("<seealso[^<]+</seealso>" . font-lock-comment-face)
   )
  "Additional expressions to highlight in SGML mode.")

  (setq font-lock-defaults '(sgml-font-lock-keywords t))

(defun sgml-elname ()
   "Insert sgmltag element for an element type name."
   (interactive)
   (insert "<sgmltag class=\"element\"></sgmltag>")
   (backward-char 10))

(defun sgml-atname ()
   "Insert sgmltag element for an attribute name."
   (interactive)
   (insert "<sgmltag class=\"attribute\"></sgmltag>")
   (backward-char 10))

; right-click selected element for edit attributes popup
(define-key sgml-mode-map [mouse-3] 'sgml-attrib-menu)
(custom-set-faces)

Tim dosahnete funkcniho obarvovani. 

Doufam, ze to bude vsem k uzitku.

zdravim
dan




Další informace o konferenci Linux