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