home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / www / cern / doc / www-talk.archive.Z / www-talk.archive / partapplication-octet-stream340 < prev    next >
Encoding:
Text File  |  1992-11-30  |  4.9 KB  |  140 lines

  1. ;; SGML mode.
  2. ;; Copyright (C) 1992 James Clark (jjc@jclark.com)
  3. ;; Parts derived from blink-matching-open in simple.el, which is
  4. ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
  5.  
  6. ;; This file is not yet part of GNU Emacs.
  7.  
  8. ;; GNU Emacs is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 1, or (at your option)
  11. ;; any later version.
  12.  
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;; GNU General Public License for more details.
  17.  
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  20. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. ;; Some suggestions for your .emacs file:
  23. ;;
  24. ;; (autoload 'sgml-mode "sgml-mode" "SGML mode" t)
  25. ;;
  26. ;; (setq auto-mode-alist
  27. ;;       (append (list (cons "\\.sgm$" 'sgml-mode)
  28. ;;                     (cons "\\.sgml$"  'sgml-mode)
  29. ;;                     (cons "\\.dtd$" 'sgml-mode))
  30. ;;               auto-mode-alist))
  31.  
  32. (provide 'sgml-mode)
  33. (require 'compile)
  34.  
  35. ;;; sgmls is a free SGML parser available from
  36. ;;; ftp.uu.net:pub/text-processing/sgml
  37. ;;; Its error messages can be parsed by next-error.
  38. ;;; The -s option suppresses output.
  39.  
  40. (defconst sgml-validate-command
  41.   "sgmls -s"
  42.   "*The command to validate an SGML document.
  43. The file name of current buffer file name will be appended to this,
  44. separated by a space.")
  45.  
  46. (defvar sgml-saved-validate-command nil
  47.   "The command last used to validate in this buffer.")
  48.  
  49. (defvar sgml-mode-map nil "Keymap for SGML mode")
  50.  
  51. (if sgml-mode-map
  52.     ()
  53.   (setq sgml-mode-map (make-sparse-keymap))
  54.   (define-key sgml-mode-map ">" 'sgml-close-angle)
  55.   (define-key sgml-mode-map "/" 'sgml-slash)
  56.   (define-key sgml-mode-map "\C-c\C-v" 'sgml-validate))
  57.  
  58. (defun sgml-mode ()
  59.   "Major mode for editing SGML.
  60. Makes > display the matching <.  Makes / display matching /.
  61. Use \\[sgml-validate] to validate your document with an SGML parser."
  62.   (interactive)
  63.   (kill-all-local-variables)
  64.   (setq local-abbrev-table text-mode-abbrev-table)
  65.   (use-local-map sgml-mode-map)
  66.   (setq mode-name "SGML")
  67.   (setq major-mode 'sgml-mode)
  68.   (make-local-variable 'paragraph-start)
  69.   ;; A start or end tag by itself on a line separates a paragraph.
  70.   ;; This is desirable because SGML discards a newline that appears
  71.   ;; immediately after a start tag or immediately before an end tag.
  72.   (setq paragraph-start
  73.     "^[ \t\n]\\|\
  74. \\(</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$\\)")
  75.   (make-local-variable 'paragraph-separate)
  76.   (setq paragraph-separate
  77.     "^[ \t\n]*$\\|\
  78. ^</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$")
  79.   (make-local-variable 'sgml-saved-validate-command)
  80.   (set-syntax-table text-mode-syntax-table)
  81.   (make-local-variable 'comment-start)
  82.   (setq comment-start "<!-- ")
  83.   (make-local-variable 'comment-end)
  84.   (setq comment-end " -->")
  85.   (make-local-variable 'comment-indent-hook)
  86.   (setq comment-indent-hook 'sgml-comment-indent)
  87.   (make-local-variable 'comment-start-skip)
  88.   ;; This will allow existing comments within declarations to be
  89.   ;; recognized.
  90.   (setq comment-start-skip "--[ \t]*")
  91.   (run-hooks 'text-mode-hook 'sgml-mode-hook))
  92.  
  93. (defun sgml-comment-indent ()
  94.   (if (and (looking-at "--")
  95.        (not (and (eq (char-after (1- (point))) ?!)
  96.              (eq (char-after (- (point) 2)) ?<))))
  97.       (progn
  98.     (skip-chars-backward " \t")
  99.     (max comment-column (1+ (current-column))))
  100.     0))
  101.  
  102. (defconst sgml-start-tag-regex
  103.   "<[A-Za-z]\\([-.A-Za-z0-9= \n\t]\\|\"[^\"]*\"\\|'[^']*'\\)*"
  104.   "Regular expression that matches a non-empty start tag.
  105. Any terminating > or / is not matched.")
  106.  
  107. (defvar sgml-mode-markup-syntax-table nil
  108.   "Syntax table used for scanning SGML markup.")
  109.  
  110. (if sgml-mode-markup-syntax-table
  111.     ()
  112.   (setq sgml-mode-markup-syntax-table (make-syntax-table))
  113.   (modify-syntax-entry ?< "(>" sgml-mode-markup-syntax-table)
  114.   (modify-syntax-entry ?> ")<" sgml-mode-markup-syntax-table)
  115.   (modify-syntax-entry ?- "_ 1234" sgml-mode-markup-syntax-table)
  116.   (modify-syntax-entry ?\' "\"" sgml-mode-markup-syntax-table))
  117.  
  118. (defconst sgml-angle-distance 4000
  119.   "*If non-nil, is the maximum distance to search for matching <
  120. when > is inserted.")
  121.  
  122. (defun sgml-close-angle (arg)
  123.   "Insert > and display matching <."
  124.   (interactive "p")
  125.   (insert-char ?> arg)
  126.   (if (> arg 0)
  127.       (let ((oldpos (point))
  128.         (blinkpos))
  129.     (save-excursion
  130.       (save-restriction
  131.         (if sgml-angle-distance
  132.         (narrow-to-region (max (point-min)
  133.                        (- (point) sgml-angle-distance))
  134.                   oldpos))
  135.         ;; See if it's the end of a marked section.
  136.         (and (> (- (point) (point-min)) 3)
  137.          (eq (char-after (- (point) 2)) ?\])
  138.          (eq (char-after (- (point) 3)) ?\])
  139.          (re-search-backward "<!\\[\\(-?[A-Za-z0-9. \t\n&;]\\|\
  140.