(define-skeleton): Doc fix.
[bpt/emacs.git] / lisp / textmodes / sgml-mode.el
CommitLineData
1caf38eb 1;;; sgml-mode.el --- SGML- and HTML-editing modes
72c0ae01 2
1caf38eb 3;; Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
6d74b528 4
64ae0c23 5;; Author: James Clark <jjc@jclark.com>
1caf38eb 6;; Adapted-By: ESR; Daniel.Pfeiffer@Informatik.START.dbp.de
a391b179 7;; F.Potorti@cnuce.cnr.it
1caf38eb 8;; Keywords: wp, hypermedia, comm, languages
72c0ae01 9
72c0ae01
ER
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
7c938215 14;; the Free Software Foundation; either version 2, or (at your option)
72c0ae01
ER
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
b578f267
EN
23;; along with GNU Emacs; see the file COPYING. If not, write to the
24;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25;; Boston, MA 02111-1307, USA.
72c0ae01
ER
26
27;;; Commentary:
28
1caf38eb
RS
29;; Configurable major mode for editing document in the SGML standard general
30;; markup language. As an example contains a mode for editing the derived
31;; HTML hypertext markup language.
72c0ae01
ER
32
33;;; Code:
34
64ae0c23
RS
35(defgroup sgml nil
36 "SGML editing mode"
37 :group 'languages)
38
a391b179
RS
39(defcustom sgml-transformation nil
40 "*Default value for `skeleton-transformation' (which see) in SGML mode."
41 :type 'function
c60e7b0d 42 :group 'sgml)
a391b179
RS
43
44(put 'sgml-transformation 'variable-interactive
45 "aTransformation function: ")
46
1caf38eb
RS
47;; As long as Emacs' syntax can't be complemented with predicates to context
48;; sensitively confirm the syntax of characters, we have to live with this
49;; kludgy kind of tradeoff.
21a6f23c 50(defvar sgml-specials '(?\")
1caf38eb
RS
51 "List of characters that have a special meaning for sgml-mode.
52This list is used when first loading the sgml-mode library.
53The supported characters and potential disadvantages are:
54
55 ?\\\" Makes \" in text start a string.
56 ?' Makes ' in text start a string.
57 ?- Makes -- in text start a comment.
58
59When only one of ?\\\" or ?' are included, \"'\" or '\"' as it can be found in
60DTDs, start a string. To partially avoid this problem this also makes these
21a6f23c
RS
61self insert as named entities depending on `sgml-quick-keys'.
62
63Including ?- has the problem of affecting dashes that have nothing to do
64with comments, so we normally turn it off.")
fcc3195e
RS
65
66(defvar sgml-quick-keys nil
67 "Use <, >, &, SPC and `sgml-specials' keys ``electrically'' when non-nil.
68This takes effect when first loading the library.")
1caf38eb
RS
69
70
71(defvar sgml-mode-map
72 (let ((map (list 'keymap (make-vector 256 nil)))
73 (menu-map (make-sparse-keymap "SGML")))
74 (define-key map "\t" 'indent-relative-maybe)
75 (define-key map "\C-c\C-i" 'sgml-tags-invisible)
76 (define-key map "/" 'sgml-slash)
fcc3195e
RS
77 (define-key map "\C-c\C-n" 'sgml-name-char)
78 (define-key map "\C-c\C-t" 'sgml-tag)
1caf38eb
RS
79 (define-key map "\C-c\C-a" 'sgml-attributes)
80 (define-key map "\C-c\C-b" 'sgml-skip-tag-backward)
81 (define-key map [?\C-c left] 'sgml-skip-tag-backward)
82 (define-key map "\C-c\C-f" 'sgml-skip-tag-forward)
83 (define-key map [?\C-c right] 'sgml-skip-tag-forward)
84 (define-key map "\C-c\C-d" 'sgml-delete-tag)
85 (define-key map "\C-c\^?" 'sgml-delete-tag)
86 (define-key map "\C-c?" 'sgml-tag-help)
1caf38eb
RS
87 (define-key map "\C-c8" 'sgml-name-8bit-mode)
88 (define-key map "\C-c\C-v" 'sgml-validate)
fcc3195e
RS
89 (if sgml-quick-keys
90 (progn
91 (define-key map "&" 'sgml-name-char)
92 (define-key map "<" 'sgml-tag)
93 (define-key map " " 'sgml-auto-attributes)
94 (define-key map ">" 'sgml-maybe-end-tag)
95 (if (memq ?\" sgml-specials)
96 (define-key map "\"" 'sgml-name-self))
97 (if (memq ?' sgml-specials)
98 (define-key map "'" 'sgml-name-self))))
1caf38eb
RS
99 (let ((c 127)
100 (map (nth 1 map)))
101 (while (< (setq c (1+ c)) 256)
102 (aset map c 'sgml-maybe-name-self)))
103 (define-key map [menu-bar sgml] (cons "SGML" menu-map))
104 (define-key menu-map [sgml-validate] '("Validate" . sgml-validate))
105 (define-key menu-map [sgml-name-8bit-mode]
106 '("Toggle 8 Bit Insertion" . sgml-name-8bit-mode))
107 (define-key menu-map [sgml-tags-invisible]
108 '("Toggle Tag Visibility" . sgml-tags-invisible))
109 (define-key menu-map [sgml-tag-help]
110 '("Describe Tag" . sgml-tag-help))
111 (define-key menu-map [sgml-delete-tag]
112 '("Delete Tag" . sgml-delete-tag))
113 (define-key menu-map [sgml-skip-tag-forward]
114 '("Forward Tag" . sgml-skip-tag-forward))
115 (define-key menu-map [sgml-skip-tag-backward]
116 '("Backward Tag" . sgml-skip-tag-backward))
117 (define-key menu-map [sgml-attributes]
118 '("Insert Attributes" . sgml-attributes))
119 (define-key menu-map [sgml-tag] '("Insert Tag" . sgml-tag))
120 map)
121 "Keymap for SGML mode. See also `sgml-specials'.")
122
123
124(defvar sgml-mode-syntax-table
125 (let ((table (copy-syntax-table text-mode-syntax-table)))
126 (modify-syntax-entry ?< "(>" table)
127 (modify-syntax-entry ?> ")<" table)
128 (if (memq ?- sgml-specials)
129 (modify-syntax-entry ?- "_ 1234" table))
130 (if (memq ?\" sgml-specials)
131 (modify-syntax-entry ?\" "\"\"" table))
132 (if (memq ?' sgml-specials)
133 (modify-syntax-entry ?\' "\"'" table))
134 table)
135 "Syntax table used in SGML mode. See also `sgml-specials'.")
136
72c0ae01 137
64ae0c23
RS
138(defcustom sgml-name-8bit-mode nil
139 "*When non-`nil' insert 8 bit characters with their names."
140 :type 'boolean
141 :group 'sgml)
72c0ae01 142
1caf38eb
RS
143(defvar sgml-char-names
144 [nil nil nil nil nil nil nil nil
145 nil nil nil nil nil nil nil nil
146 nil nil nil nil nil nil nil nil
147 nil nil nil nil nil nil nil nil
a391b179 148 "nbsp" "excl" "quot" "num" "dollar" "percnt" "amp" "apos"
1caf38eb
RS
149 "lpar" "rpar" "ast" "plus" "comma" "hyphen" "period" "sol"
150 nil nil nil nil nil nil nil nil
151 nil nil "colon" "semi" "lt" "eq" "gt" "quest"
152 "commat" nil nil nil nil nil nil nil
153 nil nil nil nil nil nil nil nil
154 nil nil nil nil nil nil nil nil
155 nil nil nil "lsqb" nil "rsqb" "uarr" "lowbar"
156 "lsquo" nil nil nil nil nil nil nil
157 nil nil nil nil nil nil nil nil
158 nil nil nil nil nil nil nil nil
159 nil nil nil "lcub" "verbar" "rcub" "tilde" nil
160 nil nil nil nil nil nil nil nil
161 nil nil nil nil nil nil nil nil
162 nil nil nil nil nil nil nil nil
163 nil nil nil nil nil nil nil nil
164 "nbsp" "iexcl" "cent" "pound" "curren" "yen" "brvbar" "sect"
165 "uml" "copy" "ordf" "laquo" "not" "shy" "reg" "macr"
166 "ring" "plusmn" "sup2" "sup3" "acute" "micro" "para" "middot"
167 "cedil" "sup1" "ordm" "raquo" "frac14" "half" "frac34" "iquest"
168 "Agrave" "Aacute" "Acirc" "Atilde" "Auml" "Aring" "AElig" "Ccedil"
169 "Egrave" "Eacute" "Ecirc" "Euml" "Igrave" "Iacute" "Icirc" "Iuml"
170 "ETH" "Ntilde" "Ograve" "Oacute" "Ocirc" "Otilde" "Ouml" nil
171 "Oslash" "Ugrave" "Uacute" "Ucirc" "Uuml" "Yacute" "THORN" "szlig"
172 "agrave" "aacute" "acirc" "atilde" "auml" "aring" "aelig" "ccedil"
173 "egrave" "eacute" "ecirc" "euml" "igrave" "iacute" "icirc" "iuml"
174 "eth" "ntilde" "ograve" "oacute" "ocirc" "otilde" "ouml" "divide"
175 "oslash" "ugrave" "uacute" "ucirc" "uuml" "yacute" "thorn" "yuml"]
176 "Vector of symbolic character names without `&' and `;'.")
177
178
179;; sgmls is a free SGML parser available from
180;; ftp.uu.net:pub/text-processing/sgml
181;; Its error messages can be parsed by next-error.
182;; The -s option suppresses output.
183
64ae0c23 184(defcustom sgml-validate-command "sgmls -s"
72c0ae01
ER
185 "*The command to validate an SGML document.
186The file name of current buffer file name will be appended to this,
64ae0c23
RS
187separated by a space."
188 :type 'string
189 :group 'sgml)
72c0ae01
ER
190
191(defvar sgml-saved-validate-command nil
192 "The command last used to validate in this buffer.")
193
72c0ae01 194
1caf38eb
RS
195;;; I doubt that null end tags are used much for large elements,
196;;; so use a small distance here.
64ae0c23
RS
197(defcustom sgml-slash-distance 1000
198 "*If non-nil, is the maximum distance to search for matching /."
199 :type '(choice (const nil) integer)
200 :group 'sgml)
72c0ae01 201
1caf38eb
RS
202(defconst sgml-start-tag-regex
203 "<[A-Za-z]\\([-.A-Za-z0-9= \n\t]\\|\"[^\"]*\"\\|'[^']*'\\)*"
204 "Regular expression that matches a non-empty start tag.
205Any terminating > or / is not matched.")
206
207
208(defvar sgml-font-lock-keywords
209 '(("<\\([!?][a-z0-9]+\\)" 1 font-lock-keyword-face)
210 ("<\\(/?[a-z0-9]+\\)" 1 font-lock-function-name-face)
21a6f23c
RS
211 ("[&%][-.A-Za-z0-9]+;?" . font-lock-variable-name-face)
212 ("<!--[^<>]*-->" . font-lock-comment-face))
1caf38eb
RS
213 "*Rules for highlighting SGML code. See also `sgml-tag-face-alist'.")
214
215;; internal
216(defvar sgml-font-lock-keywords-1 ())
217
218(defvar sgml-face-tag-alist ()
219 "Alist of face and tag name for facemenu.")
220
221(defvar sgml-tag-face-alist ()
222 "Tag names and face or list of faces to fontify with when invisible.
223When `font-lock-maximum-decoration' is 1 this is always used for fontifying.
224When more these are fontified together with `sgml-font-lock-keywords'.")
225
226
227(defvar sgml-display-text ()
228 "Tag names as lowercase symbols, and display string when invisible.")
229
230;; internal
231(defvar sgml-tags-invisible nil)
232
233
64ae0c23 234(defcustom sgml-tag-alist
fcc3195e
RS
235 '(("![" ("ignore" t) ("include" t))
236 ("!attlist")
1caf38eb
RS
237 ("!doctype")
238 ("!element")
239 ("!entity"))
240 "*Alist of tag names for completing read and insertion rules.
241This alist is made up as
242
243 ((\"tag\" . TAGRULE)
244 ...)
245
246TAGRULE is a list of optionally `t' (no endtag) or `\\n' (separate endtag by
247newlines) or a skeleton with `nil', `t' or `\\n' in place of the interactor
248followed by an ATTRIBUTERULE (for an always present attribute) or an
249attribute alist.
250
251The attribute alist is made up as
252
253 ((\"attribute\" . ATTRIBUTERULE)
254 ...)
255
256ATTRIBUTERULE is a list of optionally `t' (no value when no input) followed by
64ae0c23
RS
257an optional alist of possible values."
258 :type '(repeat (cons (string :tag "Tag Name")
259 (repeat :tag "Tag Rule" sexp)))
260 :group 'sgml)
1caf38eb 261
64ae0c23 262(defcustom sgml-tag-help
1caf38eb
RS
263 '(("!" . "Empty declaration for comment")
264 ("![" . "Embed declarations with parser directive")
265 ("!attlist" . "Tag attributes declaration")
266 ("!doctype" . "Document type (DTD) declaration")
267 ("!element" . "Tag declaration")
268 ("!entity" . "Entity (macro) declaration"))
64ae0c23
RS
269 "*Alist of tag name and short description."
270 :type '(repeat (cons (string :tag "Tag Name")
271 (string :tag "Description")))
272 :group 'sgml)
1caf38eb 273
1caf38eb
RS
274(defun sgml-mode-common (sgml-tag-face-alist sgml-display-text)
275 "Common code for setting up `sgml-mode' and derived modes.
276SGML-TAG-FACE-ALIST is used for calculating `sgml-font-lock-keywords-1'.
277SGML-DISPLAY-TEXT sets up alternate text for when tags are invisible (see
278varables of same name)."
72c0ae01
ER
279 (kill-all-local-variables)
280 (setq local-abbrev-table text-mode-abbrev-table)
1caf38eb
RS
281 (set-syntax-table sgml-mode-syntax-table)
282 (make-local-variable 'indent-line-function)
72c0ae01 283 (make-local-variable 'paragraph-start)
72c0ae01 284 (make-local-variable 'paragraph-separate)
72c0ae01 285 (make-local-variable 'sgml-saved-validate-command)
72c0ae01 286 (make-local-variable 'comment-start)
72c0ae01 287 (make-local-variable 'comment-end)
e41b2db1 288 (make-local-variable 'comment-indent-function)
72c0ae01 289 (make-local-variable 'comment-start-skip)
1caf38eb
RS
290 (make-local-variable 'comment-indent-function)
291 (make-local-variable 'sgml-tags-invisible)
292 (make-local-variable 'skeleton-transformation)
293 (make-local-variable 'skeleton-further-elements)
294 (make-local-variable 'skeleton-end-hook)
295 (make-local-variable 'font-lock-defaults)
296 (make-local-variable 'sgml-font-lock-keywords-1)
297 (make-local-variable 'facemenu-add-face-function)
298 (make-local-variable 'facemenu-end-add-face)
299 ;;(make-local-variable 'facemenu-remove-face-function)
300 (and sgml-tag-face-alist
301 (not (assq 1 sgml-tag-face-alist))
302 (nconc sgml-tag-face-alist
303 `((1 (,(concat "<\\("
304 (mapconcat 'car sgml-tag-face-alist "\\|")
305 "\\)\\([ \t].+\\)?>\\(.+\\)</\\1>")
306 3 (cdr (assoc (match-string 1) ',sgml-tag-face-alist)))))))
307 (setq indent-line-function 'indent-relative-maybe
308 ;; A start or end tag by itself on a line separates a paragraph.
309 ;; This is desirable because SGML discards a newline that appears
310 ;; immediately after a start tag or immediately before an end tag.
311 paragraph-start "^[ \t\n]\\|\
312\\(</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$\\)"
313 paragraph-separate "^[ \t\n]*$\\|\
314^</?\\([A-Za-z]\\([-.A-Za-z0-9= \t\n]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?>$"
315 comment-start "<!-- "
316 comment-end " -->"
317 comment-indent-function 'sgml-comment-indent
318 ;; This will allow existing comments within declarations to be
319 ;; recognized.
320 comment-start-skip "--[ \t]*"
a391b179 321 skeleton-transformation sgml-transformation
1caf38eb
RS
322 skeleton-further-elements '((completion-ignore-case t))
323 skeleton-end-hook (lambda ()
324 (or (eolp)
325 (not (or (eq v2 '\n)
326 (eq (car-safe v2) '\n)))
327 (newline-and-indent)))
328 sgml-font-lock-keywords-1 (cdr (assq 1 sgml-tag-face-alist))
329 font-lock-defaults '((sgml-font-lock-keywords
330 sgml-font-lock-keywords-1)
331 nil
332 t)
6811a757 333 facemenu-add-face-function 'sgml-mode-facemenu-add-face-function)
1caf38eb
RS
334 (while sgml-display-text
335 (put (car (car sgml-display-text)) 'before-string
336 (cdr (car sgml-display-text)))
337 (setq sgml-display-text (cdr sgml-display-text)))
72c0ae01
ER
338 (run-hooks 'text-mode-hook 'sgml-mode-hook))
339
1caf38eb 340
6811a757
RS
341(defun sgml-mode-facemenu-add-face-function (face end)
342 (if (setq face (cdr (assq face sgml-face-tag-alist)))
343 (progn
344 (setq face (funcall skeleton-transformation face))
345 (setq facemenu-end-add-face (concat "</" face ">"))
346 (concat "<" face ">"))
347 (error "Face not configured for %s mode." mode-name)))
348
349
1caf38eb
RS
350;;;###autoload
351(defun sgml-mode (&optional function)
352 "Major mode for editing SGML documents.
353Makes > match <. Makes / blink matching /.
fcc3195e
RS
354Keys <, &, SPC within <>, \" and ' can be electric depending on
355`sgml-quick-keys'.
1caf38eb 356
a391b179
RS
357An argument of N to a tag-inserting command means that the next N
358words should be wrapped. When the region is highlighted, N defaults
359to -1, which means the current region.
360
361If you like upcased tags, put (setq skeleton-transformation 'upcase) in
362sgml-mode-hook.
1caf38eb
RS
363
364Use \\[sgml-validate] to validate your document with an SGML parser.
a391b179
RS
365
366Do \\[describe-variable] sgml- SPC to see available variables.
367Do \\[describe-key] on the following bindings to discover what they do.
1caf38eb
RS
368\\{sgml-mode-map}"
369 (interactive)
370 (sgml-mode-common sgml-tag-face-alist sgml-display-text)
371 (use-local-map sgml-mode-map)
372 (setq mode-name "SGML"
373 major-mode 'sgml-mode))
374
375
376
72c0ae01
ER
377(defun sgml-comment-indent ()
378 (if (and (looking-at "--")
1caf38eb 379 (not (and (eq (preceding-char) ?!)
72c0ae01
ER
380 (eq (char-after (- (point) 2)) ?<))))
381 (progn
382 (skip-chars-backward " \t")
383 (max comment-column (1+ (current-column))))
384 0))
385
72c0ae01 386
72c0ae01
ER
387
388(defun sgml-slash (arg)
389 "Insert / and display any previous matching /.
390Two /s are treated as matching if the first / ends a net-enabling
391start tag, and the second / is the corresponding null end tag."
392 (interactive "p")
393 (insert-char ?/ arg)
394 (if (> arg 0)
395 (let ((oldpos (point))
396 (blinkpos)
397 (level 0))
398 (save-excursion
399 (save-restriction
400 (if sgml-slash-distance
401 (narrow-to-region (max (point-min)
402 (- (point) sgml-slash-distance))
403 oldpos))
404 (if (and (re-search-backward sgml-start-tag-regex (point-min) t)
405 (eq (match-end 0) (1- oldpos)))
406 ()
407 (goto-char (1- oldpos))
408 (while (and (not blinkpos)
409 (search-backward "/" (point-min) t))
410 (let ((tagend (save-excursion
411 (if (re-search-backward sgml-start-tag-regex
412 (point-min) t)
413 (match-end 0)
414 nil))))
415 (if (eq tagend (point))
416 (if (eq level 0)
417 (setq blinkpos (point))
418 (setq level (1- level)))
419 (setq level (1+ level)))))))
420 (if blinkpos
421 (progn
422 (goto-char blinkpos)
423 (if (pos-visible-in-window-p)
424 (sit-for 1)
425 (message "Matches %s"
426 (buffer-substring (progn
427 (beginning-of-line)
428 (point))
429 (1+ blinkpos))))))))))
430
1caf38eb
RS
431
432(defun sgml-name-char (&optional char)
433 "Insert a symbolic character name according to `sgml-char-names'.
4348 bit chars may be inserted with the meta key as in M-SPC for no break space,
435or M-- for a soft hyphen."
436 (interactive "*")
437 (insert ?&)
438 (or char
9b0ffdac 439 (setq char (read-quoted-char "Enter char or octal number")))
1caf38eb
RS
440 (delete-backward-char 1)
441 (insert char)
442 (undo-boundary)
443 (delete-backward-char 1)
444 (insert ?&
445 (or (aref sgml-char-names char)
446 (format "#%d" char))
447 ?\;))
448
449
450(defun sgml-name-self ()
451 "Insert a symbolic character name according to `sgml-char-names'."
452 (interactive "*")
453 (sgml-name-char last-command-char))
454
455
456(defun sgml-maybe-name-self ()
457 "Insert a symbolic character name according to `sgml-char-names'."
458 (interactive "*")
459 (if sgml-name-8bit-mode
460 (sgml-name-char last-command-char)
461 (self-insert-command 1)))
462
463
464(defun sgml-name-8bit-mode ()
465 "Toggle insertion of 8 bit characters."
466 (interactive)
467 (setq sgml-name-8bit-mode (not sgml-name-8bit-mode)))
468
469
470
471(define-skeleton sgml-tag
472 "Insert a tag you are prompted for, optionally with attributes.
473Completion and configuration is according to `sgml-tag-alist'.
474If you like tags and attributes in uppercase set `skeleton-transformation'
475to `upcase'."
476 (funcall skeleton-transformation
477 (completing-read "Tag: " sgml-tag-alist))
478 ?< (setq v1 (eval str)) |
479 (("") -1 '(undo-boundary) "&lt;") |
480 (("") '(setq v2 (sgml-attributes v1 t)) ?>
fcc3195e
RS
481 (if (string= "![" v1)
482 (prog1 '(("") " [ " _ " ]]")
483 (backward-char))
484 (if (or (eq v2 t)
485 (string-match "^[/!?]" v1))
486 ()
487 (if (symbolp v2)
488 '(("") v2 _ v2 "</" v1 ?>)
489 (if (eq (car v2) t)
490 (cons '("") (cdr v2))
491 (append '(("") (car v2))
492 (cdr v2)
493 '(resume: (car v2) _ "</" v1 ?>))))))))
1caf38eb
RS
494
495(autoload 'skeleton-read "skeleton")
496
497(defun sgml-attributes (alist &optional quiet)
498 "When at toplevel of a tag, interactively insert attributes."
499 (interactive (list (save-excursion (sgml-beginning-of-tag t))))
500 (or (stringp alist) (error "Wrong context for adding attribute"))
501 (if alist
502 (let ((completion-ignore-case t)
503 car attribute i)
504 (setq alist (cdr (assoc (downcase alist) sgml-tag-alist)))
505 (if (or (symbolp (car alist))
506 (symbolp (car (car alist))))
507 (setq car (car alist)
508 alist (cdr alist)))
509 (or quiet
510 (message "No attributes configured."))
511 (if (stringp (car alist))
512 (progn
513 (insert (if (eq (preceding-char) ? ) "" ? ) (car alist))
514 (sgml-value alist))
515 (setq i (length alist))
516 (while (> i 0)
517 (insert ? )
518 (insert (funcall skeleton-transformation
519 (setq attribute
520 (skeleton-read '(completing-read
521 "[Attribute]: "
522 alist)))))
523 (if (string= "" attribute)
524 (setq i 0)
525 (sgml-value (assoc attribute alist))
526 (setq i (1- i))))
527 (if (eq (preceding-char) ? )
528 (delete-backward-char 1)))
529 car)))
530
531(defun sgml-auto-attributes (arg)
532 "Self insert, except, when at top level of tag, prompt for attributes.
fcc3195e 533With prefix ARG only self insert."
1caf38eb
RS
534 (interactive "*P")
535 (let ((point (point))
536 tag)
537 (if (or arg
1caf38eb
RS
538 (not sgml-tag-alist) ; no message when nothing configured
539 (symbolp (setq tag (save-excursion (sgml-beginning-of-tag t))))
540 (eq (aref tag 0) ?/))
541 (self-insert-command (prefix-numeric-value arg))
542 (sgml-attributes tag)
543 (setq last-command-char ? )
544 (or (> (point) point)
545 (self-insert-command 1)))))
546
547
548(defun sgml-tag-help (&optional tag)
549 "Display description of optional TAG or tag at point."
550 (interactive)
551 (or tag
552 (save-excursion
553 (if (eq (following-char) ?<)
554 (forward-char))
555 (setq tag (sgml-beginning-of-tag))))
556 (or (stringp tag)
557 (error "No tag selected"))
558 (setq tag (downcase tag))
f68f40e0
KH
559 (message "%s"
560 (or (cdr (assoc tag sgml-tag-help))
1caf38eb
RS
561 (and (eq (aref tag 0) ?/)
562 (cdr (assoc (substring tag 1) sgml-tag-help)))
563 "No description available")))
564
565
566(defun sgml-maybe-end-tag ()
567 "Name self unless in position to end a tag."
568 (interactive)
569 (or (condition-case nil
570 (save-excursion (up-list -1))
571 (error
572 (sgml-name-self)
573 t))
574 (condition-case nil
575 (progn
576 (save-excursion (up-list 1))
577 (sgml-name-self))
578 (error (self-insert-command 1)))))
579
580
581(defun sgml-skip-tag-backward (arg)
582 "Skip to beginning of tag or matching opening tag if present.
583With prefix ARG, repeat that many times."
584 (interactive "p")
585 (while (>= arg 1)
586 (search-backward "<" nil t)
587 (if (looking-at "</\\([^ \n\t>]+\\)")
588 ;; end tag, skip any nested pairs
589 (let ((case-fold-search t)
590 (re (concat "</?" (regexp-quote (match-string 1)))))
591 (while (and (re-search-backward re nil t)
592 (eq (char-after (1+ (point))) ?/))
593 (forward-char 1)
594 (sgml-skip-tag-backward 1))))
595 (setq arg (1- arg))))
596
597(defun sgml-skip-tag-forward (arg &optional return)
598 "Skip to end of tag or matching closing tag if present.
599With prefix ARG, repeat that many times.
600Return t iff after a closing tag."
601 (interactive "p")
602 (setq return t)
603 (while (>= arg 1)
604 (skip-chars-forward "^<>")
605 (if (eq (following-char) ?>)
606 (up-list -1))
607 (if (looking-at "<\\([^/ \n\t>]+\\)")
608 ;; start tag, skip any nested same pairs _and_ closing tag
609 (let ((case-fold-search t)
610 (re (concat "</?" (regexp-quote (match-string 1))))
611 point close)
612 (forward-list 1)
613 (setq point (point))
614 (while (and (re-search-forward re nil t)
615 (not (setq close
616 (eq (char-after (1+ (match-beginning 0))) ?/)))
617 (not (up-list -1))
618 (sgml-skip-tag-forward 1))
619 (setq close nil))
620 (if close
621 (up-list 1)
622 (goto-char point)
623 (setq return)))
624 (forward-list 1))
625 (setq arg (1- arg)))
626 return)
627
628(defun sgml-delete-tag (arg)
629 "Delete tag on or after cursor, and matching closing or opening tag.
630With prefix ARG, repeat that many times."
631 (interactive "p")
632 (while (>= arg 1)
633 (save-excursion
634 (let* (close open)
fcc3195e 635 (if (looking-at "[ \t\n]*<")
1caf38eb
RS
636 ;; just before tag
637 (if (eq (char-after (match-end 0)) ?/)
638 ;; closing tag
639 (progn
640 (setq close (point))
641 (goto-char (match-end 0))))
642 ;; on tag?
643 (or (save-excursion (setq close (sgml-beginning-of-tag)
644 close (and (stringp close)
645 (eq (aref close 0) ?/)
646 (point))))
647 ;; not on closing tag
648 (let ((point (point)))
649 (sgml-skip-tag-backward 1)
650 (if (or (not (eq (following-char) ?<))
651 (save-excursion
652 (forward-list 1)
653 (<= (point) point)))
654 (error "Not on or before tag")))))
655 (if close
656 (progn
657 (sgml-skip-tag-backward 1)
658 (setq open (point))
659 (goto-char close)
660 (kill-sexp 1))
661 (setq open (point))
662 (sgml-skip-tag-forward 1)
663 (backward-list)
664 (forward-char)
665 (if (eq (aref (sgml-beginning-of-tag) 0) ?/)
666 (kill-sexp 1)))
667 (goto-char open)
668 (kill-sexp 1)))
669 (setq arg (1- arg))))
a391b179
RS
670\f
671;; Put read-only last to enable setting this even when read-only enabled.
672(or (get 'sgml-tag 'invisible)
673 (setplist 'sgml-tag
674 (append '(invisible t
675 intangible t
676 point-entered sgml-point-entered
677 rear-nonsticky t
678 read-only t)
679 (symbol-plist 'sgml-tag))))
1caf38eb
RS
680
681(defun sgml-tags-invisible (arg)
682 "Toggle visibility of existing tags."
683 (interactive "P")
684 (let ((modified (buffer-modified-p))
685 (inhibit-read-only t)
a391b179
RS
686 ;; This is needed in case font lock gets called,
687 ;; since it moves point and might call sgml-point-entered.
688 (inhibit-point-motion-hooks t)
1caf38eb
RS
689 symbol)
690 (save-excursion
a391b179 691 (goto-char (point-min))
1caf38eb
RS
692 (if (setq sgml-tags-invisible
693 (if arg
694 (>= (prefix-numeric-value arg) 0)
695 (not sgml-tags-invisible)))
696 (while (re-search-forward "<\\([!/?A-Za-z][-A-Za-z0-9]*\\)"
697 nil t)
698 (setq symbol (intern-soft (downcase (match-string 1))))
699 (goto-char (match-beginning 0))
700 (and (get symbol 'before-string)
701 (not (overlays-at (point)))
702 (overlay-put (make-overlay (point)
703 (match-beginning 1))
704 'category symbol))
a391b179
RS
705 (put-text-property (point)
706 (progn (forward-list) (point))
1caf38eb 707 'category 'sgml-tag))
a391b179
RS
708 (let ((pos (point)))
709 (while (< (setq pos (next-overlay-change pos)) (point-max))
710 (delete-overlay (car (overlays-at pos)))))
1caf38eb
RS
711 (remove-text-properties (point-min) (point-max)
712 '(category sgml-tag intangible t))))
713 (set-buffer-modified-p modified)
714 (run-hooks 'sgml-tags-invisible-hook)
715 (message "")))
716
717(defun sgml-point-entered (x y)
718 ;; Show preceding or following hidden tag, depending of cursor direction.
719 (let ((inhibit-point-motion-hooks t))
720 (save-excursion
721 (message "Invisible tag: %s"
722 (buffer-substring
723 (point)
724 (if (or (and (> x y)
725 (not (eq (following-char) ?<)))
726 (and (< x y)
727 (eq (preceding-char) ?>)))
728 (backward-list)
729 (forward-list)))))))
a391b179 730\f
1caf38eb
RS
731(autoload 'compile-internal "compile")
732
72c0ae01
ER
733(defun sgml-validate (command)
734 "Validate an SGML document.
735Runs COMMAND, a shell command, in a separate process asynchronously
736with output going to the buffer *compilation*.
737You can then use the command \\[next-error] to find the next error message
738and move to the line in the SGML document that caused it."
739 (interactive
740 (list (read-string "Validate command: "
741 (or sgml-saved-validate-command
742 (concat sgml-validate-command
743 " "
744 (let ((name (buffer-file-name)))
745 (and name
746 (file-name-nondirectory name))))))))
747 (setq sgml-saved-validate-command command)
0afdd8d0
RS
748 (if (or (not compilation-ask-about-save)
749 (y-or-n-p (message "Save buffer %s? " (buffer-name))))
750 (save-buffer))
c7aa4667 751 (compile-internal command "No more errors"))
72c0ae01 752
1caf38eb
RS
753
754(defun sgml-beginning-of-tag (&optional top-level)
755 "Skip to beginning of tag and return its name.
756Else `t'."
757 (or (if top-level
758 (condition-case nil
759 (up-list -1)
760 (error t))
761 (>= (point)
762 (if (search-backward "<" nil t)
763 (save-excursion
764 (forward-list)
765 (point))
766 0)))
767 (if (looking-at "<[!?/]?[[A-Za-z][A-Za-z0-9]*")
768 (buffer-substring-no-properties
769 (1+ (point))
770 (match-end 0))
771 t)))
772
773(defun sgml-value (alist)
774 (setq alist (cdr alist))
775 (if (stringp (car alist))
776 (insert "=\"" (car alist) ?\")
777 (if (eq (car alist) t)
778 (if (cdr alist)
779 (progn
780 (insert "=\"")
781 (setq alist (skeleton-read '(completing-read
782 "[Value]: " (cdr alist))))
783 (if (string< "" alist)
a391b179 784 (insert alist ?\")
1caf38eb
RS
785 (delete-backward-char 2))))
786 (insert "=\"")
787 (if alist
a391b179 788 (insert (skeleton-read '(completing-read "Value: " alist))))
1caf38eb
RS
789 (insert ?\"))))
790
791(provide 'sgml-mode)
792\f
fcc3195e 793(defvar html-quick-keys sgml-quick-keys
b1e7bb48 794 "Use C-c X combinations for quick insertion of frequent tags when non-nil.
fcc3195e 795This defaults to `sgml-quick-keys'.
1caf38eb
RS
796This takes effect when first loading the library.")
797
798(defvar html-mode-map
799 (let ((map (nconc (make-sparse-keymap) sgml-mode-map))
800 (menu-map (make-sparse-keymap "HTML")))
7e49eef2
RS
801 (define-key map "\C-c6" 'html-headline-6)
802 (define-key map "\C-c5" 'html-headline-5)
803 (define-key map "\C-c4" 'html-headline-4)
804 (define-key map "\C-c3" 'html-headline-3)
805 (define-key map "\C-c2" 'html-headline-2)
806 (define-key map "\C-c1" 'html-headline-1)
fcc3195e
RS
807 (define-key map "\C-c\r" 'html-paragraph)
808 (define-key map "\C-c\n" 'html-line)
809 (define-key map "\C-c\C-c-" 'html-horizontal-rule)
7e49eef2
RS
810 (define-key map "\C-c\C-co" 'html-ordered-list)
811 (define-key map "\C-c\C-cu" 'html-unordered-list)
fcc3195e
RS
812 (define-key map "\C-c\C-cr" 'html-radio-buttons)
813 (define-key map "\C-c\C-cc" 'html-checkboxes)
814 (define-key map "\C-c\C-cl" 'html-list-item)
815 (define-key map "\C-c\C-ch" 'html-href-anchor)
816 (define-key map "\C-c\C-cn" 'html-name-anchor)
817 (define-key map "\C-c\C-ci" 'html-image)
1caf38eb
RS
818 (if html-quick-keys
819 (progn
1caf38eb 820 (define-key map "\C-c-" 'html-horizontal-rule)
7e49eef2
RS
821 (define-key map "\C-co" 'html-ordered-list)
822 (define-key map "\C-cu" 'html-unordered-list)
1caf38eb 823 (define-key map "\C-cr" 'html-radio-buttons)
fcc3195e 824 (define-key map "\C-cc" 'html-checkboxes)
1caf38eb
RS
825 (define-key map "\C-cl" 'html-list-item)
826 (define-key map "\C-ch" 'html-href-anchor)
827 (define-key map "\C-cn" 'html-name-anchor)
828 (define-key map "\C-ci" 'html-image)))
829 (define-key map "\C-c\C-s" 'html-autoview-mode)
830 (define-key map "\C-c\C-v" 'browse-url-of-buffer)
831 (define-key map [menu-bar html] (cons "HTML" menu-map))
832 (define-key menu-map [html-autoview-mode]
833 '("Toggle Autoviewing" . html-autoview-mode))
834 (define-key menu-map [browse-url-of-buffer]
835 '("View Buffer Contents" . browse-url-of-buffer))
836 (define-key menu-map [nil] '("--"))
7e49eef2
RS
837 ;;(define-key menu-map "6" '("Heading 6" . html-headline-6))
838 ;;(define-key menu-map "5" '("Heading 5" . html-headline-5))
839 ;;(define-key menu-map "4" '("Heading 4" . html-headline-4))
840 (define-key menu-map "3" '("Heading 3" . html-headline-3))
841 (define-key menu-map "2" '("Heading 2" . html-headline-2))
842 (define-key menu-map "1" '("Heading 1" . html-headline-1))
1caf38eb 843 (define-key menu-map "l" '("Radio Buttons" . html-radio-buttons))
fcc3195e 844 (define-key menu-map "c" '("Checkboxes" . html-checkboxes))
1caf38eb 845 (define-key menu-map "l" '("List Item" . html-list-item))
7e49eef2
RS
846 (define-key menu-map "u" '("Unordered List" . html-unordered-list))
847 (define-key menu-map "o" '("Ordered List" . html-ordered-list))
fcc3195e 848 (define-key menu-map "-" '("Horizontal Rule" . html-horizontal-rule))
1caf38eb
RS
849 (define-key menu-map "\n" '("Line Break" . html-line))
850 (define-key menu-map "\r" '("Paragraph" . html-paragraph))
851 (define-key menu-map "i" '("Image" . html-image))
852 (define-key menu-map "h" '("Href Anchor" . html-href-anchor))
853 (define-key menu-map "n" '("Name Anchor" . html-name-anchor))
854 map)
855 "Keymap for commands for use in HTML mode.")
856
857
858(defvar html-face-tag-alist
859 '((bold . "b")
860 (italic . "i")
861 (underline . "u")
862 (modeline . "rev"))
863 "Value of `sgml-face-tag-alist' for HTML mode.")
864
865(defvar html-tag-face-alist
866 '(("b" . bold)
867 ("big" . bold)
868 ("blink" . highlight)
869 ("cite" . italic)
870 ("em" . italic)
871 ("h1" bold underline)
872 ("h2" bold-italic underline)
873 ("h3" italic underline)
874 ("h4" . underline)
875 ("h5" . underline)
876 ("h6" . underline)
877 ("i" . italic)
878 ("rev" . modeline)
879 ("s" . underline)
880 ("small" . default)
881 ("strong" . bold)
882 ("title" bold underline)
883 ("tt" . default)
884 ("u" . underline)
885 ("var" . italic))
886 "Value of `sgml-tag-face-alist' for HTML mode.")
887
888
889(defvar html-display-text
890 '((img . "[/]")
891 (hr . "----------")
892 (li . "o "))
893 "Value of `sgml-display-text' for HTML mode.")
894
895
896; should code exactly HTML 3 here when that is finished
897(defvar html-tag-alist
898 (let* ((1-9 '(("8") ("9")
899 ("1") ("2") ("3") ("4") ("5") ("6") ("7")))
900 (align '(("align" ("left") ("center") ("right"))))
901 (valign '(("top") ("middle") ("bottom") ("baseline")))
902 (rel '(("next") ("previous") ("parent") ("subdocument") ("made")))
903 (href '("href" ("ftp:") ("file:") ("finger:") ("gopher:") ("http:")
904 ("mailto:") ("news:") ("rlogin:") ("telnet:") ("tn3270:")
fcc3195e 905 ("wais:") ("/cgi-bin/")))
1caf38eb
RS
906 (name '("name"))
907 (link `(,href
908 ("rel" ,@rel)
909 ("rev" ,@rel)
910 ("title")))
911 (list '((nil \n
912 ( "List item: "
913 "<li>" str \n))
914 ("type" ("A") ("a") ("I") ("i") ("1"))))
915 (cell `(t
916 ,align
917 ("valign" ,@valign)
918 ("colspan" ,@1-9)
919 ("rowspan" ,@1-9)
920 ("nowrap" t))))
921 ;; put ,-expressions first, else byte-compile chokes (as of V19.29)
922 ;; and like this it's more efficient anyway
923 `(("a" ,name ,@link)
924 ("base" t ,@href)
925 ("dir" ,@list)
5e70d78d 926 ("font" ("size" ("-1") ("+1") ("-2") ("+2") ,@(cdr (cdr 1-9))))
fcc3195e
RS
927 ("form" (\n _ \n "<input type=\"submit\" value=\"\">")
928 ("action" ,@(cdr href)) ("method" ("get") ("post")))
1caf38eb
RS
929 ("h1" ,@align)
930 ("h2" ,@align)
931 ("h3" ,@align)
932 ("h4" ,@align)
933 ("h5" ,@align)
934 ("h6" ,@align)
935 ("hr" t ("size" ,@1-9) ("width") ("noshade" t) ,@align)
936 ("img" t ("align" ,@valign ("texttop") ("absmiddle") ("absbottom"))
937 ("src") ("alt") ("width" "1") ("height" "1")
938 ("border" "1") ("vspace" "1") ("hspace" "1") ("ismap" t))
939 ("input" t ("size" ,@1-9) ("maxlength" ,@1-9) ("checked" t) ,name
fcc3195e
RS
940 ("type" ("text") ("password") ("checkbox") ("radio")
941 ("submit") ("reset"))
1caf38eb
RS
942 ("value"))
943 ("link" t ,@link)
944 ("menu" ,@list)
945 ("ol" ,@list)
946 ("p" t ,@align)
947 ("select" (nil \n
948 ("Text: "
949 "<option>" str \n))
950 ,name ("size" ,@1-9) ("multiple" t))
951 ("table" (nil \n
952 ((completing-read "Cell kind: " '(("td") ("th"))
953 nil t "t")
954 "<tr><" str ?> _ \n))
955 ("border" t ,@1-9) ("width" "10") ("cellpadding"))
956 ("td" ,@cell)
957 ("textarea" ,name ("rows" ,@1-9) ("cols" ,@1-9))
958 ("th" ,@cell)
959 ("ul" ,@list)
960
961 ,@sgml-tag-alist
962
963 ("abbrev")
964 ("acronym")
965 ("address")
966 ("array" (nil \n
967 ("Item: " "<item>" str \n))
968 "align")
969 ("au")
970 ("b")
971 ("big")
972 ("blink")
973 ("blockquote" \n)
974 ("body" \n ("background" ".gif") ("bgcolor" "#") ("text" "#")
975 ("link" "#") ("alink" "#") ("vlink" "#"))
976 ("box" (nil _ "<over>" _))
977 ("br" t ("clear" ("left") ("right")))
978 ("caption" ("valign" ("top") ("bottom")))
979 ("center" \n)
980 ("cite")
981 ("code" \n)
982 ("dd" t)
983 ("del")
984 ("dfn")
985 ("dl" (nil \n
986 ( "Term: "
987 "<dt>" str "<dd>" _ \n)))
988 ("dt" (t _ "<dd>"))
989 ("em")
990 ("fn" "id" "fn")
991 ("head" \n)
992 ("html" (\n
993 "<head>\n"
994 "<title>" (setq str (read-input "Title: ")) "</title>\n"
995 "<body>\n<h1>" str "</h1>\n" _
996 "\n<address>\n<a href=\"mailto:"
be047262 997 user-mail-address
1caf38eb
RS
998 "\">" (user-full-name) "</a>\n</address>"))
999 ("i")
1000 ("ins")
1001 ("isindex" t ("action") ("prompt"))
1002 ("kbd")
1003 ("lang")
1004 ("li" t)
1005 ("math" \n)
1006 ("nobr")
1007 ("option" t ("value") ("label") ("selected" t))
1008 ("over" t)
1009 ("person")
1010 ("pre" \n)
1011 ("q")
1012 ("rev")
1013 ("s")
1014 ("samp")
1015 ("small")
1016 ("strong")
1017 ("sub")
1018 ("sup")
1019 ("title")
1020 ("tr" t)
1021 ("tt")
1022 ("u")
1023 ("var")
1024 ("wbr" t)))
1025 "*Value of `sgml-tag-alist' for HTML mode.")
1026
1027(defvar html-tag-help
1028 `(,@sgml-tag-help
1029 ("a" . "Anchor of point or link elsewhere")
1030 ("abbrev" . "?")
1031 ("acronym" . "?")
1032 ("address" . "Formatted mail address")
1033 ("array" . "Math array")
1034 ("au" . "?")
1035 ("b" . "Bold face")
1036 ("base" . "Base address for URLs")
1037 ("big" . "Font size")
1038 ("blink" . "Blinking text")
1039 ("blockquote" . "Indented quotation")
1040 ("body" . "Document body")
1041 ("box" . "Math fraction")
1042 ("br" . "Line break")
1043 ("caption" . "Table caption")
1044 ("center" . "Centered text")
1045 ("changed" . "Change bars")
1046 ("cite" . "Citation of a document")
1047 ("code" . "Formatted source code")
1048 ("dd" . "Definition of term")
1049 ("del" . "?")
1050 ("dfn" . "?")
1051 ("dir" . "Directory list (obsolete)")
1052 ("dl" . "Definition list")
1053 ("dt" . "Term to be definined")
1054 ("em" . "Emphasised")
1055 ("embed" . "Embedded data in foreign format")
1056 ("fig" . "Figure")
1057 ("figa" . "Figure anchor")
1058 ("figd" . "Figure description")
1059 ("figt" . "Figure text")
1060 ("fn" . "?")
1061 ("font" . "Font size")
1062 ("form" . "Form with input fields")
1063 ("group" . "Document grouping")
1064 ("h1" . "Most important section headline")
1065 ("h2" . "Important section headline")
1066 ("h3" . "Section headline")
1067 ("h4" . "Minor section headline")
1068 ("h5" . "Unimportant section headline")
1069 ("h6" . "Least important section headline")
1070 ("head" . "Document header")
1071 ("hr" . "Horizontal rule")
1072 ("html" . "HTML Document")
1073 ("i" . "Italic face")
1074 ("img" . "Graphic image")
1075 ("input" . "Form input field")
1076 ("ins" . "?")
1077 ("isindex" . "Input field for index search")
1078 ("kbd" . "Keybard example face")
1079 ("lang" . "Natural language")
1080 ("li" . "List item")
1081 ("link" . "Link relationship")
1082 ("math" . "Math formula")
1083 ("menu" . "Menu list (obsolete)")
1084 ("mh" . "Form mail header")
1085 ("nextid" . "Allocate new id")
1086 ("nobr" . "Text without line break")
1087 ("ol" . "Ordered list")
1088 ("option" . "Selection list item")
1089 ("over" . "Math fraction rule")
1090 ("p" . "Paragraph start")
1091 ("panel" . "Floating panel")
1092 ("person" . "?")
1093 ("pre" . "Preformatted fixed width text")
1094 ("q" . "?")
1095 ("rev" . "Reverse video")
1096 ("s" . "?")
1097 ("samp" . "Sample text")
1098 ("select" . "Selection list")
1099 ("small" . "Font size")
1100 ("sp" . "Nobreak space")
1101 ("strong" . "Standout text")
1102 ("sub" . "Subscript")
1103 ("sup" . "Superscript")
1104 ("table" . "Table with rows and columns")
1105 ("tb" . "Table vertical break")
1106 ("td" . "Table data cell")
1107 ("textarea" . "Form multiline edit area")
1108 ("th" . "Table header cell")
1109 ("title" . "Document title")
1110 ("tr" . "Table row separator")
1111 ("tt" . "Typewriter face")
1112 ("u" . "Underlined text")
1113 ("ul" . "Unordered list")
1114 ("var" . "Math variable face")
1115 ("wbr" . "Enable <br> within <nobr>"))
1116"*Value of `sgml-tag-help' for HTML mode.")
1117
1118
1119
1120;;;###autoload
1121(defun html-mode ()
1122 "Major mode based on SGML mode for editing HTML documents.
fcc3195e
RS
1123This allows inserting skeleton costructs used in hypertext documents with
1124completion. See below for an introduction to HTML. Use
1125\\[browse-url-of-buffer] to see how this comes out. See also `sgml-mode' on
1126which this is based.
1caf38eb 1127
fcc3195e 1128Do \\[describe-variable] html- SPC and \\[describe-variable] sgml- SPC to see available variables.
1caf38eb
RS
1129
1130To write fairly well formatted pages you only need to know few things. Most
1131browsers have a function to read the source code of the page being seen, so
1132you can imitate various tricks. Here's a very short HTML primer which you
1133can also view with a browser to see what happens:
1134
1135<title>A Title Describing Contents</title> should be on every page. Pages can
1136have <h1>Very Major Headlines</h1> through <h6>Very Minor Headlines</h6>
1137<hr> Parts can be separated with horizontal rules.
1138
1139<p>Paragraphs only need an opening tag. Line breaks and multiple spaces are
1140ignored unless the text is <pre>preformatted.</pre> Text can be marked as
1141<b>bold</b>, <i>italic</i> or <u>underlined</u> using the normal M-g or
1142Edit/Text Properties/Face commands.
1143
1144Pages can have <a name=\"SOMENAME\">named points</a> and can link other points
1145to them with <a href=\"#SOMENAME\">see also somename</a>. In the same way <a
1146href=\"URL\">see also URL</a> where URL is a filename relative to current
1147directory or something like http://www.cs.indiana.edu/elisp/w3/docs.html.
1148
1149Images in many formats can be inlined with <img src=\"URL\">.
1150
1151If you mainly create your own documents, `sgml-specials' might be interesting.
1152But note that some HTML 2 browsers can't handle &apos;. To work around that
1153do:
1154
1155\(eval-after-load \"sgml-mode\" '(aset sgml-char-names ?' nil))
1156\\{html-mode-map}"
1157 (interactive)
1158 (sgml-mode-common html-tag-face-alist html-display-text)
1159 (use-local-map html-mode-map)
1160 (make-local-variable 'sgml-tag-alist)
1161 (make-local-variable 'sgml-face-tag-alist)
1162 (make-local-variable 'sgml-tag-help)
1163 (make-local-variable 'outline-regexp)
1164 (make-local-variable 'outline-heading-end-regexp)
1165 (make-local-variable 'outline-level)
da84bdc4
RS
1166 (make-local-variable 'sentence-end)
1167 (setq sentence-end
1168 "[.?!][]\"')}]*\\(<[^>]*>\\)*\\($\\| $\\|\t\\| \\)[ \t\n]*")
1caf38eb
RS
1169 (setq mode-name "HTML"
1170 major-mode 'html-mode
1171 sgml-tag-alist html-tag-alist
1172 sgml-face-tag-alist html-face-tag-alist
1173 sgml-tag-help html-tag-help
1174 outline-regexp "^.*<[Hh][1-6]\\>"
1175 outline-heading-end-regexp "</[Hh][1-6]>"
1176 outline-level (lambda ()
1177 (char-after (1- (match-end 0)))))
1178 (run-hooks 'html-mode-hook))
1179
1180
1181(define-skeleton html-href-anchor
1182 "HTML anchor tag with href attribute."
a391b179
RS
1183 "URL: "
1184 '(setq input "http:")
1185 "<a href=\"" str "\">" _ "</a>")
1caf38eb
RS
1186
1187(define-skeleton html-name-anchor
1188 "HTML anchor tag with name attribute."
a391b179
RS
1189 "Name: "
1190 "<a name=\"" str "\">" _ "</a>")
1caf38eb 1191
7e49eef2
RS
1192(define-skeleton html-headline-1
1193 "HTML level 1 headline tags."
1194 nil
1195 "<h1>" _ "</h1>")
1196
1197(define-skeleton html-headline-2
1198 "HTML level 2 headline tags."
1199 nil
1200 "<h2>" _ "</h2>")
1201
1202(define-skeleton html-headline-3
1203 "HTML level 3 headline tags."
1204 nil
1205 "<h3>" _ "</h3>")
1206
1207(define-skeleton html-headline-4
1208 "HTML level 4 headline tags."
1209 nil
1210 "<h4>" _ "</h4>")
1211
1212(define-skeleton html-headline-5
1213 "HTML level 5 headline tags."
1214 nil
1215 "<h5>" _ "</h5>")
1216
1217(define-skeleton html-headline-6
1218 "HTML level 6 headline tags."
1219 nil
1220 "<h6>" _ "</h6>")
1caf38eb
RS
1221
1222(define-skeleton html-horizontal-rule
1223 "HTML horizontal rule tag."
1224 nil
1225 "<hr>" \n)
1226
1227(define-skeleton html-image
1228 "HTML image tag."
1229 nil
a391b179 1230 "<img src=\"" _ "\">")
1caf38eb
RS
1231
1232(define-skeleton html-line
1233 "HTML line break tag."
1234 nil
1235 "<br>" \n)
1236
7e49eef2
RS
1237(define-skeleton html-ordered-list
1238 "HTML ordered list tags."
1239 nil
a391b179 1240 "<ol>" \n
7e49eef2
RS
1241 "<li>" _ \n
1242 "</ol>")
1243
1244(define-skeleton html-unordered-list
1245 "HTML unordered list tags."
1246 nil
a391b179 1247 "<ul>" \n
1caf38eb 1248 "<li>" _ \n
7e49eef2 1249 "</ul>")
1caf38eb
RS
1250
1251(define-skeleton html-list-item
1252 "HTML list item tag."
1253 nil
1254 (if (bolp) nil '\n)
1255 "<li>")
1256
1257(define-skeleton html-paragraph
1258 "HTML paragraph tag."
1259 nil
1260 (if (bolp) nil ?\n)
1261 \n "<p>")
1262
fcc3195e
RS
1263(define-skeleton html-checkboxes
1264 "Group of connected checkbox inputs."
1265 nil
a391b179
RS
1266 '(setq v1 nil
1267 v2 nil)
1268 ("Value: "
1269 "<input type=\"" (identity "checkbox")
1270 "\" name=\"" (or v1 (setq v1 (skeleton-read "Name: ")))
fcc3195e 1271 "\" value=\"" str ?\"
a391b179
RS
1272 (if (y-or-n-p "Set \"checked\" attribute? ")
1273 (funcall skeleton-transformation " checked")) ">"
1274 (skeleton-read "Text: " (capitalize str))
1275 (or v2 (setq v2 (if (y-or-n-p "Newline after text? ")
1276 (funcall skeleton-transformation "<br>")
1277 "")))
1278 \n))
fcc3195e 1279
1caf38eb
RS
1280(define-skeleton html-radio-buttons
1281 "Group of connected radio button inputs."
1282 nil
a391b179
RS
1283 '(setq v1 nil
1284 v2 (cons nil nil))
1285 ("Value: "
1286 "<input type=\"" (identity "radio")
1287 "\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: ")))
1caf38eb 1288 "\" value=\"" str ?\"
a391b179
RS
1289 (if (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? ")))
1290 (funcall skeleton-transformation " checked") ">")
1291 (skeleton-read "Text: " (capitalize str))
1292 (or (cdr v2) (setcdr v2 (if (y-or-n-p "Newline after text? ")
1293 (funcall skeleton-transformation "<br>")
1294 "")))
1295 \n))
1caf38eb
RS
1296
1297
1298(defun html-autoview-mode (&optional arg)
1299 "Toggle automatic viewing via `html-viewer' upon saving buffer.
1300With positive prefix ARG always turns viewing on, with negative ARG always off.
1301Can be used as a value for `html-mode-hook'."
1302 (interactive "P")
1303 (if (setq arg (if arg
1304 (< (prefix-numeric-value arg) 0)
1305 (and (boundp 'after-save-hook)
1306 (memq 'browse-url-of-buffer after-save-hook))))
1307 (setq after-save-hook (delq 'browse-url-of-buffer after-save-hook))
1308 (make-local-hook 'after-save-hook)
1309 (add-hook 'after-save-hook 'browse-url-of-buffer nil t))
1310 (message "Autoviewing turned %s."
1311 (if arg "off" "on")))
1312
72c0ae01 1313;;; sgml-mode.el ends here