(sgml-validate): Use `compilation-start'
[bpt/emacs.git] / lisp / textmodes / sgml-mode.el
CommitLineData
1caf38eb 1;;; sgml-mode.el --- SGML- and HTML-editing modes
72c0ae01 2
3731a850
TTN
3;; Copyright (C) 1992, 1995, 1996, 1998, 2001, 2002, 2003, 2004,
4;; 2005 Free Software Foundation, Inc.
6d74b528 5
64ae0c23 6;; Author: James Clark <jjc@jclark.com>
0fda8eff 7;; Maintainer: FSF
3e910376 8;; Adapted-By: ESR, Daniel Pfeiffer <occitan@esperanto.org>,
a391b179 9;; F.Potorti@cnuce.cnr.it
1caf38eb 10;; Keywords: wp, hypermedia, comm, languages
72c0ae01 11
72c0ae01
ER
12;; This file is part of GNU Emacs.
13
14;; GNU Emacs is free software; you can redistribute it and/or modify
15;; it under the terms of the GNU General Public License as published by
7c938215 16;; the Free Software Foundation; either version 2, or (at your option)
72c0ae01
ER
17;; any later version.
18
19;; GNU Emacs is distributed in the hope that it will be useful,
20;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;; GNU General Public License for more details.
23
24;; You should have received a copy of the GNU General Public License
b578f267 25;; along with GNU Emacs; see the file COPYING. If not, write to the
4fc5845f
LK
26;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27;; Boston, MA 02110-1301, USA.
72c0ae01
ER
28
29;;; Commentary:
30
1caf38eb
RS
31;; Configurable major mode for editing document in the SGML standard general
32;; markup language. As an example contains a mode for editing the derived
33;; HTML hypertext markup language.
72c0ae01
ER
34
35;;; Code:
36
d4c89075
DL
37(eval-when-compile
38 (require 'skeleton)
a06283b1
MW
39 (require 'outline)
40 (require 'cl))
b0a377e6 41
64ae0c23 42(defgroup sgml nil
fae1a906 43 "SGML editing mode."
64ae0c23
RS
44 :group 'languages)
45
5f3d924d
SM
46(defcustom sgml-basic-offset 2
47 "*Specifies the basic indentation level for `sgml-indent-line'."
48 :type 'integer
49 :group 'sgml)
50
d10447ba 51(defcustom sgml-transformation 'identity
a391b179
RS
52 "*Default value for `skeleton-transformation' (which see) in SGML mode."
53 :type 'function
c60e7b0d 54 :group 'sgml)
a391b179
RS
55
56(put 'sgml-transformation 'variable-interactive
57 "aTransformation function: ")
58
d4c89075
DL
59(defcustom sgml-mode-hook nil
60 "Hook run by command `sgml-mode'.
61`text-mode-hook' is run first."
62 :group 'sgml
63 :type 'hook)
64
1caf38eb
RS
65;; As long as Emacs' syntax can't be complemented with predicates to context
66;; sensitively confirm the syntax of characters, we have to live with this
67;; kludgy kind of tradeoff.
21a6f23c 68(defvar sgml-specials '(?\")
f788776c 69 "List of characters that have a special meaning for SGML mode.
140d71ba 70This list is used when first loading the `sgml-mode' library.
1caf38eb
RS
71The supported characters and potential disadvantages are:
72
73 ?\\\" Makes \" in text start a string.
74 ?' Makes ' in text start a string.
75 ?- Makes -- in text start a comment.
76
4fa91cfe 77When only one of ?\\\" or ?' are included, \"'\" or '\"', as can be found in
1caf38eb 78DTDs, start a string. To partially avoid this problem this also makes these
21a6f23c
RS
79self insert as named entities depending on `sgml-quick-keys'.
80
81Including ?- has the problem of affecting dashes that have nothing to do
82with comments, so we normally turn it off.")
fcc3195e
RS
83
84(defvar sgml-quick-keys nil
2394187c 85 "Use <, >, &, /, SPC and `sgml-specials' keys \"electrically\" when non-nil.
140d71ba 86This takes effect when first loading the `sgml-mode' library.")
1caf38eb 87
1caf38eb 88(defvar sgml-mode-map
e1940c83 89 (let ((map (make-keymap)) ;`sparse' doesn't allow binding to charsets.
1caf38eb 90 (menu-map (make-sparse-keymap "SGML")))
1caf38eb
RS
91 (define-key map "\C-c\C-i" 'sgml-tags-invisible)
92 (define-key map "/" 'sgml-slash)
fcc3195e
RS
93 (define-key map "\C-c\C-n" 'sgml-name-char)
94 (define-key map "\C-c\C-t" 'sgml-tag)
1caf38eb
RS
95 (define-key map "\C-c\C-a" 'sgml-attributes)
96 (define-key map "\C-c\C-b" 'sgml-skip-tag-backward)
97 (define-key map [?\C-c left] 'sgml-skip-tag-backward)
98 (define-key map "\C-c\C-f" 'sgml-skip-tag-forward)
99 (define-key map [?\C-c right] 'sgml-skip-tag-forward)
100 (define-key map "\C-c\C-d" 'sgml-delete-tag)
101 (define-key map "\C-c\^?" 'sgml-delete-tag)
102 (define-key map "\C-c?" 'sgml-tag-help)
f6ab0573 103 (define-key map "\C-c/" 'sgml-close-tag)
1caf38eb
RS
104 (define-key map "\C-c8" 'sgml-name-8bit-mode)
105 (define-key map "\C-c\C-v" 'sgml-validate)
b4f05c38
SS
106 (when sgml-quick-keys
107 (define-key map "&" 'sgml-name-char)
108 (define-key map "<" 'sgml-tag)
109 (define-key map " " 'sgml-auto-attributes)
110 (define-key map ">" 'sgml-maybe-end-tag)
111 (when (memq ?\" sgml-specials)
112 (define-key map "\"" 'sgml-name-self))
113 (when (memq ?' sgml-specials)
114 (define-key map "'" 'sgml-name-self)))
f7ac3e28
SM
115 (define-key map (vector (make-char 'latin-iso8859-1))
116 'sgml-maybe-name-self)
2840d653
EZ
117 (let ((c 127)
118 (map (nth 1 map)))
119 (while (< (setq c (1+ c)) 256)
120 (aset map c 'sgml-maybe-name-self)))
1caf38eb
RS
121 (define-key map [menu-bar sgml] (cons "SGML" menu-map))
122 (define-key menu-map [sgml-validate] '("Validate" . sgml-validate))
123 (define-key menu-map [sgml-name-8bit-mode]
124 '("Toggle 8 Bit Insertion" . sgml-name-8bit-mode))
125 (define-key menu-map [sgml-tags-invisible]
126 '("Toggle Tag Visibility" . sgml-tags-invisible))
127 (define-key menu-map [sgml-tag-help]
128 '("Describe Tag" . sgml-tag-help))
129 (define-key menu-map [sgml-delete-tag]
130 '("Delete Tag" . sgml-delete-tag))
131 (define-key menu-map [sgml-skip-tag-forward]
132 '("Forward Tag" . sgml-skip-tag-forward))
133 (define-key menu-map [sgml-skip-tag-backward]
134 '("Backward Tag" . sgml-skip-tag-backward))
135 (define-key menu-map [sgml-attributes]
136 '("Insert Attributes" . sgml-attributes))
137 (define-key menu-map [sgml-tag] '("Insert Tag" . sgml-tag))
138 map)
139 "Keymap for SGML mode. See also `sgml-specials'.")
140
1c1d2eb6
SM
141(defun sgml-make-syntax-table (specials)
142 (let ((table (make-syntax-table text-mode-syntax-table)))
1caf38eb
RS
143 (modify-syntax-entry ?< "(>" table)
144 (modify-syntax-entry ?> ")<" table)
1c1d2eb6
SM
145 (modify-syntax-entry ?: "_" table)
146 (modify-syntax-entry ?_ "_" table)
147 (modify-syntax-entry ?. "_" table)
148 (if (memq ?- specials)
1caf38eb 149 (modify-syntax-entry ?- "_ 1234" table))
1c1d2eb6 150 (if (memq ?\" specials)
1caf38eb 151 (modify-syntax-entry ?\" "\"\"" table))
1c1d2eb6 152 (if (memq ?' specials)
1caf38eb 153 (modify-syntax-entry ?\' "\"'" table))
1c1d2eb6
SM
154 table))
155
156(defvar sgml-mode-syntax-table (sgml-make-syntax-table sgml-specials)
1caf38eb
RS
157 "Syntax table used in SGML mode. See also `sgml-specials'.")
158
1c1d2eb6
SM
159(defconst sgml-tag-syntax-table
160 (let ((table (sgml-make-syntax-table '(?- ?\" ?\'))))
161 (dolist (char '(?\( ?\) ?\{ ?\} ?\[ ?\] ?$ ?% ?& ?* ?+ ?/))
162 (modify-syntax-entry char "." table))
163 table)
164 "Syntax table used to parse SGML tags.")
165
64ae0c23 166(defcustom sgml-name-8bit-mode nil
2840d653 167 "*When non-nil, insert non-ASCII characters as named entities."
64ae0c23
RS
168 :type 'boolean
169 :group 'sgml)
72c0ae01 170
1caf38eb
RS
171(defvar sgml-char-names
172 [nil nil nil nil nil nil nil nil
173 nil nil nil nil nil nil nil nil
174 nil nil nil nil nil nil nil nil
175 nil nil nil nil nil nil nil nil
a391b179 176 "nbsp" "excl" "quot" "num" "dollar" "percnt" "amp" "apos"
1caf38eb
RS
177 "lpar" "rpar" "ast" "plus" "comma" "hyphen" "period" "sol"
178 nil nil nil nil nil nil nil nil
179 nil nil "colon" "semi" "lt" "eq" "gt" "quest"
180 "commat" nil nil nil nil nil nil nil
181 nil nil nil nil nil nil nil nil
182 nil nil nil nil nil nil nil nil
183 nil nil nil "lsqb" nil "rsqb" "uarr" "lowbar"
184 "lsquo" nil nil nil nil nil nil nil
185 nil nil nil nil nil nil nil nil
186 nil nil nil nil nil nil nil nil
187 nil nil nil "lcub" "verbar" "rcub" "tilde" nil
188 nil nil nil nil nil nil nil nil
189 nil nil nil nil nil nil nil nil
190 nil nil nil nil nil nil nil nil
191 nil nil nil nil nil nil nil nil
192 "nbsp" "iexcl" "cent" "pound" "curren" "yen" "brvbar" "sect"
193 "uml" "copy" "ordf" "laquo" "not" "shy" "reg" "macr"
194 "ring" "plusmn" "sup2" "sup3" "acute" "micro" "para" "middot"
e79ad8a1 195 "cedil" "sup1" "ordm" "raquo" "frac14" "frac12" "frac34" "iquest"
1caf38eb
RS
196 "Agrave" "Aacute" "Acirc" "Atilde" "Auml" "Aring" "AElig" "Ccedil"
197 "Egrave" "Eacute" "Ecirc" "Euml" "Igrave" "Iacute" "Icirc" "Iuml"
198 "ETH" "Ntilde" "Ograve" "Oacute" "Ocirc" "Otilde" "Ouml" nil
199 "Oslash" "Ugrave" "Uacute" "Ucirc" "Uuml" "Yacute" "THORN" "szlig"
200 "agrave" "aacute" "acirc" "atilde" "auml" "aring" "aelig" "ccedil"
201 "egrave" "eacute" "ecirc" "euml" "igrave" "iacute" "icirc" "iuml"
202 "eth" "ntilde" "ograve" "oacute" "ocirc" "otilde" "ouml" "divide"
203 "oslash" "ugrave" "uacute" "ucirc" "uuml" "yacute" "thorn" "yuml"]
204 "Vector of symbolic character names without `&' and `;'.")
205
2840d653
EZ
206(put 'sgml-table 'char-table-extra-slots 0)
207
208(defvar sgml-char-names-table
209 (let ((table (make-char-table 'sgml-table))
210 (i 32)
211 elt)
212 (while (< i 256)
213 (setq elt (aref sgml-char-names i))
214 (if elt (aset table (make-char 'latin-iso8859-1 i) elt))
215 (setq i (1+ i)))
216 table)
217 "A table for mapping non-ASCII characters into SGML entity names.
218Currently, only Latin-1 characters are supported.")
219
5121371d
DL
220;; nsgmls is a free SGML parser in the SP suite available from
221;; ftp.jclark.com and otherwise packaged for GNU systems.
1caf38eb
RS
222;; Its error messages can be parsed by next-error.
223;; The -s option suppresses output.
224
5121371d 225(defcustom sgml-validate-command "nsgmls -s" ; replaced old `sgmls'
72c0ae01
ER
226 "*The command to validate an SGML document.
227The file name of current buffer file name will be appended to this,
64ae0c23
RS
228separated by a space."
229 :type 'string
d4c89075 230 :version "21.1"
64ae0c23 231 :group 'sgml)
72c0ae01
ER
232
233(defvar sgml-saved-validate-command nil
234 "The command last used to validate in this buffer.")
235
e1940c83
SM
236;; I doubt that null end tags are used much for large elements,
237;; so use a small distance here.
64ae0c23 238(defcustom sgml-slash-distance 1000
f788776c 239 "*If non-nil, is the maximum distance to search for matching `/'."
64ae0c23
RS
240 :type '(choice (const nil) integer)
241 :group 'sgml)
72c0ae01 242
b0045305 243(defconst sgml-namespace-re "[_[:alpha:]][-_.[:alnum:]]*")
5f3d924d
SM
244(defconst sgml-name-re "[_:[:alpha:]][-_.:[:alnum:]]*")
245(defconst sgml-tag-name-re (concat "<\\([!/?]?" sgml-name-re "\\)"))
246(defconst sgml-attrs-re "\\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*")
247(defconst sgml-start-tag-regex (concat "<" sgml-name-re sgml-attrs-re)
1caf38eb 248 "Regular expression that matches a non-empty start tag.
f788776c 249Any terminating `>' or `/' is not matched.")
1caf38eb 250
b390eb09 251(defface sgml-namespace
b0045305 252 '((t (:inherit font-lock-builtin-face)))
dc11bf76
LK
253 "`sgml-mode' face used to highlight the namespace part of identifiers."
254 :group 'sgml)
b390eb09 255(defvar sgml-namespace-face 'sgml-namespace)
1caf38eb 256
c6a63534
RS
257;; internal
258(defconst sgml-font-lock-keywords-1
5f3d924d 259 `((,(concat "<\\([!?]" sgml-name-re "\\)") 1 font-lock-keyword-face)
b0045305
SM
260 ;; We could use the simpler "\\(" sgml-namespace-re ":\\)?" instead,
261 ;; but it would cause a bit more backtracking in the re-matcher.
262 (,(concat "</?\\(" sgml-namespace-re "\\)\\(?::\\(" sgml-name-re "\\)\\)?")
263 (1 (if (match-end 2) sgml-namespace-face font-lock-function-name-face))
264 (2 font-lock-function-name-face nil t))
1c1d2eb6 265 ;; FIXME: this doesn't cover the variables using a default value.
b0045305
SM
266 (,(concat "\\(" sgml-namespace-re "\\)\\(?::\\("
267 sgml-name-re "\\)\\)?=[\"']")
268 (1 (if (match-end 2) sgml-namespace-face font-lock-variable-name-face))
269 (2 font-lock-variable-name-face nil t))
5f3d924d 270 (,(concat "[&%]" sgml-name-re ";?") . font-lock-variable-name-face)))
64367655
SM
271
272(defconst sgml-font-lock-keywords-2
273 (append
274 sgml-font-lock-keywords-1
275 '((eval
276 . (cons (concat "<"
277 (regexp-opt (mapcar 'car sgml-tag-face-alist) t)
278 "\\([ \t][^>]*\\)?>\\([^<]+\\)</\\1>")
279 '(3 (cdr (assoc (downcase (match-string 1))
13b454db 280 sgml-tag-face-alist)) prepend))))))
c6a63534
RS
281
282;; for font-lock, but must be defvar'ed after
283;; sgml-font-lock-keywords-1 and sgml-font-lock-keywords-2 above
284(defvar sgml-font-lock-keywords sgml-font-lock-keywords-1
1caf38eb
RS
285 "*Rules for highlighting SGML code. See also `sgml-tag-face-alist'.")
286
64367655
SM
287(defvar sgml-font-lock-syntactic-keywords
288 ;; Use the `b' style of comments to avoid interference with the -- ... --
289 ;; comments recognized when `sgml-specials' includes ?-.
290 ;; FIXME: beware of <!--> blabla <!--> !!
291 '(("\\(<\\)!--" (1 "< b"))
292 ("--[ \t\n]*\\(>\\)" (1 "> b")))
293 "Syntactic keywords for `sgml-mode'.")
294
1caf38eb 295;; internal
1caf38eb
RS
296(defvar sgml-face-tag-alist ()
297 "Alist of face and tag name for facemenu.")
298
299(defvar sgml-tag-face-alist ()
300 "Tag names and face or list of faces to fontify with when invisible.
301When `font-lock-maximum-decoration' is 1 this is always used for fontifying.
302When more these are fontified together with `sgml-font-lock-keywords'.")
303
1caf38eb
RS
304(defvar sgml-display-text ()
305 "Tag names as lowercase symbols, and display string when invisible.")
306
307;; internal
308(defvar sgml-tags-invisible nil)
309
64ae0c23 310(defcustom sgml-tag-alist
fcc3195e
RS
311 '(("![" ("ignore" t) ("include" t))
312 ("!attlist")
1caf38eb
RS
313 ("!doctype")
314 ("!element")
315 ("!entity"))
316 "*Alist of tag names for completing read and insertion rules.
317This alist is made up as
318
319 ((\"tag\" . TAGRULE)
320 ...)
321
9d4ce428
MW
322TAGRULE is a list of optionally t (no endtag) or `\\n' (separate endtag by
323newlines) or a skeleton with nil, t or `\\n' in place of the interactor
1caf38eb
RS
324followed by an ATTRIBUTERULE (for an always present attribute) or an
325attribute alist.
326
327The attribute alist is made up as
328
329 ((\"attribute\" . ATTRIBUTERULE)
330 ...)
331
9d4ce428 332ATTRIBUTERULE is a list of optionally t (no value when no input) followed by
64ae0c23
RS
333an optional alist of possible values."
334 :type '(repeat (cons (string :tag "Tag Name")
335 (repeat :tag "Tag Rule" sexp)))
336 :group 'sgml)
1caf38eb 337
64ae0c23 338(defcustom sgml-tag-help
1caf38eb
RS
339 '(("!" . "Empty declaration for comment")
340 ("![" . "Embed declarations with parser directive")
341 ("!attlist" . "Tag attributes declaration")
342 ("!doctype" . "Document type (DTD) declaration")
343 ("!element" . "Tag declaration")
344 ("!entity" . "Entity (macro) declaration"))
64ae0c23
RS
345 "*Alist of tag name and short description."
346 :type '(repeat (cons (string :tag "Tag Name")
347 (string :tag "Description")))
348 :group 'sgml)
1caf38eb 349
a3ec4ba0 350(defcustom sgml-xml-mode nil
c77c3a73
SS
351 "*When non-nil, tag insertion functions will be XML-compliant.
352If this variable is customized, the custom value is used always.
353Otherwise, it is set to be buffer-local when the file has
af3abed1 354a DOCTYPE or an XML declaration."
c77c3a73 355 :type 'boolean
bf247b6e 356 :version "22.1"
c77c3a73
SS
357 :group 'sgml)
358
73d25e52
SM
359(defvar sgml-empty-tags nil
360 "List of tags whose !ELEMENT definition says EMPTY.")
361
5f3d924d
SM
362(defvar sgml-unclosed-tags nil
363 "List of tags whose !ELEMENT definition says the end-tag is optional.")
364
c77c3a73
SS
365(defun sgml-xml-guess ()
366 "Guess whether the current buffer is XML."
367 (save-excursion
368 (goto-char (point-min))
a3ec4ba0
SM
369 (when (or (string= "xml" (file-name-extension (or buffer-file-name "")))
370 (looking-at "\\s-*<\\?xml")
371 (when (re-search-forward
372 (eval-when-compile
59444a9c
SM
373 (mapconcat 'identity
374 '("<!DOCTYPE" "\\(\\w+\\)" "\\(\\w+\\)"
a3ec4ba0
SM
375 "\"\\([^\"]+\\)\"" "\"\\([^\"]+\\)\"")
376 "\\s-+"))
377 nil t)
378 (string-match "X\\(HT\\)?ML" (match-string 3))))
379 (set (make-local-variable 'sgml-xml-mode) t))))
c77c3a73 380
b0a377e6
DL
381(defvar v2) ; free for skeleton
382
60128096
SM
383(defun sgml-comment-indent-new-line (&optional soft)
384 (let ((comment-start "-- ")
385 (comment-start-skip "\\(<!\\)?--[ \t]*")
386 (comment-end " --")
387 (comment-style 'plain))
388 (comment-indent-new-line soft)))
389
a3ec4ba0
SM
390(defun sgml-mode-facemenu-add-face-function (face end)
391 (if (setq face (cdr (assq face sgml-face-tag-alist)))
392 (progn
393 (setq face (funcall skeleton-transformation face))
394 (setq facemenu-end-add-face (concat "</" face ">"))
395 (concat "<" face ">"))
396 (error "Face not configured for %s mode" mode-name)))
397
ed8031f2
SM
398(defun sgml-fill-nobreak ()
399 ;; Don't break between a tag name and its first argument.
400 (save-excursion
401 (skip-chars-backward " \t")
402 (and (not (zerop (skip-syntax-backward "w_")))
403 (skip-chars-backward "/?!")
404 (eq (char-before) ?<))))
405
a3ec4ba0
SM
406;;;###autoload
407(define-derived-mode sgml-mode text-mode "SGML"
408 "Major mode for editing SGML documents.
409Makes > match <.
2394187c 410Keys <, &, SPC within <>, \", / and ' can be electric depending on
a3ec4ba0
SM
411`sgml-quick-keys'.
412
413An argument of N to a tag-inserting command means to wrap it around
414the next N words. In Transient Mark mode, when the mark is active,
415N defaults to -1, which means to wrap it around the current region.
416
417If you like upcased tags, put (setq sgml-transformation 'upcase) in
418your `.emacs' file.
419
420Use \\[sgml-validate] to validate your document with an SGML parser.
421
422Do \\[describe-variable] sgml- SPC to see available variables.
423Do \\[describe-key] on the following bindings to discover what they do.
424\\{sgml-mode-map}"
72c0ae01 425 (make-local-variable 'sgml-saved-validate-command)
1caf38eb
RS
426 (make-local-variable 'facemenu-end-add-face)
427 ;;(make-local-variable 'facemenu-remove-face-function)
c77c3a73
SS
428 ;; A start or end tag by itself on a line separates a paragraph.
429 ;; This is desirable because SGML discards a newline that appears
430 ;; immediately after a start tag or immediately before an end tag.
5f3d924d
SM
431 (set (make-local-variable 'paragraph-start) (concat "[ \t]*$\\|\
432\[ \t]*</?\\(" sgml-name-re sgml-attrs-re "\\)?>"))
433 (set (make-local-variable 'paragraph-separate)
434 (concat paragraph-start "$"))
c77c3a73 435 (set (make-local-variable 'adaptive-fill-regexp) "[ \t]*")
ed8031f2 436 (add-hook 'fill-nobreak-predicate 'sgml-fill-nobreak nil t)
9c599518 437 (set (make-local-variable 'indent-line-function) 'sgml-indent-line)
c77c3a73
SS
438 (set (make-local-variable 'comment-start) "<!-- ")
439 (set (make-local-variable 'comment-end) " -->")
440 (set (make-local-variable 'comment-indent-function) 'sgml-comment-indent)
60128096
SM
441 (set (make-local-variable 'comment-line-break-function)
442 'sgml-comment-indent-new-line)
c77c3a73
SS
443 (set (make-local-variable 'skeleton-further-elements)
444 '((completion-ignore-case t)))
445 (set (make-local-variable 'skeleton-end-hook)
446 (lambda ()
447 (or (eolp)
448 (not (or (eq v2 '\n) (eq (car-safe v2) '\n)))
449 (newline-and-indent))))
450 (set (make-local-variable 'font-lock-defaults)
451 '((sgml-font-lock-keywords
452 sgml-font-lock-keywords-1
453 sgml-font-lock-keywords-2)
454 nil t nil nil
455 (font-lock-syntactic-keywords
456 . sgml-font-lock-syntactic-keywords)))
457 (set (make-local-variable 'facemenu-add-face-function)
458 'sgml-mode-facemenu-add-face-function)
a3ec4ba0
SM
459 (sgml-xml-guess)
460 (if sgml-xml-mode
461 (setq mode-name "XML")
462 (set (make-local-variable 'skeleton-transformation) sgml-transformation))
4afa094d
SM
463 ;; This will allow existing comments within declarations to be
464 ;; recognized.
465 (set (make-local-variable 'comment-start-skip) "\\(?:<!\\)?--[ \t]*")
a3ec4ba0 466 (set (make-local-variable 'comment-end-skip) "[ \t]*--\\([ \t\n]*>\\)?")
4456f964
DP
467 ;; This definition has an HTML leaning but probably fits well for other modes.
468 (setq imenu-generic-expression
469 `((nil
470 ,(concat "<!\\(element\\|entity\\)[ \t\n]+%?[ \t\n]*\\("
471 sgml-name-re "\\)")
472 2)
473 ("Id"
474 ,(concat "<[^>]+[ \t\n]+[Ii][Dd]=\\(['\"]"
475 (if sgml-xml-mode "" "?")
476 "\\)\\(" sgml-name-re "\\)\\1")
477 2)
478 ("Name"
479 ,(concat "<[^>]+[ \t\n]+[Nn][Aa][Mm][Ee]=\\(['\"]"
480 (if sgml-xml-mode "" "?")
481 "\\)\\(" sgml-name-re "\\)\\1")
482 2))))
1caf38eb 483
9d118494
CW
484;; Some programs (such as Glade 2) generate XML which has
485;; -*- mode: xml -*-.
7461dcb0 486;;;###autoload
9d118494
CW
487(defalias 'xml-mode 'sgml-mode)
488
72c0ae01 489(defun sgml-comment-indent ()
4afa094d 490 (if (looking-at "--") comment-column 0))
72c0ae01 491
72c0ae01 492(defun sgml-slash (arg)
2394187c
SM
493 "Insert ARG slash characters.
494Behaves electrically if `sgml-quick-keys' is non-nil."
495 (interactive "p")
496 (cond
497 ((not (and (eq (char-before) ?<) (= arg 1)))
498 (sgml-slash-matching arg))
499 ((eq sgml-quick-keys 'indent)
500 (insert-char ?/ 1)
501 (indent-according-to-mode))
502 ((eq sgml-quick-keys 'close)
503 (delete-backward-char 1)
f6ab0573 504 (sgml-close-tag))
2394187c
SM
505 (t
506 (sgml-slash-matching arg))))
507
508(defun sgml-slash-matching (arg)
f788776c
RS
509 "Insert `/' and display any previous matching `/'.
510Two `/'s are treated as matching if the first `/' ends a net-enabling
511start tag, and the second `/' is the corresponding null end tag."
72c0ae01
ER
512 (interactive "p")
513 (insert-char ?/ arg)
514 (if (> arg 0)
515 (let ((oldpos (point))
516 (blinkpos)
517 (level 0))
518 (save-excursion
519 (save-restriction
520 (if sgml-slash-distance
521 (narrow-to-region (max (point-min)
522 (- (point) sgml-slash-distance))
523 oldpos))
524 (if (and (re-search-backward sgml-start-tag-regex (point-min) t)
525 (eq (match-end 0) (1- oldpos)))
526 ()
527 (goto-char (1- oldpos))
528 (while (and (not blinkpos)
529 (search-backward "/" (point-min) t))
530 (let ((tagend (save-excursion
531 (if (re-search-backward sgml-start-tag-regex
532 (point-min) t)
533 (match-end 0)
534 nil))))
535 (if (eq tagend (point))
536 (if (eq level 0)
537 (setq blinkpos (point))
538 (setq level (1- level)))
539 (setq level (1+ level)))))))
5950e029
SS
540 (when blinkpos
541 (goto-char blinkpos)
542 (if (pos-visible-in-window-p)
543 (sit-for 1)
544 (message "Matches %s"
545 (buffer-substring (line-beginning-position)
546 (1+ blinkpos)))))))))
72c0ae01 547
0fda8eff
SM
548;; Why doesn't this use the iso-cvt table or, preferably, generate the
549;; inverse of the extensive table in the SGML Quail input method? -- fx
550;; I guess that's moot since it only works with Latin-1 anyhow.
1caf38eb
RS
551(defun sgml-name-char (&optional char)
552 "Insert a symbolic character name according to `sgml-char-names'.
2840d653
EZ
553Non-ASCII chars may be inserted either with the meta key, as in M-SPC for
554no-break space or M-- for a soft hyphen; or via an input method or
555encoded keyboard operation."
1caf38eb
RS
556 (interactive "*")
557 (insert ?&)
558 (or char
9b0ffdac 559 (setq char (read-quoted-char "Enter char or octal number")))
1caf38eb
RS
560 (delete-backward-char 1)
561 (insert char)
562 (undo-boundary)
4e7a42d2
SM
563 (sgml-namify-char))
564
565(defun sgml-namify-char ()
566 "Change the char before point into its `&name;' equivalent.
567Uses `sgml-char-names'."
568 (interactive)
569 (let* ((char (char-before))
570 (name
571 (cond
572 ((null char) (error "No char before point"))
573 ((< char 256) (or (aref sgml-char-names char) char))
574 ((aref sgml-char-names-table char))
575 ((encode-char char 'ucs)))))
576 (if (not name)
577 (error "Don't know the name of `%c'" char)
578 (delete-backward-char 1)
579 (insert (format (if (numberp name) "&#%d;" "&%s;") name)))))
1caf38eb
RS
580
581(defun sgml-name-self ()
582 "Insert a symbolic character name according to `sgml-char-names'."
583 (interactive "*")
584 (sgml-name-char last-command-char))
585
1caf38eb
RS
586(defun sgml-maybe-name-self ()
587 "Insert a symbolic character name according to `sgml-char-names'."
588 (interactive "*")
589 (if sgml-name-8bit-mode
2840d653
EZ
590 (let ((mc last-command-char))
591 (if (< mc 256)
592 (setq mc (unibyte-char-to-multibyte mc)))
593 (or mc (setq mc last-command-char))
594 (sgml-name-char mc))
1caf38eb
RS
595 (self-insert-command 1)))
596
1caf38eb 597(defun sgml-name-8bit-mode ()
0fda8eff
SM
598 "Toggle whether to insert named entities instead of non-ASCII characters.
599This only works for Latin-1 input."
1caf38eb 600 (interactive)
d10447ba 601 (setq sgml-name-8bit-mode (not sgml-name-8bit-mode))
2840d653 602 (message "sgml name entity mode is now %s"
d10447ba 603 (if sgml-name-8bit-mode "ON" "OFF")))
1caf38eb 604
f788776c
RS
605;; When an element of a skeleton is a string "str", it is passed
606;; through skeleton-transformation and inserted. If "str" is to be
607;; inserted literally, one should obtain it as the return value of a
608;; function, e.g. (identity "str").
1caf38eb 609
4e7a42d2
SM
610(defvar sgml-tag-last nil)
611(defvar sgml-tag-history nil)
1caf38eb 612(define-skeleton sgml-tag
f788776c
RS
613 "Prompt for a tag and insert it, optionally with attributes.
614Completion and configuration are done according to `sgml-tag-alist'.
d10447ba 615If you like tags and attributes in uppercase do \\[set-variable]
f788776c
RS
616skeleton-transformation RET upcase RET, or put this in your `.emacs':
617 (setq sgml-transformation 'upcase)"
51df53f8 618 (funcall (or skeleton-transformation 'identity)
4e7a42d2
SM
619 (setq sgml-tag-last
620 (completing-read
621 (if (> (length sgml-tag-last) 0)
622 (format "Tag (default %s): " sgml-tag-last)
623 "Tag: ")
624 sgml-tag-alist nil nil nil 'sgml-tag-history sgml-tag-last)))
4afa094d 625 ?< str |
d10447ba 626 (("") -1 '(undo-boundary) (identity "&lt;")) | ; see comment above
73d25e52
SM
627 `(("") '(setq v2 (sgml-attributes ,str t)) ?>
628 (cond
629 ((string= "![" ,str)
630 (backward-char)
631 '(("") " [ " _ " ]]"))
a3ec4ba0 632 ((and (eq v2 t) sgml-xml-mode (member ,str sgml-empty-tags))
af3abed1 633 '(("") -1 " />"))
a3ec4ba0 634 ((or (and (eq v2 t) (not sgml-xml-mode)) (string-match "^[/!?]" ,str))
73d25e52
SM
635 nil)
636 ((symbolp v2)
637 ;; Make sure we don't fall into an infinite loop.
638 ;; For xhtml's `tr' tag, we should maybe use \n instead.
639 (if (eq v2 t) (setq v2 nil))
640 ;; We use `identity' to prevent skeleton from passing
641 ;; `str' through skeleton-transformation a second time.
642 '(("") v2 _ v2 "</" (identity ',str) ?>))
643 ((eq (car v2) t)
644 (cons '("") (cdr v2)))
645 (t
646 (append '(("") (car v2))
647 (cdr v2)
648 '(resume: (car v2) _ "</" (identity ',str) ?>))))))
1caf38eb
RS
649
650(autoload 'skeleton-read "skeleton")
651
d10447ba 652(defun sgml-attributes (tag &optional quiet)
f788776c 653 "When at top level of a tag, interactively insert attributes.
d10447ba 654
f788776c
RS
655Completion and configuration of TAG are done according to `sgml-tag-alist'.
656If QUIET, do not print a message when there are no attributes for TAG."
1caf38eb 657 (interactive (list (save-excursion (sgml-beginning-of-tag t))))
d10447ba
RS
658 (or (stringp tag) (error "Wrong context for adding attribute"))
659 (if tag
1caf38eb 660 (let ((completion-ignore-case t)
d10447ba 661 (alist (cdr (assoc (downcase tag) sgml-tag-alist)))
1caf38eb 662 car attribute i)
1caf38eb
RS
663 (if (or (symbolp (car alist))
664 (symbolp (car (car alist))))
665 (setq car (car alist)
666 alist (cdr alist)))
667 (or quiet
668 (message "No attributes configured."))
669 (if (stringp (car alist))
670 (progn
fae1a906 671 (insert (if (eq (preceding-char) ?\s) "" ?\s)
d10447ba 672 (funcall skeleton-transformation (car alist)))
1caf38eb
RS
673 (sgml-value alist))
674 (setq i (length alist))
675 (while (> i 0)
fae1a906 676 (insert ?\s)
1caf38eb
RS
677 (insert (funcall skeleton-transformation
678 (setq attribute
679 (skeleton-read '(completing-read
d10447ba 680 "Attribute: "
1caf38eb
RS
681 alist)))))
682 (if (string= "" attribute)
683 (setq i 0)
aa7a8f0e 684 (sgml-value (assoc (downcase attribute) alist))
1caf38eb 685 (setq i (1- i))))
fae1a906 686 (if (eq (preceding-char) ?\s)
1caf38eb
RS
687 (delete-backward-char 1)))
688 car)))
689
690(defun sgml-auto-attributes (arg)
f788776c
RS
691 "Self insert the character typed; at top level of tag, prompt for attributes.
692With prefix argument, only self insert."
1caf38eb
RS
693 (interactive "*P")
694 (let ((point (point))
695 tag)
696 (if (or arg
1caf38eb
RS
697 (not sgml-tag-alist) ; no message when nothing configured
698 (symbolp (setq tag (save-excursion (sgml-beginning-of-tag t))))
699 (eq (aref tag 0) ?/))
700 (self-insert-command (prefix-numeric-value arg))
701 (sgml-attributes tag)
fae1a906 702 (setq last-command-char ?\s)
1caf38eb
RS
703 (or (> (point) point)
704 (self-insert-command 1)))))
705
1caf38eb 706(defun sgml-tag-help (&optional tag)
f788776c 707 "Display description of tag TAG. If TAG is omitted, use the tag at point."
1caf38eb
RS
708 (interactive)
709 (or tag
710 (save-excursion
711 (if (eq (following-char) ?<)
712 (forward-char))
713 (setq tag (sgml-beginning-of-tag))))
714 (or (stringp tag)
715 (error "No tag selected"))
716 (setq tag (downcase tag))
f68f40e0 717 (message "%s"
aa7a8f0e 718 (or (cdr (assoc (downcase tag) sgml-tag-help))
1caf38eb 719 (and (eq (aref tag 0) ?/)
aa7a8f0e 720 (cdr (assoc (downcase (substring tag 1)) sgml-tag-help)))
1caf38eb
RS
721 "No description available")))
722
1c1d2eb6
SM
723(defun sgml-maybe-end-tag (&optional arg)
724 "Name self unless in position to end a tag or a prefix ARG is given."
725 (interactive "P")
726 (if (or arg (eq (car (sgml-lexical-context)) 'tag))
727 (self-insert-command (prefix-numeric-value arg))
728 (sgml-name-self)))
1caf38eb
RS
729
730(defun sgml-skip-tag-backward (arg)
731 "Skip to beginning of tag or matching opening tag if present.
f788776c 732With prefix argument ARG, repeat this ARG times."
1caf38eb 733 (interactive "p")
4e7a42d2 734 ;; FIXME: use sgml-get-context or something similar.
1caf38eb
RS
735 (while (>= arg 1)
736 (search-backward "<" nil t)
737 (if (looking-at "</\\([^ \n\t>]+\\)")
738 ;; end tag, skip any nested pairs
739 (let ((case-fold-search t)
65b34485
SM
740 (re (concat "</?" (regexp-quote (match-string 1))
741 ;; Ignore empty tags like <foo/>.
742 "\\([^>]*[^/>]\\)?>")))
1caf38eb
RS
743 (while (and (re-search-backward re nil t)
744 (eq (char-after (1+ (point))) ?/))
745 (forward-char 1)
746 (sgml-skip-tag-backward 1))))
747 (setq arg (1- arg))))
748
65b34485 749(defun sgml-skip-tag-forward (arg)
1caf38eb 750 "Skip to end of tag or matching closing tag if present.
f788776c 751With prefix argument ARG, repeat this ARG times.
1caf38eb
RS
752Return t iff after a closing tag."
753 (interactive "p")
4e7a42d2
SM
754 ;; FIXME: Use sgml-get-context or something similar.
755 ;; It currently might jump to an unrelated </P> if the <P>
756 ;; we're skipping has no matching </P>.
65b34485 757 (let ((return t))
4e7a42d2
SM
758 (with-syntax-table sgml-tag-syntax-table
759 (while (>= arg 1)
760 (skip-chars-forward "^<>")
761 (if (eq (following-char) ?>)
762 (up-list -1))
763 (if (looking-at "<\\([^/ \n\t>]+\\)\\([^>]*[^/>]\\)?>")
764 ;; start tag, skip any nested same pairs _and_ closing tag
765 (let ((case-fold-search t)
766 (re (concat "</?" (regexp-quote (match-string 1))
767 ;; Ignore empty tags like <foo/>.
768 "\\([^>]*[^/>]\\)?>"))
769 point close)
770 (forward-list 1)
771 (setq point (point))
772 ;; FIXME: This re-search-forward will mistakenly match
773 ;; tag-like text inside attributes.
774 (while (and (re-search-forward re nil t)
775 (not (setq close
776 (eq (char-after (1+ (match-beginning 0))) ?/)))
777 (goto-char (match-beginning 0))
778 (sgml-skip-tag-forward 1))
779 (setq close nil))
780 (unless close
781 (goto-char point)
782 (setq return nil)))
783 (forward-list 1))
784 (setq arg (1- arg)))
785 return)))
1caf38eb
RS
786
787(defun sgml-delete-tag (arg)
4e7a42d2 788 ;; FIXME: Should be called sgml-kill-tag or should not touch the kill-ring.
1caf38eb 789 "Delete tag on or after cursor, and matching closing or opening tag.
f788776c 790With prefix argument ARG, repeat this ARG times."
1caf38eb
RS
791 (interactive "p")
792 (while (>= arg 1)
793 (save-excursion
794 (let* (close open)
fcc3195e 795 (if (looking-at "[ \t\n]*<")
1caf38eb
RS
796 ;; just before tag
797 (if (eq (char-after (match-end 0)) ?/)
798 ;; closing tag
799 (progn
800 (setq close (point))
801 (goto-char (match-end 0))))
802 ;; on tag?
803 (or (save-excursion (setq close (sgml-beginning-of-tag)
804 close (and (stringp close)
805 (eq (aref close 0) ?/)
806 (point))))
807 ;; not on closing tag
808 (let ((point (point)))
809 (sgml-skip-tag-backward 1)
810 (if (or (not (eq (following-char) ?<))
811 (save-excursion
812 (forward-list 1)
813 (<= (point) point)))
814 (error "Not on or before tag")))))
815 (if close
816 (progn
817 (sgml-skip-tag-backward 1)
818 (setq open (point))
819 (goto-char close)
820 (kill-sexp 1))
821 (setq open (point))
af3abed1
JL
822 (when (and (sgml-skip-tag-forward 1)
823 (not (looking-back "/>")))
4e7a42d2
SM
824 (kill-sexp -1)))
825 ;; Delete any resulting empty line. If we didn't kill-sexp,
826 ;; this *should* do nothing, because we're right after the tag.
827 (if (progn (forward-line 0) (looking-at "\\(?:[ \t]*$\\)\n?"))
828 (delete-region (match-beginning 0) (match-end 0)))
1caf38eb 829 (goto-char open)
4e7a42d2
SM
830 (kill-sexp 1)
831 (if (progn (forward-line 0) (looking-at "\\(?:[ \t]*$\\)\n?"))
832 (delete-region (match-beginning 0) (match-end 0)))))
1caf38eb 833 (setq arg (1- arg))))
9d4ce428 834
a391b179
RS
835\f
836;; Put read-only last to enable setting this even when read-only enabled.
837(or (get 'sgml-tag 'invisible)
838 (setplist 'sgml-tag
839 (append '(invisible t
a391b179
RS
840 point-entered sgml-point-entered
841 rear-nonsticky t
842 read-only t)
843 (symbol-plist 'sgml-tag))))
1caf38eb
RS
844
845(defun sgml-tags-invisible (arg)
846 "Toggle visibility of existing tags."
847 (interactive "P")
848 (let ((modified (buffer-modified-p))
849 (inhibit-read-only t)
e1940c83
SM
850 (inhibit-modification-hooks t)
851 ;; Avoid spurious the `file-locked' checks.
852 (buffer-file-name nil)
a391b179
RS
853 ;; This is needed in case font lock gets called,
854 ;; since it moves point and might call sgml-point-entered.
64367655 855 ;; How could it get called? -stef
a391b179 856 (inhibit-point-motion-hooks t)
64367655 857 string)
e1940c83
SM
858 (unwind-protect
859 (save-excursion
860 (goto-char (point-min))
73d25e52
SM
861 (if (set (make-local-variable 'sgml-tags-invisible)
862 (if arg
863 (>= (prefix-numeric-value arg) 0)
864 (not sgml-tags-invisible)))
1c1d2eb6 865 (while (re-search-forward sgml-tag-name-re nil t)
64367655
SM
866 (setq string
867 (cdr (assq (intern-soft (downcase (match-string 1)))
868 sgml-display-text)))
e1940c83 869 (goto-char (match-beginning 0))
64367655 870 (and (stringp string)
e1940c83 871 (not (overlays-at (point)))
73d25e52
SM
872 (let ((ol (make-overlay (point) (match-beginning 1))))
873 (overlay-put ol 'before-string string)
874 (overlay-put ol 'sgml-tag t)))
e1940c83
SM
875 (put-text-property (point)
876 (progn (forward-list) (point))
877 'category 'sgml-tag))
64367655 878 (let ((pos (point-min)))
e1940c83 879 (while (< (setq pos (next-overlay-change pos)) (point-max))
73d25e52 880 (dolist (ol (overlays-at pos))
b2e8c203 881 (if (overlay-get ol 'sgml-tag)
73d25e52 882 (delete-overlay ol)))))
64367655 883 (remove-text-properties (point-min) (point-max) '(category nil))))
e1940c83 884 (restore-buffer-modified-p modified))
1caf38eb
RS
885 (run-hooks 'sgml-tags-invisible-hook)
886 (message "")))
887
888(defun sgml-point-entered (x y)
889 ;; Show preceding or following hidden tag, depending of cursor direction.
890 (let ((inhibit-point-motion-hooks t))
891 (save-excursion
892 (message "Invisible tag: %s"
e1940c83
SM
893 ;; Strip properties, otherwise, the text is invisible.
894 (buffer-substring-no-properties
1caf38eb
RS
895 (point)
896 (if (or (and (> x y)
897 (not (eq (following-char) ?<)))
898 (and (< x y)
899 (eq (preceding-char) ?>)))
900 (backward-list)
901 (forward-list)))))))
9d4ce428 902
a391b179 903\f
27024d2f 904(autoload 'compilation-start "compile")
1caf38eb 905
72c0ae01
ER
906(defun sgml-validate (command)
907 "Validate an SGML document.
908Runs COMMAND, a shell command, in a separate process asynchronously
f788776c 909with output going to the buffer `*compilation*'.
72c0ae01
ER
910You can then use the command \\[next-error] to find the next error message
911and move to the line in the SGML document that caused it."
912 (interactive
913 (list (read-string "Validate command: "
914 (or sgml-saved-validate-command
915 (concat sgml-validate-command
916 " "
917 (let ((name (buffer-file-name)))
918 (and name
919 (file-name-nondirectory name))))))))
920 (setq sgml-saved-validate-command command)
b7cd1746 921 (save-some-buffers (not compilation-ask-about-save) nil)
27024d2f 922 (compilation-start command))
72c0ae01 923
662deeab
MW
924(defsubst sgml-at-indentation-p ()
925 "Return true if point is at the first non-whitespace character on the line."
926 (save-excursion
927 (skip-chars-backward " \t")
928 (bolp)))
929
1c1d2eb6
SM
930(defun sgml-lexical-context (&optional limit)
931 "Return the lexical context at point as (TYPE . START).
932START is the location of the start of the lexical element.
2cfd19d4 933TYPE is one of `string', `comment', `tag', `cdata', or `text'.
1c1d2eb6 934
41bfcbee
MW
935Optional argument LIMIT is the position to start parsing from.
936If nil, start from a preceding tag at indentation."
1c1d2eb6
SM
937 (save-excursion
938 (let ((pos (point))
14614b6d 939 text-start state)
41bfcbee
MW
940 (if limit
941 (goto-char limit)
942 ;; Skip tags backwards until we find one at indentation
943 (while (and (ignore-errors (sgml-parse-tag-backward))
944 (not (sgml-at-indentation-p)))))
5f3d924d
SM
945 (with-syntax-table sgml-tag-syntax-table
946 (while (< (point) pos)
947 ;; When entering this loop we're inside text.
80fc318e 948 (setq text-start (point))
5f3d924d 949 (skip-chars-forward "^<" pos)
14614b6d
MW
950 (setq state
951 (cond
60128096 952 ((= (point) pos)
14614b6d
MW
953 ;; We got to the end without seeing a tag.
954 nil)
955 ((looking-at "<!\\[[A-Z]+\\[")
956 ;; We've found a CDATA section or similar.
957 (let ((cdata-start (point)))
958 (unless (search-forward "]]>" pos 'move)
959 (list 0 nil nil 'cdata nil nil nil nil cdata-start))))
960 (t
2871b07a 961 ;; We've reached a tag. Parse it.
14614b6d
MW
962 ;; FIXME: Handle net-enabling start-tags
963 (parse-partial-sexp (point) pos 0))))))
964 (cond
965 ((eq (nth 3 state) 'cdata) (cons 'cdata (nth 8 state)))
966 ((nth 3 state) (cons 'string (nth 8 state)))
967 ((nth 4 state) (cons 'comment (nth 8 state)))
968 ((and state (> (nth 0 state) 0)) (cons 'tag (nth 1 state)))
969 (t (cons 'text text-start))))))
1c1d2eb6 970
1caf38eb
RS
971(defun sgml-beginning-of-tag (&optional top-level)
972 "Skip to beginning of tag and return its name.
1c1d2eb6
SM
973If this can't be done, return nil."
974 (let ((context (sgml-lexical-context)))
975 (if (eq (car context) 'tag)
976 (progn
977 (goto-char (cdr context))
978 (when (looking-at sgml-tag-name-re)
979 (match-string-no-properties 1)))
980 (if top-level nil
3fb819e5 981 (when (not (eq (car context) 'text))
1c1d2eb6
SM
982 (goto-char (cdr context))
983 (sgml-beginning-of-tag t))))))
1caf38eb
RS
984
985(defun sgml-value (alist)
347ea557 986 "Interactively insert value taken from attribute-rule ALIST.
5950e029 987See `sgml-tag-alist' for info about attribute rules."
1caf38eb
RS
988 (setq alist (cdr alist))
989 (if (stringp (car alist))
990 (insert "=\"" (car alist) ?\")
a3ec4ba0 991 (if (and (eq (car alist) t) (not sgml-xml-mode))
5950e029 992 (when (cdr alist)
73d25e52
SM
993 (insert "=\"")
994 (setq alist (skeleton-read '(completing-read "Value: " (cdr alist))))
995 (if (string< "" alist)
996 (insert alist ?\")
997 (delete-backward-char 2)))
1caf38eb 998 (insert "=\"")
5950e029
SS
999 (when alist
1000 (insert (skeleton-read '(completing-read "Value: " alist))))
1caf38eb 1001 (insert ?\"))))
64367655
SM
1002
1003(defun sgml-quote (start end &optional unquotep)
7492ed8e
SM
1004 "Quote SGML text in region START ... END.
1005Only &, < and > are quoted, the rest is left untouched.
1006With prefix argument UNQUOTEP, unquote the region."
1007 (interactive "r\nP")
1008 (save-restriction
1009 (narrow-to-region start end)
1010 (goto-char (point-min))
1011 (if unquotep
1012 ;; FIXME: We should unquote other named character references as well.
1013 (while (re-search-forward
1014 "\\(&\\(amp\\|\\(l\\|\\(g\\)\\)t\\)\\)[][<>&;\n\t \"%!'(),/=?]"
1015 nil t)
1016 (replace-match (if (match-end 4) ">" (if (match-end 3) "<" "&")) t t
1017 nil (if (eq (char-before (match-end 0)) ?\;) 0 1)))
1018 (while (re-search-forward "[&<>]" nil t)
1019 (replace-match (cdr (assq (char-before) '((?& . "&amp;")
1020 (?< . "&lt;")
1021 (?> . "&gt;"))))
1022 t t)))))
1023
1024(defun sgml-pretty-print (beg end)
1025 "Simple-minded pretty printer for SGML.
1026Re-indents the code and inserts newlines between BEG and END.
1027You might want to turn on `auto-fill-mode' to get better results."
1028 ;; TODO:
1029 ;; - insert newline between some start-tag and text.
1030 ;; - don't insert newline in front of some end-tags.
1031 (interactive "r")
1032 (save-excursion
1033 (if (< beg end)
1034 (goto-char beg)
1035 (goto-char end)
1036 (setq end beg)
1037 (setq beg (point)))
1038 ;; Don't use narrowing because it screws up auto-indent.
1039 (setq end (copy-marker end t))
1040 (with-syntax-table sgml-tag-syntax-table
1041 (while (re-search-forward "<" end t)
1042 (goto-char (match-beginning 0))
1043 (unless (or ;;(looking-at "</")
1044 (progn (skip-chars-backward " \t") (bolp)))
1045 (reindent-then-newline-and-indent))
1046 (forward-sexp 1)))
1047 ;; (indent-region beg end)
1048 ))
e1940c83 1049
2394187c
SM
1050\f
1051;; Parsing
1052
1053(defstruct (sgml-tag
1054 (:constructor sgml-make-tag (type start end name)))
1055 type start end name)
1056
1057(defsubst sgml-parse-tag-name ()
1058 "Skip past a tag-name, and return the name."
1059 (buffer-substring-no-properties
1060 (point) (progn (skip-syntax-forward "w_") (point))))
1061
41bfcbee
MW
1062(defsubst sgml-looking-back-at (str)
1063 "Return t if the test before point matches STR."
1064 (let ((start (- (point) (length str))))
80fc318e 1065 (and (>= start (point-min))
41bfcbee 1066 (equal str (buffer-substring-no-properties start (point))))))
2394187c 1067
e9146d5a
SM
1068(defun sgml-tag-text-p (start end)
1069 "Return non-nil if text between START and END is a tag.
1070Checks among other things that the tag does not contain spurious
1071unquoted < or > chars inside, which would indicate that it
1072really isn't a tag after all."
1073 (save-excursion
1074 (with-syntax-table sgml-tag-syntax-table
1075 (let ((pps (parse-partial-sexp start end 2)))
1076 (and (= (nth 0 pps) 0))))))
1077
4e7a42d2 1078(defun sgml-parse-tag-backward (&optional limit)
2394187c
SM
1079 "Parse an SGML tag backward, and return information about the tag.
1080Assume that parsing starts from within a textual context.
1081Leave point at the beginning of the tag."
e9146d5a
SM
1082 (catch 'found
1083 (let (tag-type tag-start tag-end name)
1084 (or (re-search-backward "[<>]" limit 'move)
1085 (error "No tag found"))
1086 (when (eq (char-after) ?<)
1087 ;; Oops!! Looks like we were not in a textual context after all!.
1088 ;; Let's try to recover.
1089 (with-syntax-table sgml-tag-syntax-table
1090 (let ((pos (point)))
1091 (condition-case nil
1092 (forward-sexp)
1093 (scan-error
1094 ;; This < seems to be just a spurious one, let's ignore it.
1095 (goto-char pos)
1096 (throw 'found (sgml-parse-tag-backward limit))))
1097 ;; Check it is really a tag, without any extra < or > inside.
1098 (unless (sgml-tag-text-p pos (point))
1099 (goto-char pos)
1100 (throw 'found (sgml-parse-tag-backward limit)))
1101 (forward-char -1))))
1102 (setq tag-end (1+ (point)))
1103 (cond
1104 ((sgml-looking-back-at "--") ; comment
1105 (setq tag-type 'comment
1106 tag-start (search-backward "<!--" nil t)))
1107 ((sgml-looking-back-at "]]") ; cdata
1108 (setq tag-type 'cdata
1109 tag-start (re-search-backward "<!\\[[A-Z]+\\[" nil t)))
1110 (t
1111 (setq tag-start
1112 (with-syntax-table sgml-tag-syntax-table
1113 (goto-char tag-end)
1114 (condition-case nil
1115 (backward-sexp)
1116 (scan-error
1117 ;; This > isn't really the end of a tag. Skip it.
1118 (goto-char (1- tag-end))
1119 (throw 'found (sgml-parse-tag-backward limit))))
1120 (point)))
1121 (goto-char (1+ tag-start))
1122 (case (char-after)
1123 (?! ; declaration
1124 (setq tag-type 'decl))
1125 (?? ; processing-instruction
1126 (setq tag-type 'pi))
1127 (?/ ; close-tag
1128 (forward-char 1)
1129 (setq tag-type 'close
1130 name (sgml-parse-tag-name)))
1131 (?% ; JSP tags
1132 (setq tag-type 'jsp))
1133 (t ; open or empty tag
1134 (setq tag-type 'open
1135 name (sgml-parse-tag-name))
1136 (if (or (eq ?/ (char-before (- tag-end 1)))
1137 (sgml-empty-tag-p name))
1138 (setq tag-type 'empty))))))
1139 (goto-char tag-start)
1140 (sgml-make-tag tag-type tag-start tag-end name))))
2394187c 1141
59444a9c 1142(defun sgml-get-context (&optional until)
2394187c 1143 "Determine the context of the current position.
59444a9c
SM
1144By default, parse until we find a start-tag as the first thing on a line.
1145If UNTIL is `empty', return even if the context is empty (i.e.
2394187c 1146we just skipped over some element and got to a beginning of line).
2394187c
SM
1147
1148The context is a list of tag-info structures. The last one is the tag
59444a9c
SM
1149immediately enclosing the current position.
1150
1151Point is assumed to be outside of any tag. If we discover that it's
1152not the case, the first tag returned is the one inside which we are."
2394187c 1153 (let ((here (point))
ed8031f2 1154 (stack nil)
2394187c
SM
1155 (ignore nil)
1156 (context nil)
1157 tag-info)
1158 ;; CONTEXT keeps track of the tag-stack
ed8031f2
SM
1159 ;; STACK keeps track of the end tags we've seen (and thus the start-tags
1160 ;; we'll have to ignore) when skipping over matching open..close pairs.
1161 ;; IGNORE is a list of tags that can be ignored because they have been
1162 ;; closed implicitly.
2394187c
SM
1163 (skip-chars-backward " \t\n") ; Make sure we're not at indentation.
1164 (while
59444a9c 1165 (and (not (eq until 'now))
ed8031f2 1166 (or stack
59444a9c 1167 (not (if until (eq until 'empty) context))
2394187c
SM
1168 (not (sgml-at-indentation-p))
1169 (and context
1170 (/= (point) (sgml-tag-start (car context)))
59444a9c 1171 (sgml-unclosed-tag-p (sgml-tag-name (car context)))))
2394187c 1172 (setq tag-info (ignore-errors (sgml-parse-tag-backward))))
a9d4efa2 1173
2394187c
SM
1174 ;; This tag may enclose things we thought were tags. If so,
1175 ;; discard them.
1176 (while (and context
1177 (> (sgml-tag-end tag-info)
1178 (sgml-tag-end (car context))))
1179 (setq context (cdr context)))
a9d4efa2 1180
2394187c 1181 (cond
59444a9c
SM
1182 ((> (sgml-tag-end tag-info) here)
1183 ;; Oops!! Looks like we were not outside of any tag, after all.
1184 (push tag-info context)
1185 (setq until 'now))
2394187c 1186
2394187c
SM
1187 ;; start-tag
1188 ((eq (sgml-tag-type tag-info) 'open)
1189 (cond
ed8031f2
SM
1190 ((null stack)
1191 (if (member-ignore-case (sgml-tag-name tag-info) ignore)
2394187c
SM
1192 ;; There was an implicit end-tag.
1193 nil
ed8031f2
SM
1194 (push tag-info context)
1195 ;; We're changing context so the tags implicitly closed inside
1196 ;; the previous context aren't implicitly closed here any more.
1197 ;; [ Well, actually it depends, but we don't have the info about
1198 ;; when it doesn't and when it does. --Stef ]
1199 (setq ignore nil)))
2394187c 1200 ((eq t (compare-strings (sgml-tag-name tag-info) nil nil
ed8031f2
SM
1201 (car stack) nil nil t))
1202 (setq stack (cdr stack)))
2394187c
SM
1203 (t
1204 ;; The open and close tags don't match.
1205 (if (not sgml-xml-mode)
2394187c 1206 (unless (sgml-unclosed-tag-p (sgml-tag-name tag-info))
7492ed8e 1207 (message "Unclosed tag <%s>" (sgml-tag-name tag-info))
ed8031f2 1208 (let ((tmp stack))
7492ed8e
SM
1209 ;; We could just assume that the tag is simply not closed
1210 ;; but it's a bad assumption when tags *are* closed but
1211 ;; not properly nested.
1212 (while (and (cdr tmp)
1213 (not (eq t (compare-strings
1214 (sgml-tag-name tag-info) nil nil
1215 (cadr tmp) nil nil t))))
1216 (setq tmp (cdr tmp)))
1217 (if (cdr tmp) (setcdr tmp (cddr tmp)))))
2394187c 1218 (message "Unmatched tags <%s> and </%s>"
ed8031f2 1219 (sgml-tag-name tag-info) (pop stack)))))
bf247b6e 1220
ed8031f2
SM
1221 (if (and (null stack) (sgml-unclosed-tag-p (sgml-tag-name tag-info)))
1222 ;; This is a top-level open of an implicitly closed tag, so any
1223 ;; occurrence of such an open tag at the same level can be ignored
1224 ;; because it's been implicitly closed.
1225 (push (sgml-tag-name tag-info) ignore)))
2394187c
SM
1226
1227 ;; end-tag
1228 ((eq (sgml-tag-type tag-info) 'close)
1229 (if (sgml-empty-tag-p (sgml-tag-name tag-info))
1230 (message "Spurious </%s>: empty tag" (sgml-tag-name tag-info))
ed8031f2 1231 (push (sgml-tag-name tag-info) stack)))
2394187c
SM
1232 ))
1233
1234 ;; return context
1235 context))
1236
1237(defun sgml-show-context (&optional full)
1238 "Display the current context.
1239If FULL is non-nil, parse back to the beginning of the buffer."
1240 (interactive "P")
1241 (with-output-to-temp-buffer "*XML Context*"
7492ed8e
SM
1242 (save-excursion
1243 (let ((context (sgml-get-context)))
1244 (when full
1245 (let ((more nil))
1246 (while (setq more (sgml-get-context))
1247 (setq context (nconc more context)))))
1248 (pp context)))))
2394187c
SM
1249
1250\f
1251;; Editing shortcuts
1252
f6ab0573 1253(defun sgml-close-tag ()
4e7a42d2
SM
1254 "Close current element.
1255Depending on context, inserts a matching close-tag, or closes
1256the current start-tag or the current comment or the current cdata, ..."
2394187c 1257 (interactive)
f6ab0573
MW
1258 (case (car (sgml-lexical-context))
1259 (comment (insert " -->"))
1260 (cdata (insert "]]>"))
1261 (pi (insert " ?>"))
1262 (jsp (insert " %>"))
1263 (tag (insert " />"))
1264 (text
1265 (let ((context (save-excursion (sgml-get-context))))
1266 (if context
2871b07a 1267 (progn
f6ab0573
MW
1268 (insert "</" (sgml-tag-name (car (last context))) ">")
1269 (indent-according-to-mode)))))
1270 (otherwise
1271 (error "Nothing to close"))))
2394187c 1272
347ea557
MW
1273(defun sgml-empty-tag-p (tag-name)
1274 "Return non-nil if TAG-NAME is an implicitly empty tag."
1275 (and (not sgml-xml-mode)
1276 (member-ignore-case tag-name sgml-empty-tags)))
1277
1278(defun sgml-unclosed-tag-p (tag-name)
1279 "Return non-nil if TAG-NAME is a tag for which an end-tag is optional."
1280 (and (not sgml-xml-mode)
1281 (member-ignore-case tag-name sgml-unclosed-tags)))
1282
59444a9c
SM
1283(defun sgml-calculate-indent (&optional lcon)
1284 "Calculate the column to which this line should be indented.
1285LCON is the lexical context, if any."
1286 (unless lcon (setq lcon (sgml-lexical-context)))
1287
1288 ;; Indent comment-start markers inside <!-- just like comment-end markers.
1289 (if (and (eq (car lcon) 'tag)
1290 (looking-at "--")
1291 (save-excursion (goto-char (cdr lcon)) (looking-at "<!--")))
1292 (setq lcon (cons 'comment (+ (cdr lcon) 2))))
1293
1294 (case (car lcon)
1295
1296 (string
1297 ;; Go back to previous non-empty line.
1298 (while (and (> (point) (cdr lcon))
1299 (zerop (forward-line -1))
1300 (looking-at "[ \t]*$")))
1301 (if (> (point) (cdr lcon))
1302 ;; Previous line is inside the string.
1303 (current-indentation)
1304 (goto-char (cdr lcon))
1305 (1+ (current-column))))
1306
1307 (comment
1308 (let ((mark (looking-at "--")))
1c1d2eb6
SM
1309 ;; Go back to previous non-empty line.
1310 (while (and (> (point) (cdr lcon))
1311 (zerop (forward-line -1))
59444a9c
SM
1312 (or (looking-at "[ \t]*$")
1313 (if mark (not (looking-at "[ \t]*--"))))))
1c1d2eb6 1314 (if (> (point) (cdr lcon))
59444a9c
SM
1315 ;; Previous line is inside the comment.
1316 (skip-chars-forward " \t")
1c1d2eb6 1317 (goto-char (cdr lcon))
59444a9c
SM
1318 ;; Skip `<!' to get to the `--' with which we want to align.
1319 (search-forward "--")
1320 (goto-char (match-beginning 0)))
1321 (when (and (not mark) (looking-at "--"))
1322 (forward-char 2) (skip-chars-forward " \t"))
1323 (current-column)))
1324
1325 ;; We don't know how to indent it. Let's be honest about it.
1326 (cdata nil)
1327
1328 (tag
1329 (goto-char (1+ (cdr lcon)))
1330 (skip-chars-forward "^ \t\n") ;Skip tag name.
1331 (skip-chars-forward " \t")
1332 (if (not (eolp))
1333 (current-column)
1334 ;; This is the first attribute: indent.
1c1d2eb6 1335 (goto-char (1+ (cdr lcon)))
59444a9c
SM
1336 (+ (current-column) sgml-basic-offset)))
1337
1338 (text
1339 (while (looking-at "</")
1340 (forward-sexp 1)
1341 (skip-chars-forward " \t"))
1342 (let* ((here (point))
1343 (unclosed (and ;; (not sgml-xml-mode)
1344 (looking-at sgml-tag-name-re)
1345 (member-ignore-case (match-string 1)
1346 sgml-unclosed-tags)
1347 (match-string 1)))
1348 (context
1349 ;; If possible, align on the previous non-empty text line.
1350 ;; Otherwise, do a more serious parsing to find the
1351 ;; tag(s) relative to which we should be indenting.
1352 (if (and (not unclosed) (skip-chars-backward " \t")
1353 (< (skip-chars-backward " \t\n") 0)
1354 (back-to-indentation)
1355 (> (point) (cdr lcon)))
1356 nil
1357 (goto-char here)
1358 (nreverse (sgml-get-context (if unclosed nil 'empty)))))
1359 (there (point)))
1360 ;; Ignore previous unclosed start-tag in context.
1361 (while (and context unclosed
1362 (eq t (compare-strings
1363 (sgml-tag-name (car context)) nil nil
1364 unclosed nil nil t)))
1365 (setq context (cdr context)))
1366 ;; Indent to reflect nesting.
1367 (cond
1368 ;; If we were not in a text context after all, let's try again.
1369 ((and context (> (sgml-tag-end (car context)) here))
1370 (goto-char here)
1371 (sgml-calculate-indent
1372 (cons (if (memq (sgml-tag-type (car context)) '(comment cdata))
1373 (sgml-tag-type (car context)) 'tag)
1374 (sgml-tag-start (car context)))))
1375 ;; Align on the first element after the nearest open-tag, if any.
1376 ((and context
1377 (goto-char (sgml-tag-end (car context)))
1378 (skip-chars-forward " \t\n")
1379 (< (point) here) (sgml-at-indentation-p))
1380 (current-column))
1381 (t
1382 (goto-char there)
1383 (+ (current-column)
1384 (* sgml-basic-offset (length context)))))))
1385
1386 (otherwise
98d90904 1387 (error "Unrecognized context %s" (car lcon)))
59444a9c
SM
1388
1389 ))
1c1d2eb6
SM
1390
1391(defun sgml-indent-line ()
1392 "Indent the current line as SGML."
1393 (interactive)
1394 (let* ((savep (point))
1395 (indent-col
1396 (save-excursion
5f3d924d 1397 (back-to-indentation)
1c1d2eb6 1398 (if (>= (point) savep) (setq savep nil))
1c1d2eb6 1399 (sgml-calculate-indent))))
59444a9c
SM
1400 (if (null indent-col)
1401 'noindent
1402 (if savep
1403 (save-excursion (indent-line-to indent-col))
1404 (indent-line-to indent-col)))))
1c1d2eb6 1405
2871b07a
MW
1406(defun sgml-guess-indent ()
1407 "Guess an appropriate value for `sgml-basic-offset'.
1408Base the guessed identation level on the first indented tag in the buffer.
1409Add this to `sgml-mode-hook' for convenience."
1410 (interactive)
1411 (save-excursion
1412 (goto-char (point-min))
232dbe4f 1413 (if (re-search-forward "^\\([ \t]+\\)<" 500 'noerror)
2871b07a
MW
1414 (progn
1415 (set (make-local-variable 'sgml-basic-offset)
1c8438ab 1416 (1- (current-column)))
2871b07a
MW
1417 (message "Guessed sgml-basic-offset = %d"
1418 sgml-basic-offset)
1419 ))))
1420
5f3d924d
SM
1421(defun sgml-parse-dtd ()
1422 "Simplistic parse of the current buffer as a DTD.
1423Currently just returns (EMPTY-TAGS UNCLOSED-TAGS)."
1424 (goto-char (point-min))
1425 (let ((empty nil)
1426 (unclosed nil))
1427 (while (re-search-forward "<!ELEMENT[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+[-O][ \t\n]+\\([-O]\\)[ \t\n]+\\([^ \t\n]+\\)" nil t)
1428 (cond
1429 ((string= (match-string 3) "EMPTY")
1430 (push (match-string-no-properties 1) empty))
1431 ((string= (match-string 2) "O")
1432 (push (match-string-no-properties 1) unclosed))))
1433 (setq empty (sort (mapcar 'downcase empty) 'string<))
1434 (setq unclosed (sort (mapcar 'downcase unclosed) 'string<))
1435 (list empty unclosed)))
1436
e1940c83
SM
1437;;; HTML mode
1438
d4c89075
DL
1439(defcustom html-mode-hook nil
1440 "Hook run by command `html-mode'.
1441`text-mode-hook' and `sgml-mode-hook' are run first."
1442 :group 'sgml
1443 :type 'hook
1444 :options '(html-autoview-mode))
1445
fcc3195e 1446(defvar html-quick-keys sgml-quick-keys
b1e7bb48 1447 "Use C-c X combinations for quick insertion of frequent tags when non-nil.
fcc3195e 1448This defaults to `sgml-quick-keys'.
1caf38eb
RS
1449This takes effect when first loading the library.")
1450
1451(defvar html-mode-map
5f5c9e79 1452 (let ((map (make-sparse-keymap))
1caf38eb 1453 (menu-map (make-sparse-keymap "HTML")))
5f5c9e79 1454 (set-keymap-parent map sgml-mode-map)
7e49eef2
RS
1455 (define-key map "\C-c6" 'html-headline-6)
1456 (define-key map "\C-c5" 'html-headline-5)
1457 (define-key map "\C-c4" 'html-headline-4)
1458 (define-key map "\C-c3" 'html-headline-3)
1459 (define-key map "\C-c2" 'html-headline-2)
1460 (define-key map "\C-c1" 'html-headline-1)
fcc3195e
RS
1461 (define-key map "\C-c\r" 'html-paragraph)
1462 (define-key map "\C-c\n" 'html-line)
1463 (define-key map "\C-c\C-c-" 'html-horizontal-rule)
7e49eef2
RS
1464 (define-key map "\C-c\C-co" 'html-ordered-list)
1465 (define-key map "\C-c\C-cu" 'html-unordered-list)
fcc3195e
RS
1466 (define-key map "\C-c\C-cr" 'html-radio-buttons)
1467 (define-key map "\C-c\C-cc" 'html-checkboxes)
1468 (define-key map "\C-c\C-cl" 'html-list-item)
1469 (define-key map "\C-c\C-ch" 'html-href-anchor)
1470 (define-key map "\C-c\C-cn" 'html-name-anchor)
1471 (define-key map "\C-c\C-ci" 'html-image)
5950e029
SS
1472 (when html-quick-keys
1473 (define-key map "\C-c-" 'html-horizontal-rule)
1474 (define-key map "\C-co" 'html-ordered-list)
1475 (define-key map "\C-cu" 'html-unordered-list)
1476 (define-key map "\C-cr" 'html-radio-buttons)
1477 (define-key map "\C-cc" 'html-checkboxes)
1478 (define-key map "\C-cl" 'html-list-item)
1479 (define-key map "\C-ch" 'html-href-anchor)
1480 (define-key map "\C-cn" 'html-name-anchor)
1481 (define-key map "\C-ci" 'html-image))
1caf38eb
RS
1482 (define-key map "\C-c\C-s" 'html-autoview-mode)
1483 (define-key map "\C-c\C-v" 'browse-url-of-buffer)
1484 (define-key map [menu-bar html] (cons "HTML" menu-map))
1485 (define-key menu-map [html-autoview-mode]
1486 '("Toggle Autoviewing" . html-autoview-mode))
1487 (define-key menu-map [browse-url-of-buffer]
1488 '("View Buffer Contents" . browse-url-of-buffer))
1489 (define-key menu-map [nil] '("--"))
7e49eef2
RS
1490 ;;(define-key menu-map "6" '("Heading 6" . html-headline-6))
1491 ;;(define-key menu-map "5" '("Heading 5" . html-headline-5))
1492 ;;(define-key menu-map "4" '("Heading 4" . html-headline-4))
1493 (define-key menu-map "3" '("Heading 3" . html-headline-3))
1494 (define-key menu-map "2" '("Heading 2" . html-headline-2))
1495 (define-key menu-map "1" '("Heading 1" . html-headline-1))
1caf38eb 1496 (define-key menu-map "l" '("Radio Buttons" . html-radio-buttons))
fcc3195e 1497 (define-key menu-map "c" '("Checkboxes" . html-checkboxes))
1caf38eb 1498 (define-key menu-map "l" '("List Item" . html-list-item))
7e49eef2
RS
1499 (define-key menu-map "u" '("Unordered List" . html-unordered-list))
1500 (define-key menu-map "o" '("Ordered List" . html-ordered-list))
fcc3195e 1501 (define-key menu-map "-" '("Horizontal Rule" . html-horizontal-rule))
1caf38eb
RS
1502 (define-key menu-map "\n" '("Line Break" . html-line))
1503 (define-key menu-map "\r" '("Paragraph" . html-paragraph))
1504 (define-key menu-map "i" '("Image" . html-image))
1505 (define-key menu-map "h" '("Href Anchor" . html-href-anchor))
1506 (define-key menu-map "n" '("Name Anchor" . html-name-anchor))
1507 map)
1508 "Keymap for commands for use in HTML mode.")
1509
1caf38eb
RS
1510(defvar html-face-tag-alist
1511 '((bold . "b")
1512 (italic . "i")
1513 (underline . "u")
1514 (modeline . "rev"))
1515 "Value of `sgml-face-tag-alist' for HTML mode.")
1516
1517(defvar html-tag-face-alist
1518 '(("b" . bold)
1519 ("big" . bold)
1520 ("blink" . highlight)
1521 ("cite" . italic)
1522 ("em" . italic)
1523 ("h1" bold underline)
1524 ("h2" bold-italic underline)
1525 ("h3" italic underline)
1526 ("h4" . underline)
1527 ("h5" . underline)
1528 ("h6" . underline)
1529 ("i" . italic)
1530 ("rev" . modeline)
1531 ("s" . underline)
1532 ("small" . default)
1533 ("strong" . bold)
1534 ("title" bold underline)
1535 ("tt" . default)
1536 ("u" . underline)
1537 ("var" . italic))
1538 "Value of `sgml-tag-face-alist' for HTML mode.")
1539
1caf38eb
RS
1540(defvar html-display-text
1541 '((img . "[/]")
1542 (hr . "----------")
1543 (li . "o "))
1544 "Value of `sgml-display-text' for HTML mode.")
b4f05c38 1545
9d4ce428 1546\f
3bf0b727 1547;; should code exactly HTML 3 here when that is finished
1caf38eb 1548(defvar html-tag-alist
d10447ba 1549 (let* ((1-7 '(("1") ("2") ("3") ("4") ("5") ("6") ("7")))
e1940c83 1550 (1-9 `(,@1-7 ("8") ("9")))
1caf38eb
RS
1551 (align '(("align" ("left") ("center") ("right"))))
1552 (valign '(("top") ("middle") ("bottom") ("baseline")))
1553 (rel '(("next") ("previous") ("parent") ("subdocument") ("made")))
1554 (href '("href" ("ftp:") ("file:") ("finger:") ("gopher:") ("http:")
1555 ("mailto:") ("news:") ("rlogin:") ("telnet:") ("tn3270:")
fcc3195e 1556 ("wais:") ("/cgi-bin/")))
1caf38eb
RS
1557 (name '("name"))
1558 (link `(,href
1559 ("rel" ,@rel)
1560 ("rev" ,@rel)
1561 ("title")))
b4f05c38 1562 (list '((nil \n ("List item: " "<li>" str
a3ec4ba0 1563 (if sgml-xml-mode "</li>") \n))))
1caf38eb 1564 (cell `(t
e1940c83 1565 ,@align
1caf38eb
RS
1566 ("valign" ,@valign)
1567 ("colspan" ,@1-9)
1568 ("rowspan" ,@1-9)
1569 ("nowrap" t))))
1570 ;; put ,-expressions first, else byte-compile chokes (as of V19.29)
1571 ;; and like this it's more efficient anyway
1572 `(("a" ,name ,@link)
1573 ("base" t ,@href)
1574 ("dir" ,@list)
d10447ba 1575 ("font" nil "size" ("-1") ("+1") ("-2") ("+2") ,@1-7)
73d25e52 1576 ("form" (\n _ \n "<input type=\"submit\" value=\"\""
af3abed1 1577 (if sgml-xml-mode " />" ">"))
fcc3195e 1578 ("action" ,@(cdr href)) ("method" ("get") ("post")))
1caf38eb
RS
1579 ("h1" ,@align)
1580 ("h2" ,@align)
1581 ("h3" ,@align)
1582 ("h4" ,@align)
1583 ("h5" ,@align)
1584 ("h6" ,@align)
1585 ("hr" t ("size" ,@1-9) ("width") ("noshade" t) ,@align)
1586 ("img" t ("align" ,@valign ("texttop") ("absmiddle") ("absbottom"))
1587 ("src") ("alt") ("width" "1") ("height" "1")
1588 ("border" "1") ("vspace" "1") ("hspace" "1") ("ismap" t))
1589 ("input" t ("size" ,@1-9) ("maxlength" ,@1-9) ("checked" t) ,name
fcc3195e
RS
1590 ("type" ("text") ("password") ("checkbox") ("radio")
1591 ("submit") ("reset"))
1caf38eb
RS
1592 ("value"))
1593 ("link" t ,@link)
1594 ("menu" ,@list)
d10447ba 1595 ("ol" ,@list ("type" ("A") ("a") ("I") ("i") ("1")))
1caf38eb
RS
1596 ("p" t ,@align)
1597 ("select" (nil \n
1598 ("Text: "
a3ec4ba0 1599 "<option>" str (if sgml-xml-mode "</option>") \n))
1caf38eb
RS
1600 ,name ("size" ,@1-9) ("multiple" t))
1601 ("table" (nil \n
1602 ((completing-read "Cell kind: " '(("td") ("th"))
1603 nil t "t")
73d25e52 1604 "<tr><" str ?> _
a3ec4ba0 1605 (if sgml-xml-mode (concat "<" str "></tr>")) \n))
1caf38eb
RS
1606 ("border" t ,@1-9) ("width" "10") ("cellpadding"))
1607 ("td" ,@cell)
1608 ("textarea" ,name ("rows" ,@1-9) ("cols" ,@1-9))
1609 ("th" ,@cell)
d10447ba 1610 ("ul" ,@list ("type" ("disc") ("circle") ("square")))
1caf38eb
RS
1611
1612 ,@sgml-tag-alist
1613
1614 ("abbrev")
1615 ("acronym")
1616 ("address")
1617 ("array" (nil \n
a3ec4ba0 1618 ("Item: " "<item>" str (if sgml-xml-mode "</item>") \n))
1caf38eb
RS
1619 "align")
1620 ("au")
1621 ("b")
1622 ("big")
1623 ("blink")
1624 ("blockquote" \n)
1625 ("body" \n ("background" ".gif") ("bgcolor" "#") ("text" "#")
1626 ("link" "#") ("alink" "#") ("vlink" "#"))
a3ec4ba0 1627 ("box" (nil _ "<over>" _ (if sgml-xml-mode "</over>")))
1caf38eb
RS
1628 ("br" t ("clear" ("left") ("right")))
1629 ("caption" ("valign" ("top") ("bottom")))
1630 ("center" \n)
1631 ("cite")
1632 ("code" \n)
a3ec4ba0 1633 ("dd" ,(not sgml-xml-mode))
1caf38eb
RS
1634 ("del")
1635 ("dfn")
e1940c83 1636 ("div")
1caf38eb
RS
1637 ("dl" (nil \n
1638 ( "Term: "
a3ec4ba0
SM
1639 "<dt>" str (if sgml-xml-mode "</dt>")
1640 "<dd>" _ (if sgml-xml-mode "</dd>") \n)))
1641 ("dt" (t _ (if sgml-xml-mode "</dt>")
1642 "<dd>" (if sgml-xml-mode "</dd>") \n))
1caf38eb 1643 ("em")
d10447ba 1644 ;("fn" "id" "fn") ; ???
1caf38eb
RS
1645 ("head" \n)
1646 ("html" (\n
1647 "<head>\n"
1648 "<title>" (setq str (read-input "Title: ")) "</title>\n"
5e532c5c 1649 "</head>\n"
1caf38eb
RS
1650 "<body>\n<h1>" str "</h1>\n" _
1651 "\n<address>\n<a href=\"mailto:"
be047262 1652 user-mail-address
5e532c5c
RS
1653 "\">" (user-full-name) "</a>\n</address>\n"
1654 "</body>"
1655 ))
1caf38eb
RS
1656 ("i")
1657 ("ins")
1658 ("isindex" t ("action") ("prompt"))
1659 ("kbd")
1660 ("lang")
a3ec4ba0 1661 ("li" ,(not sgml-xml-mode))
1caf38eb
RS
1662 ("math" \n)
1663 ("nobr")
1664 ("option" t ("value") ("label") ("selected" t))
1665 ("over" t)
1666 ("person")
1667 ("pre" \n)
1668 ("q")
1669 ("rev")
1670 ("s")
1671 ("samp")
1672 ("small")
64367655
SM
1673 ("span" nil
1674 ("class"
1675 ("builtin")
1676 ("comment")
1677 ("constant")
1678 ("function-name")
1679 ("keyword")
1680 ("string")
1681 ("type")
1682 ("variable-name")
1683 ("warning")))
1caf38eb
RS
1684 ("strong")
1685 ("sub")
1686 ("sup")
1687 ("title")
1688 ("tr" t)
1689 ("tt")
1690 ("u")
1691 ("var")
1692 ("wbr" t)))
1693 "*Value of `sgml-tag-alist' for HTML mode.")
1694
1695(defvar html-tag-help
1696 `(,@sgml-tag-help
1697 ("a" . "Anchor of point or link elsewhere")
1698 ("abbrev" . "?")
1699 ("acronym" . "?")
1700 ("address" . "Formatted mail address")
1701 ("array" . "Math array")
1702 ("au" . "?")
1703 ("b" . "Bold face")
1704 ("base" . "Base address for URLs")
1705 ("big" . "Font size")
1706 ("blink" . "Blinking text")
1707 ("blockquote" . "Indented quotation")
1708 ("body" . "Document body")
1709 ("box" . "Math fraction")
1710 ("br" . "Line break")
1711 ("caption" . "Table caption")
1712 ("center" . "Centered text")
1713 ("changed" . "Change bars")
1714 ("cite" . "Citation of a document")
1715 ("code" . "Formatted source code")
1716 ("dd" . "Definition of term")
1717 ("del" . "?")
1718 ("dfn" . "?")
1719 ("dir" . "Directory list (obsolete)")
1720 ("dl" . "Definition list")
1721 ("dt" . "Term to be definined")
98d90904 1722 ("em" . "Emphasized")
1caf38eb
RS
1723 ("embed" . "Embedded data in foreign format")
1724 ("fig" . "Figure")
1725 ("figa" . "Figure anchor")
1726 ("figd" . "Figure description")
1727 ("figt" . "Figure text")
d10447ba 1728 ;("fn" . "?") ; ???
1caf38eb
RS
1729 ("font" . "Font size")
1730 ("form" . "Form with input fields")
1731 ("group" . "Document grouping")
1732 ("h1" . "Most important section headline")
1733 ("h2" . "Important section headline")
1734 ("h3" . "Section headline")
1735 ("h4" . "Minor section headline")
1736 ("h5" . "Unimportant section headline")
1737 ("h6" . "Least important section headline")
1738 ("head" . "Document header")
1739 ("hr" . "Horizontal rule")
1740 ("html" . "HTML Document")
1741 ("i" . "Italic face")
1742 ("img" . "Graphic image")
1743 ("input" . "Form input field")
1744 ("ins" . "?")
1745 ("isindex" . "Input field for index search")
1746 ("kbd" . "Keybard example face")
1747 ("lang" . "Natural language")
1748 ("li" . "List item")
1749 ("link" . "Link relationship")
1750 ("math" . "Math formula")
1751 ("menu" . "Menu list (obsolete)")
1752 ("mh" . "Form mail header")
1753 ("nextid" . "Allocate new id")
1754 ("nobr" . "Text without line break")
1755 ("ol" . "Ordered list")
1756 ("option" . "Selection list item")
1757 ("over" . "Math fraction rule")
1758 ("p" . "Paragraph start")
1759 ("panel" . "Floating panel")
1760 ("person" . "?")
1761 ("pre" . "Preformatted fixed width text")
1762 ("q" . "?")
1763 ("rev" . "Reverse video")
1764 ("s" . "?")
1765 ("samp" . "Sample text")
1766 ("select" . "Selection list")
1767 ("small" . "Font size")
1768 ("sp" . "Nobreak space")
1769 ("strong" . "Standout text")
1770 ("sub" . "Subscript")
1771 ("sup" . "Superscript")
1772 ("table" . "Table with rows and columns")
1773 ("tb" . "Table vertical break")
1774 ("td" . "Table data cell")
1775 ("textarea" . "Form multiline edit area")
1776 ("th" . "Table header cell")
1777 ("title" . "Document title")
1778 ("tr" . "Table row separator")
1779 ("tt" . "Typewriter face")
1780 ("u" . "Underlined text")
1781 ("ul" . "Unordered list")
1782 ("var" . "Math variable face")
1783 ("wbr" . "Enable <br> within <nobr>"))
1784"*Value of `sgml-tag-help' for HTML mode.")
9d4ce428 1785
3bf0b727 1786\f
1caf38eb 1787;;;###autoload
64367655 1788(define-derived-mode html-mode sgml-mode "HTML"
1caf38eb 1789 "Major mode based on SGML mode for editing HTML documents.
7be38f7d 1790This allows inserting skeleton constructs used in hypertext documents with
fcc3195e
RS
1791completion. See below for an introduction to HTML. Use
1792\\[browse-url-of-buffer] to see how this comes out. See also `sgml-mode' on
1793which this is based.
1caf38eb 1794
fcc3195e 1795Do \\[describe-variable] html- SPC and \\[describe-variable] sgml- SPC to see available variables.
1caf38eb
RS
1796
1797To write fairly well formatted pages you only need to know few things. Most
1798browsers have a function to read the source code of the page being seen, so
1799you can imitate various tricks. Here's a very short HTML primer which you
1800can also view with a browser to see what happens:
1801
1802<title>A Title Describing Contents</title> should be on every page. Pages can
1803have <h1>Very Major Headlines</h1> through <h6>Very Minor Headlines</h6>
1804<hr> Parts can be separated with horizontal rules.
1805
1806<p>Paragraphs only need an opening tag. Line breaks and multiple spaces are
1807ignored unless the text is <pre>preformatted.</pre> Text can be marked as
73cba75d 1808<b>bold</b>, <i>italic</i> or <u>underlined</u> using the normal M-o or
1caf38eb
RS
1809Edit/Text Properties/Face commands.
1810
1811Pages can have <a name=\"SOMENAME\">named points</a> and can link other points
1812to them with <a href=\"#SOMENAME\">see also somename</a>. In the same way <a
1813href=\"URL\">see also URL</a> where URL is a filename relative to current
f788776c 1814directory, or absolute as in `http://www.cs.indiana.edu/elisp/w3/docs.html'.
1caf38eb
RS
1815
1816Images in many formats can be inlined with <img src=\"URL\">.
1817
f788776c
RS
1818If you mainly create your own documents, `sgml-specials' might be
1819interesting. But note that some HTML 2 browsers can't handle `&apos;'.
1820To work around that, do:
1821 (eval-after-load \"sgml-mode\" '(aset sgml-char-names ?' nil))
1caf38eb 1822
1caf38eb 1823\\{html-mode-map}"
64367655
SM
1824 (set (make-local-variable 'sgml-display-text) html-display-text)
1825 (set (make-local-variable 'sgml-tag-face-alist) html-tag-face-alist)
1caf38eb
RS
1826 (make-local-variable 'sgml-tag-alist)
1827 (make-local-variable 'sgml-face-tag-alist)
1828 (make-local-variable 'sgml-tag-help)
1829 (make-local-variable 'outline-regexp)
1830 (make-local-variable 'outline-heading-end-regexp)
1831 (make-local-variable 'outline-level)
da84bdc4
RS
1832 (make-local-variable 'sentence-end)
1833 (setq sentence-end
b8b14971
DL
1834 (if sentence-end-double-space
1835 "[.?!][]\"')}]*\\(<[^>]*>\\)*\\($\\| $\\|\t\\| \\)[ \t\n]*"
64367655 1836 "[.?!][]\"')}]*\\(<[^>]*>\\)*\\($\\|[ \t]\\)[ \t\n]*"))
a01588fc 1837 (setq sgml-tag-alist html-tag-alist
1caf38eb
RS
1838 sgml-face-tag-alist html-face-tag-alist
1839 sgml-tag-help html-tag-help
1840 outline-regexp "^.*<[Hh][1-6]\\>"
1841 outline-heading-end-regexp "</[Hh][1-6]>"
1842 outline-level (lambda ()
0fda8eff 1843 (char-before (match-end 0))))
3bf0b727 1844 (setq imenu-create-index-function 'html-imenu-index)
a3ec4ba0 1845 (when sgml-xml-mode (setq mode-name "XHTML"))
73d25e52 1846 (set (make-local-variable 'sgml-empty-tags)
5f3d924d
SM
1847 ;; From HTML-4.01's loose.dtd, parsed with `sgml-parse-dtd',
1848 ;; plus manual addition of "wbr".
1849 '("area" "base" "basefont" "br" "col" "frame" "hr" "img" "input"
1850 "isindex" "link" "meta" "param" "wbr"))
1851 (set (make-local-variable 'sgml-unclosed-tags)
1852 ;; From HTML-4.01's loose.dtd, parsed with `sgml-parse-dtd'.
1853 '("body" "colgroup" "dd" "dt" "head" "html" "li" "option"
1854 "p" "tbody" "td" "tfoot" "th" "thead" "tr"))
e1940c83
SM
1855 ;; It's for the user to decide if it defeats it or not -stef
1856 ;; (make-local-variable 'imenu-sort-function)
1857 ;; (setq imenu-sort-function nil) ; sorting the menu defeats the purpose
64367655 1858 )
9d4ce428 1859
3bf0b727
RS
1860(defvar html-imenu-regexp
1861 "\\s-*<h\\([1-9]\\)[^\n<>]*>\\(<[^\n<>]*>\\)*\\s-*\\([^\n<>]*\\)"
1862 "*A regular expression matching a head line to be added to the menu.
1863The first `match-string' should be a number from 1-9.
1864The second `match-string' matches extra tags and is ignored.
1865The third `match-string' will be the used in the menu.")
1866
1867(defun html-imenu-index ()
a9d4efa2 1868 "Return a table of contents for an HTML buffer for use with Imenu."
3bf0b727
RS
1869 (let (toc-index)
1870 (save-excursion
1871 (goto-char (point-min))
1872 (while (re-search-forward html-imenu-regexp nil t)
1873 (setq toc-index
1874 (cons (cons (concat (make-string
1875 (* 2 (1- (string-to-number (match-string 1))))
fae1a906 1876 ?\s)
3bf0b727 1877 (match-string 3))
5950e029 1878 (line-beginning-position))
3bf0b727
RS
1879 toc-index))))
1880 (nreverse toc-index)))
1caf38eb 1881
4e7a42d2 1882(define-minor-mode html-autoview-mode
d4c89075 1883 "Toggle automatic viewing via `browse-url-of-buffer' upon saving buffer.
3bf0b727
RS
1884With positive prefix ARG always turns viewing on, with negative ARG always off.
1885Can be used as a value for `html-mode-hook'."
4e7a42d2 1886 nil nil nil
966cdb22 1887 :group 'sgml
4e7a42d2
SM
1888 (if html-autoview-mode
1889 (add-hook 'after-save-hook 'browse-url-of-buffer nil t)
1890 (remove-hook 'after-save-hook 'browse-url-of-buffer t)))
9d4ce428 1891
3bf0b727 1892\f
1caf38eb
RS
1893(define-skeleton html-href-anchor
1894 "HTML anchor tag with href attribute."
a391b179 1895 "URL: "
af3abed1 1896 ;; '(setq input "http:")
a391b179 1897 "<a href=\"" str "\">" _ "</a>")
1caf38eb
RS
1898
1899(define-skeleton html-name-anchor
1900 "HTML anchor tag with name attribute."
a391b179 1901 "Name: "
af3abed1
JL
1902 "<a name=\"" str "\""
1903 (if sgml-xml-mode (concat " id=\"" str "\""))
1904 ">" _ "</a>")
1caf38eb 1905
7e49eef2
RS
1906(define-skeleton html-headline-1
1907 "HTML level 1 headline tags."
1908 nil
1909 "<h1>" _ "</h1>")
1910
1911(define-skeleton html-headline-2
1912 "HTML level 2 headline tags."
1913 nil
1914 "<h2>" _ "</h2>")
1915
1916(define-skeleton html-headline-3
1917 "HTML level 3 headline tags."
1918 nil
1919 "<h3>" _ "</h3>")
1920
1921(define-skeleton html-headline-4
1922 "HTML level 4 headline tags."
1923 nil
1924 "<h4>" _ "</h4>")
1925
1926(define-skeleton html-headline-5
1927 "HTML level 5 headline tags."
1928 nil
1929 "<h5>" _ "</h5>")
1930
1931(define-skeleton html-headline-6
1932 "HTML level 6 headline tags."
1933 nil
1934 "<h6>" _ "</h6>")
1caf38eb
RS
1935
1936(define-skeleton html-horizontal-rule
1937 "HTML horizontal rule tag."
1938 nil
af3abed1 1939 (if sgml-xml-mode "<hr />" "<hr>") \n)
1caf38eb
RS
1940
1941(define-skeleton html-image
1942 "HTML image tag."
af3abed1
JL
1943 "Image URL: "
1944 "<img src=\"" str "\" alt=\"" _ "\""
1945 (if sgml-xml-mode " />" ">"))
1caf38eb
RS
1946
1947(define-skeleton html-line
1948 "HTML line break tag."
1949 nil
af3abed1 1950 (if sgml-xml-mode "<br />" "<br>") \n)
1caf38eb 1951
7e49eef2
RS
1952(define-skeleton html-ordered-list
1953 "HTML ordered list tags."
1954 nil
a391b179 1955 "<ol>" \n
a3ec4ba0 1956 "<li>" _ (if sgml-xml-mode "</li>") \n
7e49eef2
RS
1957 "</ol>")
1958
1959(define-skeleton html-unordered-list
1960 "HTML unordered list tags."
1961 nil
a391b179 1962 "<ul>" \n
a3ec4ba0 1963 "<li>" _ (if sgml-xml-mode "</li>") \n
7e49eef2 1964 "</ul>")
1caf38eb
RS
1965
1966(define-skeleton html-list-item
1967 "HTML list item tag."
1968 nil
1969 (if (bolp) nil '\n)
a3ec4ba0 1970 "<li>" _ (if sgml-xml-mode "</li>"))
1caf38eb
RS
1971
1972(define-skeleton html-paragraph
1973 "HTML paragraph tag."
1974 nil
1975 (if (bolp) nil ?\n)
af3abed1 1976 "<p>" _ (if sgml-xml-mode "</p>"))
1caf38eb 1977
fcc3195e
RS
1978(define-skeleton html-checkboxes
1979 "Group of connected checkbox inputs."
1980 nil
a391b179
RS
1981 '(setq v1 nil
1982 v2 nil)
1983 ("Value: "
d10447ba 1984 "<input type=\"" (identity "checkbox") ; see comment above about identity
a391b179 1985 "\" name=\"" (or v1 (setq v1 (skeleton-read "Name: ")))
fcc3195e 1986 "\" value=\"" str ?\"
b4f05c38 1987 (when (y-or-n-p "Set \"checked\" attribute? ")
af3abed1
JL
1988 (funcall skeleton-transformation
1989 (if sgml-xml-mode " checked=\"checked\"" " checked")))
1990 (if sgml-xml-mode " />" ">")
a391b179
RS
1991 (skeleton-read "Text: " (capitalize str))
1992 (or v2 (setq v2 (if (y-or-n-p "Newline after text? ")
b4f05c38 1993 (funcall skeleton-transformation
af3abed1 1994 (if sgml-xml-mode "<br />" "<br>"))
a391b179
RS
1995 "")))
1996 \n))
fcc3195e 1997
1caf38eb
RS
1998(define-skeleton html-radio-buttons
1999 "Group of connected radio button inputs."
2000 nil
a391b179
RS
2001 '(setq v1 nil
2002 v2 (cons nil nil))
2003 ("Value: "
d10447ba 2004 "<input type=\"" (identity "radio") ; see comment above about identity
a391b179 2005 "\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: ")))
1caf38eb 2006 "\" value=\"" str ?\"
b4f05c38 2007 (when (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? ")))
af3abed1
JL
2008 (funcall skeleton-transformation
2009 (if sgml-xml-mode " checked=\"checked\"" " checked")))
2010 (if sgml-xml-mode " />" ">")
a391b179
RS
2011 (skeleton-read "Text: " (capitalize str))
2012 (or (cdr v2) (setcdr v2 (if (y-or-n-p "Newline after text? ")
b4f05c38 2013 (funcall skeleton-transformation
af3abed1 2014 (if sgml-xml-mode "<br />" "<br>"))
a391b179
RS
2015 "")))
2016 \n))
1caf38eb 2017
e1940c83 2018(provide 'sgml-mode)
6a05d05f 2019
e9146d5a 2020;; arch-tag: 9675da94-b7f9-4bda-ad19-73ed7b4fb401
72c0ae01 2021;;; sgml-mode.el ends here