(server-process-filter): Pass proper format string to message.
[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
1bd60093 5;; Author: James Clark <jjc@clark.com>
1caf38eb
RS
6;; Adapted-By: ESR; Daniel.Pfeiffer@Informatik.START.dbp.de
7;; Keywords: wp, hypermedia, comm, languages
72c0ae01 8
72c0ae01
ER
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
7c938215 13;; the Free Software Foundation; either version 2, or (at your option)
72c0ae01
ER
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
b578f267
EN
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.
72c0ae01
ER
25
26;;; Commentary:
27
1caf38eb
RS
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.
72c0ae01
ER
31
32;;; Code:
33
1caf38eb
RS
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.
39This list is used when first loading the sgml-mode library.
40The 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
46When only one of ?\\\" or ?' are included, \"'\" or '\"' as it can be found in
47DTDs, start a string. To partially avoid this problem this also makes these
fcc3195e
RS
48self insert as named entities depending on `sgml-quick-keys'. <!----> must
49contain an even multiple of two (4, 8, ...) minuses, or Emacs' syntax
50mechanism won't recognize a comment.")
51
52(defvar sgml-quick-keys nil
53 "Use <, >, &, SPC and `sgml-specials' keys ``electrically'' when non-nil.
54This takes effect when first loading the library.")
1caf38eb
RS
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)
fcc3195e
RS
63 (define-key map "\C-c\C-n" 'sgml-name-char)
64 (define-key map "\C-c\C-t" 'sgml-tag)
1caf38eb
RS
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)
1caf38eb
RS
73 (define-key map "\C-c8" 'sgml-name-8bit-mode)
74 (define-key map "\C-c\C-v" 'sgml-validate)
fcc3195e
RS
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))))
1caf38eb
RS
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
72c0ae01 123
1caf38eb
RS
124(defvar sgml-name-8bit-mode nil
125 "*When non-`nil' insert 8 bit characters with their names.")
72c0ae01 126
1caf38eb
RS
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"
72c0ae01
ER
169 "*The command to validate an SGML document.
170The file name of current buffer file name will be appended to this,
171separated by a space.")
172
173(defvar sgml-saved-validate-command nil
174 "The command last used to validate in this buffer.")
175
72c0ae01 176
1caf38eb
RS
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 /.")
72c0ae01 181
1caf38eb
RS
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.
185Any 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.
202When `font-lock-maximum-decoration' is 1 this is always used for fontifying.
203When 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
fcc3195e
RS
214 '(("![" ("ignore" t) ("include" t))
215 ("!attlist")
1caf38eb
RS
216 ("!doctype")
217 ("!element")
218 ("!entity"))
219 "*Alist of tag names for completing read and insertion rules.
220This alist is made up as
221
222 ((\"tag\" . TAGRULE)
223 ...)
224
225TAGRULE is a list of optionally `t' (no endtag) or `\\n' (separate endtag by
226newlines) or a skeleton with `nil', `t' or `\\n' in place of the interactor
227followed by an ATTRIBUTERULE (for an always present attribute) or an
228attribute alist.
229
230The attribute alist is made up as
231
232 ((\"attribute\" . ATTRIBUTERULE)
233 ...)
234
235ATTRIBUTERULE is a list of optionally `t' (no value when no input) followed by
236an 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
1caf38eb
RS
258
259(defun sgml-mode-common (sgml-tag-face-alist sgml-display-text)
260 "Common code for setting up `sgml-mode' and derived modes.
261SGML-TAG-FACE-ALIST is used for calculating `sgml-font-lock-keywords-1'.
262SGML-DISPLAY-TEXT sets up alternate text for when tags are invisible (see
263varables of same name)."
72c0ae01
ER
264 (kill-all-local-variables)
265 (setq local-abbrev-table text-mode-abbrev-table)
1caf38eb
RS
266 (set-syntax-table sgml-mode-syntax-table)
267 (make-local-variable 'indent-line-function)
72c0ae01 268 (make-local-variable 'paragraph-start)
72c0ae01 269 (make-local-variable 'paragraph-separate)
72c0ae01 270 (make-local-variable 'sgml-saved-validate-command)
72c0ae01 271 (make-local-variable 'comment-start)
72c0ae01 272 (make-local-variable 'comment-end)
e41b2db1 273 (make-local-variable 'comment-indent-function)
72c0ae01 274 (make-local-variable 'comment-start-skip)
1caf38eb
RS
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)))
72c0ae01
ER
329 (run-hooks 'text-mode-hook 'sgml-mode-hook))
330
1caf38eb
RS
331
332;;;###autoload
333(defun sgml-mode (&optional function)
334 "Major mode for editing SGML documents.
335Makes > match <. Makes / blink matching /.
fcc3195e
RS
336Keys <, &, SPC within <>, \" and ' can be electric depending on
337`sgml-quick-keys'.
1caf38eb
RS
338
339Do \\[describe-variable] sgml- SPC to see available variables.
340
341Use \\[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
72c0ae01
ER
351(defun sgml-comment-indent ()
352 (if (and (looking-at "--")
1caf38eb 353 (not (and (eq (preceding-char) ?!)
72c0ae01
ER
354 (eq (char-after (- (point) 2)) ?<))))
355 (progn
356 (skip-chars-backward " \t")
357 (max comment-column (1+ (current-column))))
358 0))
359
72c0ae01 360
72c0ae01
ER
361
362(defun sgml-slash (arg)
363 "Insert / and display any previous matching /.
364Two /s are treated as matching if the first / ends a net-enabling
365start 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
1caf38eb
RS
405
406(defun sgml-name-char (&optional char)
407 "Insert a symbolic character name according to `sgml-char-names'.
4088 bit chars may be inserted with the meta key as in M-SPC for no break space,
409or 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.
447Completion and configuration is according to `sgml-tag-alist'.
448If you like tags and attributes in uppercase set `skeleton-transformation'
449to `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)) ?>
fcc3195e
RS
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 ?>))))))))
1caf38eb
RS
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.
fcc3195e 507With prefix ARG only self insert."
1caf38eb
RS
508 (interactive "*P")
509 (let ((point (point))
510 tag)
511 (if (or arg
1caf38eb
RS
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 (or (cdr (assoc tag sgml-tag-help))
534 (and (eq (aref tag 0) ?/)
535 (cdr (assoc (substring tag 1) sgml-tag-help)))
536 "No description available")))
537
538
539(defun sgml-maybe-end-tag ()
540 "Name self unless in position to end a tag."
541 (interactive)
542 (or (condition-case nil
543 (save-excursion (up-list -1))
544 (error
545 (sgml-name-self)
546 t))
547 (condition-case nil
548 (progn
549 (save-excursion (up-list 1))
550 (sgml-name-self))
551 (error (self-insert-command 1)))))
552
553
554(defun sgml-skip-tag-backward (arg)
555 "Skip to beginning of tag or matching opening tag if present.
556With prefix ARG, repeat that many times."
557 (interactive "p")
558 (while (>= arg 1)
559 (search-backward "<" nil t)
560 (if (looking-at "</\\([^ \n\t>]+\\)")
561 ;; end tag, skip any nested pairs
562 (let ((case-fold-search t)
563 (re (concat "</?" (regexp-quote (match-string 1)))))
564 (while (and (re-search-backward re nil t)
565 (eq (char-after (1+ (point))) ?/))
566 (forward-char 1)
567 (sgml-skip-tag-backward 1))))
568 (setq arg (1- arg))))
569
570(defun sgml-skip-tag-forward (arg &optional return)
571 "Skip to end of tag or matching closing tag if present.
572With prefix ARG, repeat that many times.
573Return t iff after a closing tag."
574 (interactive "p")
575 (setq return t)
576 (while (>= arg 1)
577 (skip-chars-forward "^<>")
578 (if (eq (following-char) ?>)
579 (up-list -1))
580 (if (looking-at "<\\([^/ \n\t>]+\\)")
581 ;; start tag, skip any nested same pairs _and_ closing tag
582 (let ((case-fold-search t)
583 (re (concat "</?" (regexp-quote (match-string 1))))
584 point close)
585 (forward-list 1)
586 (setq point (point))
587 (while (and (re-search-forward re nil t)
588 (not (setq close
589 (eq (char-after (1+ (match-beginning 0))) ?/)))
590 (not (up-list -1))
591 (sgml-skip-tag-forward 1))
592 (setq close nil))
593 (if close
594 (up-list 1)
595 (goto-char point)
596 (setq return)))
597 (forward-list 1))
598 (setq arg (1- arg)))
599 return)
600
601(defun sgml-delete-tag (arg)
602 "Delete tag on or after cursor, and matching closing or opening tag.
603With prefix ARG, repeat that many times."
604 (interactive "p")
605 (while (>= arg 1)
606 (save-excursion
607 (let* (close open)
fcc3195e 608 (if (looking-at "[ \t\n]*<")
1caf38eb
RS
609 ;; just before tag
610 (if (eq (char-after (match-end 0)) ?/)
611 ;; closing tag
612 (progn
613 (setq close (point))
614 (goto-char (match-end 0))))
615 ;; on tag?
616 (or (save-excursion (setq close (sgml-beginning-of-tag)
617 close (and (stringp close)
618 (eq (aref close 0) ?/)
619 (point))))
620 ;; not on closing tag
621 (let ((point (point)))
622 (sgml-skip-tag-backward 1)
623 (if (or (not (eq (following-char) ?<))
624 (save-excursion
625 (forward-list 1)
626 (<= (point) point)))
627 (error "Not on or before tag")))))
628 (if close
629 (progn
630 (sgml-skip-tag-backward 1)
631 (setq open (point))
632 (goto-char close)
633 (kill-sexp 1))
634 (setq open (point))
635 (sgml-skip-tag-forward 1)
636 (backward-list)
637 (forward-char)
638 (if (eq (aref (sgml-beginning-of-tag) 0) ?/)
639 (kill-sexp 1)))
640 (goto-char open)
641 (kill-sexp 1)))
642 (setq arg (1- arg))))
643
644
645
646(defun sgml-tags-invisible (arg)
647 "Toggle visibility of existing tags."
648 (interactive "P")
649 (let ((modified (buffer-modified-p))
650 (inhibit-read-only t)
651 (point (point-min))
652 symbol)
653 (save-excursion
654 (goto-char point)
655 (if (setq sgml-tags-invisible
656 (if arg
657 (>= (prefix-numeric-value arg) 0)
658 (not sgml-tags-invisible)))
659 (while (re-search-forward "<\\([!/?A-Za-z][-A-Za-z0-9]*\\)"
660 nil t)
661 (setq symbol (intern-soft (downcase (match-string 1))))
662 (goto-char (match-beginning 0))
663 (and (get symbol 'before-string)
664 (not (overlays-at (point)))
665 (overlay-put (make-overlay (point)
666 (match-beginning 1))
667 'category symbol))
668 (put-text-property (setq point (point)) (forward-list)
669 'intangible (point))
670 (put-text-property point (point)
671 'category 'sgml-tag))
672 (while (< (setq point (next-overlay-change point)) (point-max))
673 (delete-overlay (car (overlays-at point))))
674 (remove-text-properties (point-min) (point-max)
675 '(category sgml-tag intangible t))))
676 (set-buffer-modified-p modified)
677 (run-hooks 'sgml-tags-invisible-hook)
678 (message "")))
679
680(defun sgml-point-entered (x y)
681 ;; Show preceding or following hidden tag, depending of cursor direction.
682 (let ((inhibit-point-motion-hooks t))
683 (save-excursion
684 (message "Invisible tag: %s"
685 (buffer-substring
686 (point)
687 (if (or (and (> x y)
688 (not (eq (following-char) ?<)))
689 (and (< x y)
690 (eq (preceding-char) ?>)))
691 (backward-list)
692 (forward-list)))))))
693
694
695(autoload 'compile-internal "compile")
696
72c0ae01
ER
697(defun sgml-validate (command)
698 "Validate an SGML document.
699Runs COMMAND, a shell command, in a separate process asynchronously
700with output going to the buffer *compilation*.
701You can then use the command \\[next-error] to find the next error message
702and move to the line in the SGML document that caused it."
703 (interactive
704 (list (read-string "Validate command: "
705 (or sgml-saved-validate-command
706 (concat sgml-validate-command
707 " "
708 (let ((name (buffer-file-name)))
709 (and name
710 (file-name-nondirectory name))))))))
711 (setq sgml-saved-validate-command command)
c7aa4667 712 (compile-internal command "No more errors"))
72c0ae01 713
1caf38eb
RS
714
715(defun sgml-beginning-of-tag (&optional top-level)
716 "Skip to beginning of tag and return its name.
717Else `t'."
718 (or (if top-level
719 (condition-case nil
720 (up-list -1)
721 (error t))
722 (>= (point)
723 (if (search-backward "<" nil t)
724 (save-excursion
725 (forward-list)
726 (point))
727 0)))
728 (if (looking-at "<[!?/]?[[A-Za-z][A-Za-z0-9]*")
729 (buffer-substring-no-properties
730 (1+ (point))
731 (match-end 0))
732 t)))
733
734(defun sgml-value (alist)
735 (setq alist (cdr alist))
736 (if (stringp (car alist))
737 (insert "=\"" (car alist) ?\")
738 (if (eq (car alist) t)
739 (if (cdr alist)
740 (progn
741 (insert "=\"")
742 (setq alist (skeleton-read '(completing-read
743 "[Value]: " (cdr alist))))
744 (if (string< "" alist)
745 (insert (funcall skeleton-transformation alist) ?\")
746 (delete-backward-char 2))))
747 (insert "=\"")
748 (if alist
749 (insert (funcall skeleton-transformation
750 (skeleton-read '(completing-read "Value: " alist)))))
751 (insert ?\"))))
752
753(provide 'sgml-mode)
754\f
fcc3195e
RS
755(defvar html-quick-keys sgml-quick-keys
756 "Use C-c X combinations for quick insertion of frequent tags when non-nil.
757This defaults to `sgml-quick-keys'.
1caf38eb
RS
758This takes effect when first loading the library.")
759
760(defvar html-mode-map
761 (let ((map (nconc (make-sparse-keymap) sgml-mode-map))
762 (menu-map (make-sparse-keymap "HTML")))
fcc3195e
RS
763 (define-key map "\C-c6" 'html-headline)
764 (define-key map "\C-c5" 'html-headline)
765 (define-key map "\C-c4" 'html-headline)
766 (define-key map "\C-c3" 'html-headline)
767 (define-key map "\C-c2" 'html-headline)
768 (define-key map "\C-c1" 'html-headline)
769 (define-key map "\C-c\r" 'html-paragraph)
770 (define-key map "\C-c\n" 'html-line)
771 (define-key map "\C-c\C-c-" 'html-horizontal-rule)
772 (define-key map "\C-c\C-co" 'html-list)
773 (define-key map "\C-c\C-cu" 'html-list)
774 (define-key map "\C-c\C-cr" 'html-radio-buttons)
775 (define-key map "\C-c\C-cc" 'html-checkboxes)
776 (define-key map "\C-c\C-cl" 'html-list-item)
777 (define-key map "\C-c\C-ch" 'html-href-anchor)
778 (define-key map "\C-c\C-cn" 'html-name-anchor)
779 (define-key map "\C-c\C-ci" 'html-image)
1caf38eb
RS
780 (if html-quick-keys
781 (progn
1caf38eb 782 (define-key map "\C-c-" 'html-horizontal-rule)
1caf38eb
RS
783 (define-key map "\C-co" 'html-list)
784 (define-key map "\C-cu" 'html-list)
785 (define-key map "\C-cr" 'html-radio-buttons)
fcc3195e 786 (define-key map "\C-cc" 'html-checkboxes)
1caf38eb
RS
787 (define-key map "\C-cl" 'html-list-item)
788 (define-key map "\C-ch" 'html-href-anchor)
789 (define-key map "\C-cn" 'html-name-anchor)
790 (define-key map "\C-ci" 'html-image)))
791 (define-key map "\C-c\C-s" 'html-autoview-mode)
792 (define-key map "\C-c\C-v" 'browse-url-of-buffer)
793 (define-key map [menu-bar html] (cons "HTML" menu-map))
794 (define-key menu-map [html-autoview-mode]
795 '("Toggle Autoviewing" . html-autoview-mode))
796 (define-key menu-map [browse-url-of-buffer]
797 '("View Buffer Contents" . browse-url-of-buffer))
798 (define-key menu-map [nil] '("--"))
799 ;;(define-key menu-map "6" '("Heading 6" . html-headline))
800 ;;(define-key menu-map "5" '("Heading 5" . html-headline))
801 ;;(define-key menu-map "4" '("Heading 4" . html-headline))
802 (define-key menu-map "3" '("Heading 3" . html-headline))
803 (define-key menu-map "2" '("Heading 2" . html-headline))
804 (define-key menu-map "1" '("Heading 1" . html-headline))
805 (define-key menu-map "l" '("Radio Buttons" . html-radio-buttons))
fcc3195e 806 (define-key menu-map "c" '("Checkboxes" . html-checkboxes))
1caf38eb
RS
807 (define-key menu-map "l" '("List Item" . html-list-item))
808 (define-key menu-map "u" '("Unordered List" . html-list))
809 (define-key menu-map "o" '("Ordered List" . html-list))
fcc3195e 810 (define-key menu-map "-" '("Horizontal Rule" . html-horizontal-rule))
1caf38eb
RS
811 (define-key menu-map "\n" '("Line Break" . html-line))
812 (define-key menu-map "\r" '("Paragraph" . html-paragraph))
813 (define-key menu-map "i" '("Image" . html-image))
814 (define-key menu-map "h" '("Href Anchor" . html-href-anchor))
815 (define-key menu-map "n" '("Name Anchor" . html-name-anchor))
816 map)
817 "Keymap for commands for use in HTML mode.")
818
819
820(defvar html-face-tag-alist
821 '((bold . "b")
822 (italic . "i")
823 (underline . "u")
824 (modeline . "rev"))
825 "Value of `sgml-face-tag-alist' for HTML mode.")
826
827(defvar html-tag-face-alist
828 '(("b" . bold)
829 ("big" . bold)
830 ("blink" . highlight)
831 ("cite" . italic)
832 ("em" . italic)
833 ("h1" bold underline)
834 ("h2" bold-italic underline)
835 ("h3" italic underline)
836 ("h4" . underline)
837 ("h5" . underline)
838 ("h6" . underline)
839 ("i" . italic)
840 ("rev" . modeline)
841 ("s" . underline)
842 ("small" . default)
843 ("strong" . bold)
844 ("title" bold underline)
845 ("tt" . default)
846 ("u" . underline)
847 ("var" . italic))
848 "Value of `sgml-tag-face-alist' for HTML mode.")
849
850
851(defvar html-display-text
852 '((img . "[/]")
853 (hr . "----------")
854 (li . "o "))
855 "Value of `sgml-display-text' for HTML mode.")
856
857
858; should code exactly HTML 3 here when that is finished
859(defvar html-tag-alist
860 (let* ((1-9 '(("8") ("9")
861 ("1") ("2") ("3") ("4") ("5") ("6") ("7")))
862 (align '(("align" ("left") ("center") ("right"))))
863 (valign '(("top") ("middle") ("bottom") ("baseline")))
864 (rel '(("next") ("previous") ("parent") ("subdocument") ("made")))
865 (href '("href" ("ftp:") ("file:") ("finger:") ("gopher:") ("http:")
866 ("mailto:") ("news:") ("rlogin:") ("telnet:") ("tn3270:")
fcc3195e 867 ("wais:") ("/cgi-bin/")))
1caf38eb
RS
868 (name '("name"))
869 (link `(,href
870 ("rel" ,@rel)
871 ("rev" ,@rel)
872 ("title")))
873 (list '((nil \n
874 ( "List item: "
875 "<li>" str \n))
876 ("type" ("A") ("a") ("I") ("i") ("1"))))
877 (cell `(t
878 ,align
879 ("valign" ,@valign)
880 ("colspan" ,@1-9)
881 ("rowspan" ,@1-9)
882 ("nowrap" t))))
883 ;; put ,-expressions first, else byte-compile chokes (as of V19.29)
884 ;; and like this it's more efficient anyway
885 `(("a" ,name ,@link)
886 ("base" t ,@href)
887 ("dir" ,@list)
888 ("font" "size" ("-1") ("+1") ("-2") ("+2") ,@(cdr (cdr 1-9)))
fcc3195e
RS
889 ("form" (\n _ \n "<input type=\"submit\" value=\"\">")
890 ("action" ,@(cdr href)) ("method" ("get") ("post")))
1caf38eb
RS
891 ("h1" ,@align)
892 ("h2" ,@align)
893 ("h3" ,@align)
894 ("h4" ,@align)
895 ("h5" ,@align)
896 ("h6" ,@align)
897 ("hr" t ("size" ,@1-9) ("width") ("noshade" t) ,@align)
898 ("img" t ("align" ,@valign ("texttop") ("absmiddle") ("absbottom"))
899 ("src") ("alt") ("width" "1") ("height" "1")
900 ("border" "1") ("vspace" "1") ("hspace" "1") ("ismap" t))
901 ("input" t ("size" ,@1-9) ("maxlength" ,@1-9) ("checked" t) ,name
fcc3195e
RS
902 ("type" ("text") ("password") ("checkbox") ("radio")
903 ("submit") ("reset"))
1caf38eb
RS
904 ("value"))
905 ("link" t ,@link)
906 ("menu" ,@list)
907 ("ol" ,@list)
908 ("p" t ,@align)
909 ("select" (nil \n
910 ("Text: "
911 "<option>" str \n))
912 ,name ("size" ,@1-9) ("multiple" t))
913 ("table" (nil \n
914 ((completing-read "Cell kind: " '(("td") ("th"))
915 nil t "t")
916 "<tr><" str ?> _ \n))
917 ("border" t ,@1-9) ("width" "10") ("cellpadding"))
918 ("td" ,@cell)
919 ("textarea" ,name ("rows" ,@1-9) ("cols" ,@1-9))
920 ("th" ,@cell)
921 ("ul" ,@list)
922
923 ,@sgml-tag-alist
924
925 ("abbrev")
926 ("acronym")
927 ("address")
928 ("array" (nil \n
929 ("Item: " "<item>" str \n))
930 "align")
931 ("au")
932 ("b")
933 ("big")
934 ("blink")
935 ("blockquote" \n)
936 ("body" \n ("background" ".gif") ("bgcolor" "#") ("text" "#")
937 ("link" "#") ("alink" "#") ("vlink" "#"))
938 ("box" (nil _ "<over>" _))
939 ("br" t ("clear" ("left") ("right")))
940 ("caption" ("valign" ("top") ("bottom")))
941 ("center" \n)
942 ("cite")
943 ("code" \n)
944 ("dd" t)
945 ("del")
946 ("dfn")
947 ("dl" (nil \n
948 ( "Term: "
949 "<dt>" str "<dd>" _ \n)))
950 ("dt" (t _ "<dd>"))
951 ("em")
952 ("fn" "id" "fn")
953 ("head" \n)
954 ("html" (\n
955 "<head>\n"
956 "<title>" (setq str (read-input "Title: ")) "</title>\n"
957 "<body>\n<h1>" str "</h1>\n" _
958 "\n<address>\n<a href=\"mailto:"
959 (user-login-name) ?@ (system-name)
960 "\">" (user-full-name) "</a>\n</address>"))
961 ("i")
962 ("ins")
963 ("isindex" t ("action") ("prompt"))
964 ("kbd")
965 ("lang")
966 ("li" t)
967 ("math" \n)
968 ("nobr")
969 ("option" t ("value") ("label") ("selected" t))
970 ("over" t)
971 ("person")
972 ("pre" \n)
973 ("q")
974 ("rev")
975 ("s")
976 ("samp")
977 ("small")
978 ("strong")
979 ("sub")
980 ("sup")
981 ("title")
982 ("tr" t)
983 ("tt")
984 ("u")
985 ("var")
986 ("wbr" t)))
987 "*Value of `sgml-tag-alist' for HTML mode.")
988
989(defvar html-tag-help
990 `(,@sgml-tag-help
991 ("a" . "Anchor of point or link elsewhere")
992 ("abbrev" . "?")
993 ("acronym" . "?")
994 ("address" . "Formatted mail address")
995 ("array" . "Math array")
996 ("au" . "?")
997 ("b" . "Bold face")
998 ("base" . "Base address for URLs")
999 ("big" . "Font size")
1000 ("blink" . "Blinking text")
1001 ("blockquote" . "Indented quotation")
1002 ("body" . "Document body")
1003 ("box" . "Math fraction")
1004 ("br" . "Line break")
1005 ("caption" . "Table caption")
1006 ("center" . "Centered text")
1007 ("changed" . "Change bars")
1008 ("cite" . "Citation of a document")
1009 ("code" . "Formatted source code")
1010 ("dd" . "Definition of term")
1011 ("del" . "?")
1012 ("dfn" . "?")
1013 ("dir" . "Directory list (obsolete)")
1014 ("dl" . "Definition list")
1015 ("dt" . "Term to be definined")
1016 ("em" . "Emphasised")
1017 ("embed" . "Embedded data in foreign format")
1018 ("fig" . "Figure")
1019 ("figa" . "Figure anchor")
1020 ("figd" . "Figure description")
1021 ("figt" . "Figure text")
1022 ("fn" . "?")
1023 ("font" . "Font size")
1024 ("form" . "Form with input fields")
1025 ("group" . "Document grouping")
1026 ("h1" . "Most important section headline")
1027 ("h2" . "Important section headline")
1028 ("h3" . "Section headline")
1029 ("h4" . "Minor section headline")
1030 ("h5" . "Unimportant section headline")
1031 ("h6" . "Least important section headline")
1032 ("head" . "Document header")
1033 ("hr" . "Horizontal rule")
1034 ("html" . "HTML Document")
1035 ("i" . "Italic face")
1036 ("img" . "Graphic image")
1037 ("input" . "Form input field")
1038 ("ins" . "?")
1039 ("isindex" . "Input field for index search")
1040 ("kbd" . "Keybard example face")
1041 ("lang" . "Natural language")
1042 ("li" . "List item")
1043 ("link" . "Link relationship")
1044 ("math" . "Math formula")
1045 ("menu" . "Menu list (obsolete)")
1046 ("mh" . "Form mail header")
1047 ("nextid" . "Allocate new id")
1048 ("nobr" . "Text without line break")
1049 ("ol" . "Ordered list")
1050 ("option" . "Selection list item")
1051 ("over" . "Math fraction rule")
1052 ("p" . "Paragraph start")
1053 ("panel" . "Floating panel")
1054 ("person" . "?")
1055 ("pre" . "Preformatted fixed width text")
1056 ("q" . "?")
1057 ("rev" . "Reverse video")
1058 ("s" . "?")
1059 ("samp" . "Sample text")
1060 ("select" . "Selection list")
1061 ("small" . "Font size")
1062 ("sp" . "Nobreak space")
1063 ("strong" . "Standout text")
1064 ("sub" . "Subscript")
1065 ("sup" . "Superscript")
1066 ("table" . "Table with rows and columns")
1067 ("tb" . "Table vertical break")
1068 ("td" . "Table data cell")
1069 ("textarea" . "Form multiline edit area")
1070 ("th" . "Table header cell")
1071 ("title" . "Document title")
1072 ("tr" . "Table row separator")
1073 ("tt" . "Typewriter face")
1074 ("u" . "Underlined text")
1075 ("ul" . "Unordered list")
1076 ("var" . "Math variable face")
1077 ("wbr" . "Enable <br> within <nobr>"))
1078"*Value of `sgml-tag-help' for HTML mode.")
1079
1080
1081
1082;;;###autoload
1083(defun html-mode ()
1084 "Major mode based on SGML mode for editing HTML documents.
fcc3195e
RS
1085This allows inserting skeleton costructs used in hypertext documents with
1086completion. See below for an introduction to HTML. Use
1087\\[browse-url-of-buffer] to see how this comes out. See also `sgml-mode' on
1088which this is based.
1caf38eb 1089
fcc3195e 1090Do \\[describe-variable] html- SPC and \\[describe-variable] sgml- SPC to see available variables.
1caf38eb
RS
1091
1092To write fairly well formatted pages you only need to know few things. Most
1093browsers have a function to read the source code of the page being seen, so
1094you can imitate various tricks. Here's a very short HTML primer which you
1095can also view with a browser to see what happens:
1096
1097<title>A Title Describing Contents</title> should be on every page. Pages can
1098have <h1>Very Major Headlines</h1> through <h6>Very Minor Headlines</h6>
1099<hr> Parts can be separated with horizontal rules.
1100
1101<p>Paragraphs only need an opening tag. Line breaks and multiple spaces are
1102ignored unless the text is <pre>preformatted.</pre> Text can be marked as
1103<b>bold</b>, <i>italic</i> or <u>underlined</u> using the normal M-g or
1104Edit/Text Properties/Face commands.
1105
1106Pages can have <a name=\"SOMENAME\">named points</a> and can link other points
1107to them with <a href=\"#SOMENAME\">see also somename</a>. In the same way <a
1108href=\"URL\">see also URL</a> where URL is a filename relative to current
1109directory or something like http://www.cs.indiana.edu/elisp/w3/docs.html.
1110
1111Images in many formats can be inlined with <img src=\"URL\">.
1112
1113If you mainly create your own documents, `sgml-specials' might be interesting.
1114But note that some HTML 2 browsers can't handle &apos;. To work around that
1115do:
1116
1117\(eval-after-load \"sgml-mode\" '(aset sgml-char-names ?' nil))
1118\\{html-mode-map}"
1119 (interactive)
1120 (sgml-mode-common html-tag-face-alist html-display-text)
1121 (use-local-map html-mode-map)
1122 (make-local-variable 'sgml-tag-alist)
1123 (make-local-variable 'sgml-face-tag-alist)
1124 (make-local-variable 'sgml-tag-help)
1125 (make-local-variable 'outline-regexp)
1126 (make-local-variable 'outline-heading-end-regexp)
1127 (make-local-variable 'outline-level)
1128 (setq mode-name "HTML"
1129 major-mode 'html-mode
1130 sgml-tag-alist html-tag-alist
1131 sgml-face-tag-alist html-face-tag-alist
1132 sgml-tag-help html-tag-help
1133 outline-regexp "^.*<[Hh][1-6]\\>"
1134 outline-heading-end-regexp "</[Hh][1-6]>"
1135 outline-level (lambda ()
1136 (char-after (1- (match-end 0)))))
1137 (run-hooks 'html-mode-hook))
1138
1139
1140(define-skeleton html-href-anchor
1141 "HTML anchor tag with href attribute."
1142 nil
1143 "<a href=\"http:" _ "\"></a>")
1144
1145(define-skeleton html-name-anchor
1146 "HTML anchor tag with name attribute."
1147 nil
1148 "<a name=\"" _ "\"></a>")
1149
1150(define-skeleton html-headline
1151 "HTML headline tags."
1152 last-command-char
1153 "<h" str ?> _ "</h" str ?>)
1154
1155(define-skeleton html-horizontal-rule
1156 "HTML horizontal rule tag."
1157 nil
1158 "<hr>" \n)
1159
1160(define-skeleton html-image
1161 "HTML image tag."
1162 nil
1163 "<img src=\"http:" _ "\">")
1164
1165(define-skeleton html-line
1166 "HTML line break tag."
1167 nil
1168 "<br>" \n)
1169
1170(define-skeleton html-list
1171 "HTML unordered/ordered list tags."
1172 last-command-char
1173 ?< str "l>" \n
1174 "<li>" _ \n
1175 "</" str "l>")
1176
1177(define-skeleton html-list-item
1178 "HTML list item tag."
1179 nil
1180 (if (bolp) nil '\n)
1181 "<li>")
1182
1183(define-skeleton html-paragraph
1184 "HTML paragraph tag."
1185 nil
1186 (if (bolp) nil ?\n)
1187 \n "<p>")
1188
fcc3195e
RS
1189(define-skeleton html-checkboxes
1190 "Group of connected checkbox inputs."
1191 nil
1192 '(setq v1 (eval str)) ; allow passing name as argument
1193 ("Value & Text: "
1194 "<input type=\"checkbox\" name=\""
1195 (or v1 (setq v1 (skeleton-read "Name: ")))
1196 "\" value=\"" str ?\"
1197 (if v2 "" " checked") ?> str
1198 (or v2 (setq v2 (if (y-or-n-p "Newline? ") "<br>" ""))) \n))
1199
1caf38eb
RS
1200(define-skeleton html-radio-buttons
1201 "Group of connected radio button inputs."
1202 nil
1203 '(setq v1 (eval str)) ; allow passing name as argument
1204 ("Value & Text: "
1205 "<input type=\"radio\" name=\""
1206 (or v1 (setq v1 (skeleton-read "Name: ")))
1207 "\" value=\"" str ?\"
1208 (if v2 "" " checked") ?> str
1209 (or v2 (setq v2 (if (y-or-n-p "Newline? ") "<br>" ""))) \n))
1210
1211
1212(defun html-autoview-mode (&optional arg)
1213 "Toggle automatic viewing via `html-viewer' upon saving buffer.
1214With positive prefix ARG always turns viewing on, with negative ARG always off.
1215Can be used as a value for `html-mode-hook'."
1216 (interactive "P")
1217 (if (setq arg (if arg
1218 (< (prefix-numeric-value arg) 0)
1219 (and (boundp 'after-save-hook)
1220 (memq 'browse-url-of-buffer after-save-hook))))
1221 (setq after-save-hook (delq 'browse-url-of-buffer after-save-hook))
1222 (make-local-hook 'after-save-hook)
1223 (add-hook 'after-save-hook 'browse-url-of-buffer nil t))
1224 (message "Autoviewing turned %s."
1225 (if arg "off" "on")))
1226
72c0ae01 1227;;; sgml-mode.el ends here