]> code.delx.au - gnu-emacs/blob - lisp/textmodes/sgml-mode.el
(adaptive-fill-first-line-regexp): Fix regexp.
[gnu-emacs] / lisp / textmodes / sgml-mode.el
1 ;;; sgml-mode.el --- SGML- and HTML-editing modes
2
3 ;; Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
4
5 ;; Author: James Clark <jjc@jclark.com>
6 ;; Adapted-By: ESR; Daniel.Pfeiffer@Informatik.START.dbp.de
7 ;; F.Potorti@cnuce.cnr.it
8 ;; Keywords: wp, hypermedia, comm, languages
9
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
14 ;; the Free Software Foundation; either version 2, or (at your option)
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
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.
26
27 ;;; Commentary:
28
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.
32
33 ;;; Code:
34
35 (defgroup sgml nil
36 "SGML editing mode"
37 :group 'languages)
38
39 (defcustom sgml-transformation 'identity
40 "*Default value for `skeleton-transformation' (which see) in SGML mode."
41 :type 'function
42 :group 'sgml)
43
44 (put 'sgml-transformation 'variable-interactive
45 "aTransformation function: ")
46
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.
50 (defvar sgml-specials '(?\")
51 "List of characters that have a special meaning for SGML mode.
52 This list is used when first loading the sgml-mode library.
53 The 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
59 When only one of ?\\\" or ?' are included, \"'\" or '\"' as it can be found in
60 DTDs, start a string. To partially avoid this problem this also makes these
61 self insert as named entities depending on `sgml-quick-keys'.
62
63 Including ?- has the problem of affecting dashes that have nothing to do
64 with comments, so we normally turn it off.")
65
66 (defvar sgml-quick-keys nil
67 "Use <, >, &, SPC and `sgml-specials' keys \"electrically\" when non-nil.
68 This takes effect when first loading the sgml-mode library.")
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)
77 (define-key map "\C-c\C-n" 'sgml-name-char)
78 (define-key map "\C-c\C-t" 'sgml-tag)
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)
87 (define-key map "\C-c8" 'sgml-name-8bit-mode)
88 (define-key map "\C-c\C-v" 'sgml-validate)
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))))
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
137
138 (defcustom sgml-name-8bit-mode nil
139 "*When non-nil, insert 8 bit characters with their names."
140 :type 'boolean
141 :group 'sgml)
142
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
148 "nbsp" "excl" "quot" "num" "dollar" "percnt" "amp" "apos"
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
184 (defcustom sgml-validate-command "sgmls -s"
185 "*The command to validate an SGML document.
186 The file name of current buffer file name will be appended to this,
187 separated by a space."
188 :type 'string
189 :group 'sgml)
190
191 (defvar sgml-saved-validate-command nil
192 "The command last used to validate in this buffer.")
193
194
195 ;;; I doubt that null end tags are used much for large elements,
196 ;;; so use a small distance here.
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)
201
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.
205 Any 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)
211 ("[&%][-.A-Za-z0-9]+;?" . font-lock-variable-name-face)
212 ("<!--[^<>]*-->" . font-lock-comment-face))
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.
223 When `font-lock-maximum-decoration' is 1 this is always used for fontifying.
224 When 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
234 (defcustom sgml-tag-alist
235 '(("![" ("ignore" t) ("include" t))
236 ("!attlist")
237 ("!doctype")
238 ("!element")
239 ("!entity"))
240 "*Alist of tag names for completing read and insertion rules.
241 This alist is made up as
242
243 ((\"tag\" . TAGRULE)
244 ...)
245
246 TAGRULE is a list of optionally `t' (no endtag) or `\\n' (separate endtag by
247 newlines) or a skeleton with `nil', `t' or `\\n' in place of the interactor
248 followed by an ATTRIBUTERULE (for an always present attribute) or an
249 attribute alist.
250
251 The attribute alist is made up as
252
253 ((\"attribute\" . ATTRIBUTERULE)
254 ...)
255
256 ATTRIBUTERULE is a list of optionally `t' (no value when no input) followed by
257 an optional alist of possible values."
258 :type '(repeat (cons (string :tag "Tag Name")
259 (repeat :tag "Tag Rule" sexp)))
260 :group 'sgml)
261
262 (defcustom sgml-tag-help
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"))
269 "*Alist of tag name and short description."
270 :type '(repeat (cons (string :tag "Tag Name")
271 (string :tag "Description")))
272 :group 'sgml)
273
274 (defun sgml-mode-common (sgml-tag-face-alist sgml-display-text)
275 "Common code for setting up `sgml-mode' and derived modes.
276 SGML-TAG-FACE-ALIST is used for calculating `sgml-font-lock-keywords-1'.
277 SGML-DISPLAY-TEXT sets up alternate text for when tags are invisible (see
278 varables of same name)."
279 (kill-all-local-variables)
280 (setq local-abbrev-table text-mode-abbrev-table)
281 (set-syntax-table sgml-mode-syntax-table)
282 (make-local-variable 'indent-line-function)
283 (make-local-variable 'paragraph-start)
284 (make-local-variable 'paragraph-separate)
285 (make-local-variable 'sgml-saved-validate-command)
286 (make-local-variable 'comment-start)
287 (make-local-variable 'comment-end)
288 (make-local-variable 'comment-indent-function)
289 (make-local-variable 'comment-start-skip)
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]*"
321 skeleton-transformation sgml-transformation
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)
333 facemenu-add-face-function 'sgml-mode-facemenu-add-face-function)
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)))
338 (run-hooks 'text-mode-hook 'sgml-mode-hook))
339
340
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
350 ;;;###autoload
351 (defun sgml-mode (&optional function)
352 "Major mode for editing SGML documents.
353 Makes > match <. Makes / blink matching /.
354 Keys <, &, SPC within <>, \" and ' can be electric depending on
355 `sgml-quick-keys'.
356
357 An argument of N to a tag-inserting command means to wrap it around
358 the next N words. In Transient Mark mode, when the mark is active,
359 N defaults to -1, which means to wrap it around the current region.
360
361 If you like upcased tags, put (setq sgml-transformation 'upcase) in
362 your `.emacs' file.
363
364 Use \\[sgml-validate] to validate your document with an SGML parser.
365
366 Do \\[describe-variable] sgml- SPC to see available variables.
367 Do \\[describe-key] on the following bindings to discover what they do.
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
377 (defun sgml-comment-indent ()
378 (if (and (looking-at "--")
379 (not (and (eq (preceding-char) ?!)
380 (eq (char-after (- (point) 2)) ?<))))
381 (progn
382 (skip-chars-backward " \t")
383 (max comment-column (1+ (current-column))))
384 0))
385
386
387
388 (defun sgml-slash (arg)
389 "Insert `/' and display any previous matching `/'.
390 Two `/'s are treated as matching if the first `/' ends a net-enabling
391 start 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
431
432 (defun sgml-name-char (&optional char)
433 "Insert a symbolic character name according to `sgml-char-names'.
434 8 bit chars may be inserted with the meta key as in M-SPC for no break space,
435 or M-- for a soft hyphen."
436 (interactive "*")
437 (insert ?&)
438 (or char
439 (setq char (read-quoted-char "Enter char or octal number")))
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 (message "sgml name 8 bit mode is now %"
469 (if sgml-name-8bit-mode "ON" "OFF")))
470
471
472 ;; When an element of a skeleton is a string "str", it is passed
473 ;; through skeleton-transformation and inserted. If "str" is to be
474 ;; inserted literally, one should obtain it as the return value of a
475 ;; function, e.g. (identity "str").
476
477 (define-skeleton sgml-tag
478 "Prompt for a tag and insert it, optionally with attributes.
479 Completion and configuration are done according to `sgml-tag-alist'.
480 If you like tags and attributes in uppercase do \\[set-variable]
481 skeleton-transformation RET upcase RET, or put this in your `.emacs':
482 (setq sgml-transformation 'upcase)"
483 (funcall skeleton-transformation
484 (completing-read "Tag: " sgml-tag-alist))
485 ?< (setq v1 (eval str)) |
486 (("") -1 '(undo-boundary) (identity "&lt;")) | ; see comment above
487 (("") '(setq v2 (sgml-attributes v1 t)) ?>
488 (if (string= "![" v1)
489 (prog1 '(("") " [ " _ " ]]")
490 (backward-char))
491 (if (or (eq v2 t)
492 (string-match "^[/!?]" v1))
493 ()
494 (if (symbolp v2)
495 '(("") v2 _ v2 "</" v1 ?>)
496 (if (eq (car v2) t)
497 (cons '("") (cdr v2))
498 (append '(("") (car v2))
499 (cdr v2)
500 '(resume: (car v2) _ "</" v1 ?>))))))))
501
502 (autoload 'skeleton-read "skeleton")
503
504 (defun sgml-attributes (tag &optional quiet)
505 "When at top level of a tag, interactively insert attributes.
506
507 Completion and configuration of TAG are done according to `sgml-tag-alist'.
508 If QUIET, do not print a message when there are no attributes for TAG."
509 (interactive (list (save-excursion (sgml-beginning-of-tag t))))
510 (or (stringp tag) (error "Wrong context for adding attribute"))
511 (if tag
512 (let ((completion-ignore-case t)
513 (alist (cdr (assoc (downcase tag) sgml-tag-alist)))
514 car attribute i)
515 (if (or (symbolp (car alist))
516 (symbolp (car (car alist))))
517 (setq car (car alist)
518 alist (cdr alist)))
519 (or quiet
520 (message "No attributes configured."))
521 (if (stringp (car alist))
522 (progn
523 (insert (if (eq (preceding-char) ? ) "" ? )
524 (funcall skeleton-transformation (car alist)))
525 (sgml-value alist))
526 (setq i (length alist))
527 (while (> i 0)
528 (insert ? )
529 (insert (funcall skeleton-transformation
530 (setq attribute
531 (skeleton-read '(completing-read
532 "Attribute: "
533 alist)))))
534 (if (string= "" attribute)
535 (setq i 0)
536 (sgml-value (assoc attribute alist))
537 (setq i (1- i))))
538 (if (eq (preceding-char) ? )
539 (delete-backward-char 1)))
540 car)))
541
542 (defun sgml-auto-attributes (arg)
543 "Self insert the character typed; at top level of tag, prompt for attributes.
544 With prefix argument, only self insert."
545 (interactive "*P")
546 (let ((point (point))
547 tag)
548 (if (or arg
549 (not sgml-tag-alist) ; no message when nothing configured
550 (symbolp (setq tag (save-excursion (sgml-beginning-of-tag t))))
551 (eq (aref tag 0) ?/))
552 (self-insert-command (prefix-numeric-value arg))
553 (sgml-attributes tag)
554 (setq last-command-char ? )
555 (or (> (point) point)
556 (self-insert-command 1)))))
557
558
559 (defun sgml-tag-help (&optional tag)
560 "Display description of tag TAG. If TAG is omitted, use the tag at point."
561 (interactive)
562 (or tag
563 (save-excursion
564 (if (eq (following-char) ?<)
565 (forward-char))
566 (setq tag (sgml-beginning-of-tag))))
567 (or (stringp tag)
568 (error "No tag selected"))
569 (setq tag (downcase tag))
570 (message "%s"
571 (or (cdr (assoc tag sgml-tag-help))
572 (and (eq (aref tag 0) ?/)
573 (cdr (assoc (substring tag 1) sgml-tag-help)))
574 "No description available")))
575
576
577 (defun sgml-maybe-end-tag ()
578 "Name self unless in position to end a tag."
579 (interactive)
580 (or (condition-case nil
581 (save-excursion (up-list -1))
582 (error
583 (sgml-name-self)
584 t))
585 (condition-case nil
586 (progn
587 (save-excursion (up-list 1))
588 (sgml-name-self))
589 (error (self-insert-command 1)))))
590
591
592 (defun sgml-skip-tag-backward (arg)
593 "Skip to beginning of tag or matching opening tag if present.
594 With prefix argument ARG, repeat this ARG times."
595 (interactive "p")
596 (while (>= arg 1)
597 (search-backward "<" nil t)
598 (if (looking-at "</\\([^ \n\t>]+\\)")
599 ;; end tag, skip any nested pairs
600 (let ((case-fold-search t)
601 (re (concat "</?" (regexp-quote (match-string 1)))))
602 (while (and (re-search-backward re nil t)
603 (eq (char-after (1+ (point))) ?/))
604 (forward-char 1)
605 (sgml-skip-tag-backward 1))))
606 (setq arg (1- arg))))
607
608 (defun sgml-skip-tag-forward (arg &optional return)
609 "Skip to end of tag or matching closing tag if present.
610 With prefix argument ARG, repeat this ARG times.
611 Return t iff after a closing tag."
612 (interactive "p")
613 (setq return t)
614 (while (>= arg 1)
615 (skip-chars-forward "^<>")
616 (if (eq (following-char) ?>)
617 (up-list -1))
618 (if (looking-at "<\\([^/ \n\t>]+\\)")
619 ;; start tag, skip any nested same pairs _and_ closing tag
620 (let ((case-fold-search t)
621 (re (concat "</?" (regexp-quote (match-string 1))))
622 point close)
623 (forward-list 1)
624 (setq point (point))
625 (while (and (re-search-forward re nil t)
626 (not (setq close
627 (eq (char-after (1+ (match-beginning 0))) ?/)))
628 (not (up-list -1))
629 (sgml-skip-tag-forward 1))
630 (setq close nil))
631 (if close
632 (up-list 1)
633 (goto-char point)
634 (setq return)))
635 (forward-list 1))
636 (setq arg (1- arg)))
637 return)
638
639 (defun sgml-delete-tag (arg)
640 "Delete tag on or after cursor, and matching closing or opening tag.
641 With prefix argument ARG, repeat this ARG times."
642 (interactive "p")
643 (while (>= arg 1)
644 (save-excursion
645 (let* (close open)
646 (if (looking-at "[ \t\n]*<")
647 ;; just before tag
648 (if (eq (char-after (match-end 0)) ?/)
649 ;; closing tag
650 (progn
651 (setq close (point))
652 (goto-char (match-end 0))))
653 ;; on tag?
654 (or (save-excursion (setq close (sgml-beginning-of-tag)
655 close (and (stringp close)
656 (eq (aref close 0) ?/)
657 (point))))
658 ;; not on closing tag
659 (let ((point (point)))
660 (sgml-skip-tag-backward 1)
661 (if (or (not (eq (following-char) ?<))
662 (save-excursion
663 (forward-list 1)
664 (<= (point) point)))
665 (error "Not on or before tag")))))
666 (if close
667 (progn
668 (sgml-skip-tag-backward 1)
669 (setq open (point))
670 (goto-char close)
671 (kill-sexp 1))
672 (setq open (point))
673 (sgml-skip-tag-forward 1)
674 (backward-list)
675 (forward-char)
676 (if (eq (aref (sgml-beginning-of-tag) 0) ?/)
677 (kill-sexp 1)))
678 (goto-char open)
679 (kill-sexp 1)))
680 (setq arg (1- arg))))
681 \f
682 ;; Put read-only last to enable setting this even when read-only enabled.
683 (or (get 'sgml-tag 'invisible)
684 (setplist 'sgml-tag
685 (append '(invisible t
686 intangible t
687 point-entered sgml-point-entered
688 rear-nonsticky t
689 read-only t)
690 (symbol-plist 'sgml-tag))))
691
692 (defun sgml-tags-invisible (arg)
693 "Toggle visibility of existing tags."
694 (interactive "P")
695 (let ((modified (buffer-modified-p))
696 (inhibit-read-only t)
697 ;; This is needed in case font lock gets called,
698 ;; since it moves point and might call sgml-point-entered.
699 (inhibit-point-motion-hooks t)
700 symbol)
701 (save-excursion
702 (goto-char (point-min))
703 (if (setq sgml-tags-invisible
704 (if arg
705 (>= (prefix-numeric-value arg) 0)
706 (not sgml-tags-invisible)))
707 (while (re-search-forward "<\\([!/?A-Za-z][-A-Za-z0-9]*\\)"
708 nil t)
709 (setq symbol (intern-soft (downcase (match-string 1))))
710 (goto-char (match-beginning 0))
711 (and (get symbol 'before-string)
712 (not (overlays-at (point)))
713 (overlay-put (make-overlay (point)
714 (match-beginning 1))
715 'category symbol))
716 (put-text-property (point)
717 (progn (forward-list) (point))
718 'category 'sgml-tag))
719 (let ((pos (point)))
720 (while (< (setq pos (next-overlay-change pos)) (point-max))
721 (delete-overlay (car (overlays-at pos)))))
722 (remove-text-properties (point-min) (point-max)
723 '(category sgml-tag intangible t))))
724 (set-buffer-modified-p modified)
725 (run-hooks 'sgml-tags-invisible-hook)
726 (message "")))
727
728 (defun sgml-point-entered (x y)
729 ;; Show preceding or following hidden tag, depending of cursor direction.
730 (let ((inhibit-point-motion-hooks t))
731 (save-excursion
732 (message "Invisible tag: %s"
733 (buffer-substring
734 (point)
735 (if (or (and (> x y)
736 (not (eq (following-char) ?<)))
737 (and (< x y)
738 (eq (preceding-char) ?>)))
739 (backward-list)
740 (forward-list)))))))
741 \f
742 (autoload 'compile-internal "compile")
743
744 (defun sgml-validate (command)
745 "Validate an SGML document.
746 Runs COMMAND, a shell command, in a separate process asynchronously
747 with output going to the buffer `*compilation*'.
748 You can then use the command \\[next-error] to find the next error message
749 and move to the line in the SGML document that caused it."
750 (interactive
751 (list (read-string "Validate command: "
752 (or sgml-saved-validate-command
753 (concat sgml-validate-command
754 " "
755 (let ((name (buffer-file-name)))
756 (and name
757 (file-name-nondirectory name))))))))
758 (setq sgml-saved-validate-command command)
759 (if (or (not compilation-ask-about-save)
760 (y-or-n-p (message "Save buffer %s? " (buffer-name))))
761 (save-buffer))
762 (compile-internal command "No more errors"))
763
764
765 (defun sgml-beginning-of-tag (&optional top-level)
766 "Skip to beginning of tag and return its name.
767 If this can't be done, return t."
768 (or (if top-level
769 (condition-case nil
770 (up-list -1)
771 (error t))
772 (>= (point)
773 (if (search-backward "<" nil t)
774 (save-excursion
775 (forward-list)
776 (point))
777 0)))
778 (if (looking-at "<[!?/]?[[A-Za-z][A-Za-z0-9]*")
779 (buffer-substring-no-properties
780 (1+ (point))
781 (match-end 0))
782 t)))
783
784 (defun sgml-value (alist)
785 "Interactively insert value taken from attributerule ALIST.
786 See `sgml-tag-alist' for info about attributerules.."
787 (setq alist (cdr alist))
788 (if (stringp (car alist))
789 (insert "=\"" (car alist) ?\")
790 (if (eq (car alist) t)
791 (if (cdr alist)
792 (progn
793 (insert "=\"")
794 (setq alist (skeleton-read '(completing-read
795 "Value: " (cdr alist))))
796 (if (string< "" alist)
797 (insert alist ?\")
798 (delete-backward-char 2))))
799 (insert "=\"")
800 (if alist
801 (insert (skeleton-read '(completing-read "Value: " alist))))
802 (insert ?\"))))
803
804 (provide 'sgml-mode)
805 \f
806 (defvar html-quick-keys sgml-quick-keys
807 "Use C-c X combinations for quick insertion of frequent tags when non-nil.
808 This defaults to `sgml-quick-keys'.
809 This takes effect when first loading the library.")
810
811 (defvar html-mode-map
812 (let ((map (nconc (make-sparse-keymap) sgml-mode-map))
813 (menu-map (make-sparse-keymap "HTML")))
814 (define-key map "\C-c6" 'html-headline-6)
815 (define-key map "\C-c5" 'html-headline-5)
816 (define-key map "\C-c4" 'html-headline-4)
817 (define-key map "\C-c3" 'html-headline-3)
818 (define-key map "\C-c2" 'html-headline-2)
819 (define-key map "\C-c1" 'html-headline-1)
820 (define-key map "\C-c\r" 'html-paragraph)
821 (define-key map "\C-c\n" 'html-line)
822 (define-key map "\C-c\C-c-" 'html-horizontal-rule)
823 (define-key map "\C-c\C-co" 'html-ordered-list)
824 (define-key map "\C-c\C-cu" 'html-unordered-list)
825 (define-key map "\C-c\C-cr" 'html-radio-buttons)
826 (define-key map "\C-c\C-cc" 'html-checkboxes)
827 (define-key map "\C-c\C-cl" 'html-list-item)
828 (define-key map "\C-c\C-ch" 'html-href-anchor)
829 (define-key map "\C-c\C-cn" 'html-name-anchor)
830 (define-key map "\C-c\C-ci" 'html-image)
831 (if html-quick-keys
832 (progn
833 (define-key map "\C-c-" 'html-horizontal-rule)
834 (define-key map "\C-co" 'html-ordered-list)
835 (define-key map "\C-cu" 'html-unordered-list)
836 (define-key map "\C-cr" 'html-radio-buttons)
837 (define-key map "\C-cc" 'html-checkboxes)
838 (define-key map "\C-cl" 'html-list-item)
839 (define-key map "\C-ch" 'html-href-anchor)
840 (define-key map "\C-cn" 'html-name-anchor)
841 (define-key map "\C-ci" 'html-image)))
842 (define-key map "\C-c\C-s" 'html-autoview-mode)
843 (define-key map "\C-c\C-v" 'browse-url-of-buffer)
844 (define-key map [menu-bar html] (cons "HTML" menu-map))
845 (define-key menu-map [html-autoview-mode]
846 '("Toggle Autoviewing" . html-autoview-mode))
847 (define-key menu-map [browse-url-of-buffer]
848 '("View Buffer Contents" . browse-url-of-buffer))
849 (define-key menu-map [nil] '("--"))
850 ;;(define-key menu-map "6" '("Heading 6" . html-headline-6))
851 ;;(define-key menu-map "5" '("Heading 5" . html-headline-5))
852 ;;(define-key menu-map "4" '("Heading 4" . html-headline-4))
853 (define-key menu-map "3" '("Heading 3" . html-headline-3))
854 (define-key menu-map "2" '("Heading 2" . html-headline-2))
855 (define-key menu-map "1" '("Heading 1" . html-headline-1))
856 (define-key menu-map "l" '("Radio Buttons" . html-radio-buttons))
857 (define-key menu-map "c" '("Checkboxes" . html-checkboxes))
858 (define-key menu-map "l" '("List Item" . html-list-item))
859 (define-key menu-map "u" '("Unordered List" . html-unordered-list))
860 (define-key menu-map "o" '("Ordered List" . html-ordered-list))
861 (define-key menu-map "-" '("Horizontal Rule" . html-horizontal-rule))
862 (define-key menu-map "\n" '("Line Break" . html-line))
863 (define-key menu-map "\r" '("Paragraph" . html-paragraph))
864 (define-key menu-map "i" '("Image" . html-image))
865 (define-key menu-map "h" '("Href Anchor" . html-href-anchor))
866 (define-key menu-map "n" '("Name Anchor" . html-name-anchor))
867 map)
868 "Keymap for commands for use in HTML mode.")
869
870
871 (defvar html-face-tag-alist
872 '((bold . "b")
873 (italic . "i")
874 (underline . "u")
875 (modeline . "rev"))
876 "Value of `sgml-face-tag-alist' for HTML mode.")
877
878 (defvar html-tag-face-alist
879 '(("b" . bold)
880 ("big" . bold)
881 ("blink" . highlight)
882 ("cite" . italic)
883 ("em" . italic)
884 ("h1" bold underline)
885 ("h2" bold-italic underline)
886 ("h3" italic underline)
887 ("h4" . underline)
888 ("h5" . underline)
889 ("h6" . underline)
890 ("i" . italic)
891 ("rev" . modeline)
892 ("s" . underline)
893 ("small" . default)
894 ("strong" . bold)
895 ("title" bold underline)
896 ("tt" . default)
897 ("u" . underline)
898 ("var" . italic))
899 "Value of `sgml-tag-face-alist' for HTML mode.")
900
901
902 (defvar html-display-text
903 '((img . "[/]")
904 (hr . "----------")
905 (li . "o "))
906 "Value of `sgml-display-text' for HTML mode.")
907
908
909 ; should code exactly HTML 3 here when that is finished
910 (defvar html-tag-alist
911 (let* ((1-7 '(("1") ("2") ("3") ("4") ("5") ("6") ("7")))
912 (1-9 '(,@1-7 ("8") ("9")))
913 (align '(("align" ("left") ("center") ("right"))))
914 (valign '(("top") ("middle") ("bottom") ("baseline")))
915 (rel '(("next") ("previous") ("parent") ("subdocument") ("made")))
916 (href '("href" ("ftp:") ("file:") ("finger:") ("gopher:") ("http:")
917 ("mailto:") ("news:") ("rlogin:") ("telnet:") ("tn3270:")
918 ("wais:") ("/cgi-bin/")))
919 (name '("name"))
920 (link `(,href
921 ("rel" ,@rel)
922 ("rev" ,@rel)
923 ("title")))
924 (list '((nil \n ( "List item: "
925 "<li>" str \n))))
926 (cell `(t
927 ,align
928 ("valign" ,@valign)
929 ("colspan" ,@1-9)
930 ("rowspan" ,@1-9)
931 ("nowrap" t))))
932 ;; put ,-expressions first, else byte-compile chokes (as of V19.29)
933 ;; and like this it's more efficient anyway
934 `(("a" ,name ,@link)
935 ("base" t ,@href)
936 ("dir" ,@list)
937 ("font" nil "size" ("-1") ("+1") ("-2") ("+2") ,@1-7)
938 ("form" (\n _ \n "<input type=\"submit\" value=\"\">")
939 ("action" ,@(cdr href)) ("method" ("get") ("post")))
940 ("h1" ,@align)
941 ("h2" ,@align)
942 ("h3" ,@align)
943 ("h4" ,@align)
944 ("h5" ,@align)
945 ("h6" ,@align)
946 ("hr" t ("size" ,@1-9) ("width") ("noshade" t) ,@align)
947 ("img" t ("align" ,@valign ("texttop") ("absmiddle") ("absbottom"))
948 ("src") ("alt") ("width" "1") ("height" "1")
949 ("border" "1") ("vspace" "1") ("hspace" "1") ("ismap" t))
950 ("input" t ("size" ,@1-9) ("maxlength" ,@1-9) ("checked" t) ,name
951 ("type" ("text") ("password") ("checkbox") ("radio")
952 ("submit") ("reset"))
953 ("value"))
954 ("link" t ,@link)
955 ("menu" ,@list)
956 ("ol" ,@list ("type" ("A") ("a") ("I") ("i") ("1")))
957 ("p" t ,@align)
958 ("select" (nil \n
959 ("Text: "
960 "<option>" str \n))
961 ,name ("size" ,@1-9) ("multiple" t))
962 ("table" (nil \n
963 ((completing-read "Cell kind: " '(("td") ("th"))
964 nil t "t")
965 "<tr><" str ?> _ \n))
966 ("border" t ,@1-9) ("width" "10") ("cellpadding"))
967 ("td" ,@cell)
968 ("textarea" ,name ("rows" ,@1-9) ("cols" ,@1-9))
969 ("th" ,@cell)
970 ("ul" ,@list ("type" ("disc") ("circle") ("square")))
971
972 ,@sgml-tag-alist
973
974 ("abbrev")
975 ("acronym")
976 ("address")
977 ("array" (nil \n
978 ("Item: " "<item>" str \n))
979 "align")
980 ("au")
981 ("b")
982 ("big")
983 ("blink")
984 ("blockquote" \n)
985 ("body" \n ("background" ".gif") ("bgcolor" "#") ("text" "#")
986 ("link" "#") ("alink" "#") ("vlink" "#"))
987 ("box" (nil _ "<over>" _))
988 ("br" t ("clear" ("left") ("right")))
989 ("caption" ("valign" ("top") ("bottom")))
990 ("center" \n)
991 ("cite")
992 ("code" \n)
993 ("dd" t)
994 ("del")
995 ("dfn")
996 ("dl" (nil \n
997 ( "Term: "
998 "<dt>" str "<dd>" _ \n)))
999 ("dt" (t _ "<dd>"))
1000 ("em")
1001 ;("fn" "id" "fn") ; ???
1002 ("head" \n)
1003 ("html" (\n
1004 "<head>\n"
1005 "<title>" (setq str (read-input "Title: ")) "</title>\n"
1006 "<body>\n<h1>" str "</h1>\n" _
1007 "\n<address>\n<a href=\"mailto:"
1008 user-mail-address
1009 "\">" (user-full-name) "</a>\n</address>"))
1010 ("i")
1011 ("ins")
1012 ("isindex" t ("action") ("prompt"))
1013 ("kbd")
1014 ("lang")
1015 ("li" t)
1016 ("math" \n)
1017 ("nobr")
1018 ("option" t ("value") ("label") ("selected" t))
1019 ("over" t)
1020 ("person")
1021 ("pre" \n)
1022 ("q")
1023 ("rev")
1024 ("s")
1025 ("samp")
1026 ("small")
1027 ("strong")
1028 ("sub")
1029 ("sup")
1030 ("title")
1031 ("tr" t)
1032 ("tt")
1033 ("u")
1034 ("var")
1035 ("wbr" t)))
1036 "*Value of `sgml-tag-alist' for HTML mode.")
1037
1038 (defvar html-tag-help
1039 `(,@sgml-tag-help
1040 ("a" . "Anchor of point or link elsewhere")
1041 ("abbrev" . "?")
1042 ("acronym" . "?")
1043 ("address" . "Formatted mail address")
1044 ("array" . "Math array")
1045 ("au" . "?")
1046 ("b" . "Bold face")
1047 ("base" . "Base address for URLs")
1048 ("big" . "Font size")
1049 ("blink" . "Blinking text")
1050 ("blockquote" . "Indented quotation")
1051 ("body" . "Document body")
1052 ("box" . "Math fraction")
1053 ("br" . "Line break")
1054 ("caption" . "Table caption")
1055 ("center" . "Centered text")
1056 ("changed" . "Change bars")
1057 ("cite" . "Citation of a document")
1058 ("code" . "Formatted source code")
1059 ("dd" . "Definition of term")
1060 ("del" . "?")
1061 ("dfn" . "?")
1062 ("dir" . "Directory list (obsolete)")
1063 ("dl" . "Definition list")
1064 ("dt" . "Term to be definined")
1065 ("em" . "Emphasised")
1066 ("embed" . "Embedded data in foreign format")
1067 ("fig" . "Figure")
1068 ("figa" . "Figure anchor")
1069 ("figd" . "Figure description")
1070 ("figt" . "Figure text")
1071 ;("fn" . "?") ; ???
1072 ("font" . "Font size")
1073 ("form" . "Form with input fields")
1074 ("group" . "Document grouping")
1075 ("h1" . "Most important section headline")
1076 ("h2" . "Important section headline")
1077 ("h3" . "Section headline")
1078 ("h4" . "Minor section headline")
1079 ("h5" . "Unimportant section headline")
1080 ("h6" . "Least important section headline")
1081 ("head" . "Document header")
1082 ("hr" . "Horizontal rule")
1083 ("html" . "HTML Document")
1084 ("i" . "Italic face")
1085 ("img" . "Graphic image")
1086 ("input" . "Form input field")
1087 ("ins" . "?")
1088 ("isindex" . "Input field for index search")
1089 ("kbd" . "Keybard example face")
1090 ("lang" . "Natural language")
1091 ("li" . "List item")
1092 ("link" . "Link relationship")
1093 ("math" . "Math formula")
1094 ("menu" . "Menu list (obsolete)")
1095 ("mh" . "Form mail header")
1096 ("nextid" . "Allocate new id")
1097 ("nobr" . "Text without line break")
1098 ("ol" . "Ordered list")
1099 ("option" . "Selection list item")
1100 ("over" . "Math fraction rule")
1101 ("p" . "Paragraph start")
1102 ("panel" . "Floating panel")
1103 ("person" . "?")
1104 ("pre" . "Preformatted fixed width text")
1105 ("q" . "?")
1106 ("rev" . "Reverse video")
1107 ("s" . "?")
1108 ("samp" . "Sample text")
1109 ("select" . "Selection list")
1110 ("small" . "Font size")
1111 ("sp" . "Nobreak space")
1112 ("strong" . "Standout text")
1113 ("sub" . "Subscript")
1114 ("sup" . "Superscript")
1115 ("table" . "Table with rows and columns")
1116 ("tb" . "Table vertical break")
1117 ("td" . "Table data cell")
1118 ("textarea" . "Form multiline edit area")
1119 ("th" . "Table header cell")
1120 ("title" . "Document title")
1121 ("tr" . "Table row separator")
1122 ("tt" . "Typewriter face")
1123 ("u" . "Underlined text")
1124 ("ul" . "Unordered list")
1125 ("var" . "Math variable face")
1126 ("wbr" . "Enable <br> within <nobr>"))
1127 "*Value of `sgml-tag-help' for HTML mode.")
1128
1129
1130
1131 ;;;###autoload
1132 (defun html-mode ()
1133 "Major mode based on SGML mode for editing HTML documents.
1134 This allows inserting skeleton costructs used in hypertext documents with
1135 completion. See below for an introduction to HTML. Use
1136 \\[browse-url-of-buffer] to see how this comes out. See also `sgml-mode' on
1137 which this is based.
1138
1139 Do \\[describe-variable] html- SPC and \\[describe-variable] sgml- SPC to see available variables.
1140
1141 To write fairly well formatted pages you only need to know few things. Most
1142 browsers have a function to read the source code of the page being seen, so
1143 you can imitate various tricks. Here's a very short HTML primer which you
1144 can also view with a browser to see what happens:
1145
1146 <title>A Title Describing Contents</title> should be on every page. Pages can
1147 have <h1>Very Major Headlines</h1> through <h6>Very Minor Headlines</h6>
1148 <hr> Parts can be separated with horizontal rules.
1149
1150 <p>Paragraphs only need an opening tag. Line breaks and multiple spaces are
1151 ignored unless the text is <pre>preformatted.</pre> Text can be marked as
1152 <b>bold</b>, <i>italic</i> or <u>underlined</u> using the normal M-g or
1153 Edit/Text Properties/Face commands.
1154
1155 Pages can have <a name=\"SOMENAME\">named points</a> and can link other points
1156 to them with <a href=\"#SOMENAME\">see also somename</a>. In the same way <a
1157 href=\"URL\">see also URL</a> where URL is a filename relative to current
1158 directory, or absolute as in `http://www.cs.indiana.edu/elisp/w3/docs.html'.
1159
1160 Images in many formats can be inlined with <img src=\"URL\">.
1161
1162 If you mainly create your own documents, `sgml-specials' might be
1163 interesting. But note that some HTML 2 browsers can't handle `&apos;'.
1164 To work around that, do:
1165 (eval-after-load \"sgml-mode\" '(aset sgml-char-names ?' nil))
1166
1167 \\{html-mode-map}"
1168 (interactive)
1169 (sgml-mode-common html-tag-face-alist html-display-text)
1170 (use-local-map html-mode-map)
1171 (make-local-variable 'sgml-tag-alist)
1172 (make-local-variable 'sgml-face-tag-alist)
1173 (make-local-variable 'sgml-tag-help)
1174 (make-local-variable 'outline-regexp)
1175 (make-local-variable 'outline-heading-end-regexp)
1176 (make-local-variable 'outline-level)
1177 (make-local-variable 'sentence-end)
1178 (setq sentence-end
1179 "[.?!][]\"')}]*\\(<[^>]*>\\)*\\($\\| $\\|\t\\| \\)[ \t\n]*")
1180 (setq mode-name "HTML"
1181 major-mode 'html-mode
1182 sgml-tag-alist html-tag-alist
1183 sgml-face-tag-alist html-face-tag-alist
1184 sgml-tag-help html-tag-help
1185 outline-regexp "^.*<[Hh][1-6]\\>"
1186 outline-heading-end-regexp "</[Hh][1-6]>"
1187 outline-level (lambda ()
1188 (char-after (1- (match-end 0)))))
1189 (run-hooks 'html-mode-hook))
1190
1191
1192 (define-skeleton html-href-anchor
1193 "HTML anchor tag with href attribute."
1194 "URL: "
1195 '(setq input "http:")
1196 "<a href=\"" str "\">" _ "</a>")
1197
1198 (define-skeleton html-name-anchor
1199 "HTML anchor tag with name attribute."
1200 "Name: "
1201 "<a name=\"" str "\">" _ "</a>")
1202
1203 (define-skeleton html-headline-1
1204 "HTML level 1 headline tags."
1205 nil
1206 "<h1>" _ "</h1>")
1207
1208 (define-skeleton html-headline-2
1209 "HTML level 2 headline tags."
1210 nil
1211 "<h2>" _ "</h2>")
1212
1213 (define-skeleton html-headline-3
1214 "HTML level 3 headline tags."
1215 nil
1216 "<h3>" _ "</h3>")
1217
1218 (define-skeleton html-headline-4
1219 "HTML level 4 headline tags."
1220 nil
1221 "<h4>" _ "</h4>")
1222
1223 (define-skeleton html-headline-5
1224 "HTML level 5 headline tags."
1225 nil
1226 "<h5>" _ "</h5>")
1227
1228 (define-skeleton html-headline-6
1229 "HTML level 6 headline tags."
1230 nil
1231 "<h6>" _ "</h6>")
1232
1233 (define-skeleton html-horizontal-rule
1234 "HTML horizontal rule tag."
1235 nil
1236 "<hr>" \n)
1237
1238 (define-skeleton html-image
1239 "HTML image tag."
1240 nil
1241 "<img src=\"" _ "\">")
1242
1243 (define-skeleton html-line
1244 "HTML line break tag."
1245 nil
1246 "<br>" \n)
1247
1248 (define-skeleton html-ordered-list
1249 "HTML ordered list tags."
1250 nil
1251 "<ol>" \n
1252 "<li>" _ \n
1253 "</ol>")
1254
1255 (define-skeleton html-unordered-list
1256 "HTML unordered list tags."
1257 nil
1258 "<ul>" \n
1259 "<li>" _ \n
1260 "</ul>")
1261
1262 (define-skeleton html-list-item
1263 "HTML list item tag."
1264 nil
1265 (if (bolp) nil '\n)
1266 "<li>")
1267
1268 (define-skeleton html-paragraph
1269 "HTML paragraph tag."
1270 nil
1271 (if (bolp) nil ?\n)
1272 \n "<p>")
1273
1274 (define-skeleton html-checkboxes
1275 "Group of connected checkbox inputs."
1276 nil
1277 '(setq v1 nil
1278 v2 nil)
1279 ("Value: "
1280 "<input type=\"" (identity "checkbox") ; see comment above about identity
1281 "\" name=\"" (or v1 (setq v1 (skeleton-read "Name: ")))
1282 "\" value=\"" str ?\"
1283 (if (y-or-n-p "Set \"checked\" attribute? ")
1284 (funcall skeleton-transformation " checked")) ">"
1285 (skeleton-read "Text: " (capitalize str))
1286 (or v2 (setq v2 (if (y-or-n-p "Newline after text? ")
1287 (funcall skeleton-transformation "<br>")
1288 "")))
1289 \n))
1290
1291 (define-skeleton html-radio-buttons
1292 "Group of connected radio button inputs."
1293 nil
1294 '(setq v1 nil
1295 v2 (cons nil nil))
1296 ("Value: "
1297 "<input type=\"" (identity "radio") ; see comment above about identity
1298 "\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: ")))
1299 "\" value=\"" str ?\"
1300 (if (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? ")))
1301 (funcall skeleton-transformation " checked") ">")
1302 (skeleton-read "Text: " (capitalize str))
1303 (or (cdr v2) (setcdr v2 (if (y-or-n-p "Newline after text? ")
1304 (funcall skeleton-transformation "<br>")
1305 "")))
1306 \n))
1307
1308
1309 (defun html-autoview-mode (&optional arg)
1310 "Toggle automatic viewing via `html-viewer' upon saving buffer.
1311 With positive prefix ARG always turns viewing on, with negative ARG always off.
1312 Can be used as a value for `html-mode-hook'."
1313 (interactive "P")
1314 (if (setq arg (if arg
1315 (< (prefix-numeric-value arg) 0)
1316 (and (boundp 'after-save-hook)
1317 (memq 'browse-url-of-buffer after-save-hook))))
1318 (setq after-save-hook (delq 'browse-url-of-buffer after-save-hook))
1319 (make-local-hook 'after-save-hook)
1320 (add-hook 'after-save-hook 'browse-url-of-buffer nil t))
1321 (message "Autoviewing turned %s."
1322 (if arg "off" "on")))
1323
1324 ;;; sgml-mode.el ends here