home *** CD-ROM | disk | FTP | other *** search
- ;; SGML mode.
- ;; Copyright (C) 1992 James Clark (jjc@jclark.com)
- ;; Parts derived from blink-matching-open in simple.el, which is
- ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
-
- ;; This file is not yet part of GNU Emacs.
-
- ;; GNU Emacs is free software; you can redistribute it and/or modify
- ;; it under the terms of the GNU General Public License as published by
- ;; the Free Software Foundation; either version 1, or (at your option)
- ;; any later version.
-
- ;; GNU Emacs is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
- ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ;; GNU General Public License for more details.
-
- ;; You should have received a copy of the GNU General Public License
- ;; along with GNU Emacs; see the file COPYING. If not, write to
- ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-
- ;; Some suggestions for your .emacs file:
- ;;
- ;; (autoload 'sgml-mode "sgml-mode" "SGML mode" t)
- ;;
- ;; (setq auto-mode-alist
- ;; (append (list (cons "\\.sgm$" 'sgml-mode)
- ;; (cons "\\.sgml$" 'sgml-mode)
- ;; (cons "\\.dtd$" 'sgml-mode))
- ;; auto-mode-alist))
-
- (provide 'sgml-mode)
- (require 'compile)
-
- ;;; sgmls is a free SGML parser available from
- ;;; ftp.uu.net:pub/text-processing/sgml
- ;;; Its error messages can be parsed by next-error.
- ;;; The -s option suppresses output.
-
- (defconst sgml-validate-command
- "sgmls -s"
- "*The command to validate an SGML document.
- The file name of current buffer file name will be appended to this,
- separated by a space.")
-
- (defvar sgml-saved-validate-command nil
- "The command last used to validate in this buffer.")
-
- (defvar sgml-mode-map nil "Keymap for SGML mode")
-
- (if sgml-mode-map
- ()
- (setq sgml-mode-map (make-sparse-keymap))
- (define-key sgml-mode-map ">" 'sgml-close-angle)
- (define-key sgml-mode-map "/" 'sgml-slash)
- (define-key sgml-mode-map "\C-c\C-v" 'sgml-validate))
-
- (defun sgml-mode ()
- "Major mode for editing SGML.
- Makes > display the matching <. Makes / display matching /.
- Use \\[sgml-validate] to validate your document with an SGML parser."
- (interactive)
- (kill-all-local-variables)
- (setq local-abbrev-table text-mode-abbrev-table)
- (use-local-map sgml-mode-map)
- (setq mode-name "SGML")
- (setq major-mode 'sgml-mode)
- (make-local-variable 'paragraph-start)
- ;; A start or end tag by itself on a line separates a paragraph.
- ;; This is desirable because SGML discards a newline that appears
- ;; immediately after a start tag or immediately before an end tag.
- (setq paragraph-start
- "^[ \t\n]\\|\
- \\(</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$\\)")
- (make-local-variable 'paragraph-separate)
- (setq paragraph-separate
- "^[ \t\n]*$\\|\
- ^</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$")
- (make-local-variable 'sgml-saved-validate-command)
- (set-syntax-table text-mode-syntax-table)
- (make-local-variable 'comment-start)
- (setq comment-start "<!-- ")
- (make-local-variable 'comment-end)
- (setq comment-end " -->")
- (make-local-variable 'comment-indent-hook)
- (setq comment-indent-hook 'sgml-comment-indent)
- (make-local-variable 'comment-start-skip)
- ;; This will allow existing comments within declarations to be
- ;; recognized.
- (setq comment-start-skip "--[ \t]*")
- (run-hooks 'text-mode-hook 'sgml-mode-hook))
-
- (defun sgml-comment-indent ()
- (if (and (looking-at "--")
- (not (and (eq (char-after (1- (point))) ?!)
- (eq (char-after (- (point) 2)) ?<))))
- (progn
- (skip-chars-backward " \t")
- (max comment-column (1+ (current-column))))
- 0))
-
- (defconst sgml-start-tag-regex
- "<[A-Za-z]\\([-.A-Za-z0-9= \n\t]\\|\"[^\"]*\"\\|'[^']*'\\)*"
- "Regular expression that matches a non-empty start tag.
- Any terminating > or / is not matched.")
-
- (defvar sgml-mode-markup-syntax-table nil
- "Syntax table used for scanning SGML markup.")
-
- (if sgml-mode-markup-syntax-table
- ()
- (setq sgml-mode-markup-syntax-table (make-syntax-table))
- (modify-syntax-entry ?< "(>" sgml-mode-markup-syntax-table)
- (modify-syntax-entry ?> ")<" sgml-mode-markup-syntax-table)
- (modify-syntax-entry ?- "_ 1234" sgml-mode-markup-syntax-table)
- (modify-syntax-entry ?\' "\"" sgml-mode-markup-syntax-table))
-
- (defconst sgml-angle-distance 4000
- "*If non-nil, is the maximum distance to search for matching <
- when > is inserted.")
-
- (defun sgml-close-angle (arg)
- "Insert > and display matching <."
- (interactive "p")
- (insert-char ?> arg)
- (if (> arg 0)
- (let ((oldpos (point))
- (blinkpos))
- (save-excursion
- (save-restriction
- (if sgml-angle-distance
- (narrow-to-region (max (point-min)
- (- (point) sgml-angle-distance))
- oldpos))
- ;; See if it's the end of a marked section.
- (and (> (- (point) (point-min)) 3)
- (eq (char-after (- (point) 2)) ?\])
- (eq (char-after (- (point) 3)) ?\])
- (re-search-backward "<!\\[\\(-?[A-Za-z0-9. \t\n&;]\\|\
-