annotate lisp/textmodes/sgml-mode.el @ 3254:e1f5f8f23d90

(do-install): Delete redundant code to copy etc twice.
author Richard M. Stallman <rms@gnu.org>
date Sat, 29 May 1993 16:38:15 +0000
parents 8cf203c42bee
children 4db64c9c1f05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
809
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1 ;;; sgml-mode.el --- SGML-editing mode
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2
844
bf829a2d63b4 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 828
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
bf829a2d63b4 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 828
diff changeset
4
869
7861f8756850 entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 844
diff changeset
5 ;; Author: James Clark <jjc@clark.com>
809
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
6 ;; Adapted-By: ESR
814
38b2499cb3e9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 809
diff changeset
7 ;; Keywords: wp
809
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
8
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
10
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 1, or (at your option)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
14 ;; any later version.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
15
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
19 ;; GNU General Public License for more details.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
20
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
24
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
25 ;;; Commentary:
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
26
2315
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
27 ;; Major mode for editing the SGML document-markup language.
9e7ec92a4fdf Added or corrected Commentary headers
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2307
diff changeset
28 ;;
809
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
29 ;; Some suggestions for your .emacs file:
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
30 ;;
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
31 ;; (autoload 'sgml-mode "sgml-mode" "SGML mode" t)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
32 ;;
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
33 ;; (setq auto-mode-alist
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
34 ;; (append (list (cons "\\.sgm$" 'sgml-mode)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
35 ;; (cons "\\.sgml$" 'sgml-mode)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
36 ;; (cons "\\.dtd$" 'sgml-mode))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
37 ;; auto-mode-alist))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
38
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
39 ;;; Code:
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
40
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
41 (provide 'sgml-mode)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
42 (require 'compile)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
43
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
44 ;;; sgmls is a free SGML parser available from
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
45 ;;; ftp.uu.net:pub/text-processing/sgml
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
46 ;;; Its error messages can be parsed by next-error.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
47 ;;; The -s option suppresses output.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
48
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
49 (defconst sgml-validate-command
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
50 "sgmls -s"
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
51 "*The command to validate an SGML document.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
52 The file name of current buffer file name will be appended to this,
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
53 separated by a space.")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
54
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
55 (defvar sgml-saved-validate-command nil
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
56 "The command last used to validate in this buffer.")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
57
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
58 (defvar sgml-mode-map nil "Keymap for SGML mode")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
59
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
60 (if sgml-mode-map
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
61 ()
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
62 (setq sgml-mode-map (make-sparse-keymap))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
63 (define-key sgml-mode-map ">" 'sgml-close-angle)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
64 (define-key sgml-mode-map "/" 'sgml-slash)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
65 (define-key sgml-mode-map "\C-c\C-v" 'sgml-validate))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
66
3121
8cf203c42bee (sgml-validate): compile1 renamed to compile-internal.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
67 ;;;###autoload
809
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
68 (defun sgml-mode ()
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
69 "Major mode for editing SGML.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
70 Makes > display the matching <. Makes / display matching /.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
71 Use \\[sgml-validate] to validate your document with an SGML parser."
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
72 (interactive)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
73 (kill-all-local-variables)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
74 (setq local-abbrev-table text-mode-abbrev-table)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
75 (use-local-map sgml-mode-map)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
76 (setq mode-name "SGML")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
77 (setq major-mode 'sgml-mode)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
78 (make-local-variable 'paragraph-start)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
79 ;; A start or end tag by itself on a line separates a paragraph.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
80 ;; This is desirable because SGML discards a newline that appears
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
81 ;; immediately after a start tag or immediately before an end tag.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
82 (setq paragraph-start
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
83 "^[ \t\n]\\|\
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
84 \\(</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$\\)")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
85 (make-local-variable 'paragraph-separate)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
86 (setq paragraph-separate
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
87 "^[ \t\n]*$\\|\
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
88 ^</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
89 (make-local-variable 'sgml-saved-validate-command)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
90 (set-syntax-table text-mode-syntax-table)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
91 (make-local-variable 'comment-start)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
92 (setq comment-start "<!-- ")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
93 (make-local-variable 'comment-end)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
94 (setq comment-end " -->")
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 869
diff changeset
95 (make-local-variable 'comment-indent-function)
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 869
diff changeset
96 (setq comment-indent-function 'sgml-comment-indent)
809
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
97 (make-local-variable 'comment-start-skip)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
98 ;; This will allow existing comments within declarations to be
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
99 ;; recognized.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
100 (setq comment-start-skip "--[ \t]*")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
101 (run-hooks 'text-mode-hook 'sgml-mode-hook))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
102
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
103 (defun sgml-comment-indent ()
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
104 (if (and (looking-at "--")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
105 (not (and (eq (char-after (1- (point))) ?!)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
106 (eq (char-after (- (point) 2)) ?<))))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
107 (progn
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
108 (skip-chars-backward " \t")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
109 (max comment-column (1+ (current-column))))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
110 0))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
111
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
112 (defconst sgml-start-tag-regex
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
113 "<[A-Za-z]\\([-.A-Za-z0-9= \n\t]\\|\"[^\"]*\"\\|'[^']*'\\)*"
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
114 "Regular expression that matches a non-empty start tag.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
115 Any terminating > or / is not matched.")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
116
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
117 (defvar sgml-mode-markup-syntax-table nil
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
118 "Syntax table used for scanning SGML markup.")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
119
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
120 (if sgml-mode-markup-syntax-table
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
121 ()
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
122 (setq sgml-mode-markup-syntax-table (make-syntax-table))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
123 (modify-syntax-entry ?< "(>" sgml-mode-markup-syntax-table)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
124 (modify-syntax-entry ?> ")<" sgml-mode-markup-syntax-table)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
125 (modify-syntax-entry ?- "_ 1234" sgml-mode-markup-syntax-table)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
126 (modify-syntax-entry ?\' "\"" sgml-mode-markup-syntax-table))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
127
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
128 (defconst sgml-angle-distance 4000
3121
8cf203c42bee (sgml-validate): compile1 renamed to compile-internal.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
129 "*If non-nil, is the maximum distance to search for matching <.")
809
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
130
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
131 (defun sgml-close-angle (arg)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
132 "Insert > and display matching <."
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
133 (interactive "p")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
134 (insert-char ?> arg)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
135 (if (> arg 0)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
136 (let ((oldpos (point))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
137 (blinkpos))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
138 (save-excursion
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
139 (save-restriction
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
140 (if sgml-angle-distance
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
141 (narrow-to-region (max (point-min)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
142 (- (point) sgml-angle-distance))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
143 oldpos))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
144 ;; See if it's the end of a marked section.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
145 (and (> (- (point) (point-min)) 3)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
146 (eq (char-after (- (point) 2)) ?\])
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
147 (eq (char-after (- (point) 3)) ?\])
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
148 (re-search-backward "<!\\[\\(-?[A-Za-z0-9. \t\n&;]\\|\
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
149 --\\([^-]\\|-[^-]\\)*--\\)*\\["
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
150 (point-min)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
151 t)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
152 (let ((msspos (point)))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
153 (if (and (search-forward "]]>" oldpos t)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
154 (eq (point) oldpos))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
155 (setq blinkpos msspos))))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
156 ;; This handles cases where the > ends one of the following:
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
157 ;; markup declaration starting with <! (possibly including a
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
158 ;; declaration subset); start tag; end tag; SGML declaration.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
159 (if blinkpos
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
160 ()
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
161 (goto-char oldpos)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
162 (condition-case ()
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
163 (let ((oldtable (syntax-table))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
164 (parse-sexp-ignore-comments t))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
165 (unwind-protect
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
166 (progn
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
167 (set-syntax-table sgml-mode-markup-syntax-table)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
168 (setq blinkpos (scan-sexps oldpos -1)))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
169 (set-syntax-table oldtable)))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
170 (error nil))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
171 (and blinkpos
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
172 (goto-char blinkpos)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
173 (or
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
174 ;; Check that it's a valid delimiter in context.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
175 (not (looking-at
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
176 "<\\(\\?\\|/?[A-Za-z>]\\|!\\([[A-Za-z]\\|--\\)\\)"))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
177 ;; Check that it's not a net-enabling start tag
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
178 ;; nor an unclosed start-tag.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
179 (looking-at (concat sgml-start-tag-regex "[/<]"))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
180 ;; Nor an unclosed end-tag.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
181 (looking-at "</[A-Za-z][-.A-Za-z0-9]*[ \t]*<"))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
182 (setq blinkpos nil)))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
183 (if blinkpos
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
184 ()
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
185 ;; See if it's the end of a processing instruction.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
186 (goto-char oldpos)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
187 (if (search-backward "<?" (point-min) t)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
188 (let ((pipos (point)))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
189 (if (and (search-forward ">" oldpos t)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
190 (eq (point) oldpos))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
191 (setq blinkpos pipos))))))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
192 (if blinkpos
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
193 (progn
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
194 (goto-char blinkpos)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
195 (if (pos-visible-in-window-p)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
196 (sit-for 1)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
197 (message "Matches %s"
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
198 (buffer-substring blinkpos
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
199 (progn (end-of-line)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
200 (point)))))))))))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
201
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
202 ;;; I doubt that null end tags are used much for large elements,
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
203 ;;; so use a small distance here.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
204 (defconst sgml-slash-distance 1000
3121
8cf203c42bee (sgml-validate): compile1 renamed to compile-internal.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
205 "*If non-nil, is the maximum distance to search for matching /.")
809
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
206
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
207 (defun sgml-slash (arg)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
208 "Insert / and display any previous matching /.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
209 Two /s are treated as matching if the first / ends a net-enabling
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
210 start tag, and the second / is the corresponding null end tag."
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
211 (interactive "p")
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
212 (insert-char ?/ arg)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
213 (if (> arg 0)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
214 (let ((oldpos (point))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
215 (blinkpos)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
216 (level 0))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
217 (save-excursion
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
218 (save-restriction
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
219 (if sgml-slash-distance
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
220 (narrow-to-region (max (point-min)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
221 (- (point) sgml-slash-distance))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
222 oldpos))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
223 (if (and (re-search-backward sgml-start-tag-regex (point-min) t)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
224 (eq (match-end 0) (1- oldpos)))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
225 ()
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
226 (goto-char (1- oldpos))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
227 (while (and (not blinkpos)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
228 (search-backward "/" (point-min) t))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
229 (let ((tagend (save-excursion
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
230 (if (re-search-backward sgml-start-tag-regex
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
231 (point-min) t)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
232 (match-end 0)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
233 nil))))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
234 (if (eq tagend (point))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
235 (if (eq level 0)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
236 (setq blinkpos (point))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
237 (setq level (1- level)))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
238 (setq level (1+ level)))))))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
239 (if blinkpos
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
240 (progn
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
241 (goto-char blinkpos)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
242 (if (pos-visible-in-window-p)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
243 (sit-for 1)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
244 (message "Matches %s"
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
245 (buffer-substring (progn
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
246 (beginning-of-line)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
247 (point))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
248 (1+ blinkpos))))))))))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
249
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
250 (defun sgml-validate (command)
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
251 "Validate an SGML document.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
252 Runs COMMAND, a shell command, in a separate process asynchronously
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
253 with output going to the buffer *compilation*.
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
254 You can then use the command \\[next-error] to find the next error message
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
255 and move to the line in the SGML document that caused it."
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
256 (interactive
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
257 (list (read-string "Validate command: "
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
258 (or sgml-saved-validate-command
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
259 (concat sgml-validate-command
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
260 " "
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
261 (let ((name (buffer-file-name)))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
262 (and name
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
263 (file-name-nondirectory name))))))))
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
264 (setq sgml-saved-validate-command command)
3121
8cf203c42bee (sgml-validate): compile1 renamed to compile-internal.
Richard M. Stallman <rms@gnu.org>
parents: 2315
diff changeset
265 (compile-internal command "No more errors"))
809
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
266
8a0066235d56 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
267 ;;; sgml-mode.el ends here