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