1 ;;; sgml-mode.el --- SGML- and HTML-editing modes
3 ;; Copyright (C) 1992, 1995, 1996, 1998, 2001, 2002, 2003, 2004, 2005
4 ;; Free Software Foundation, Inc.
6 ;; Author: James Clark <jjc@jclark.com>
8 ;; Adapted-By: ESR, Daniel Pfeiffer <occitan@esperanto.org>,
9 ;; F.Potorti@cnuce.cnr.it
10 ;; Keywords: wp, hypermedia, comm, languages
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; Configurable major mode for editing document in the SGML standard general
32 ;; markup language. As an example contains a mode for editing the derived
33 ;; HTML hypertext markup language.
46 (defcustom sgml-basic-offset
2
47 "*Specifies the basic indentation level for `sgml-indent-line'."
51 (defcustom sgml-transformation
'identity
52 "*Default value for `skeleton-transformation' (which see) in SGML mode."
56 (put 'sgml-transformation
'variable-interactive
57 "aTransformation function: ")
59 (defcustom sgml-mode-hook nil
60 "Hook run by command `sgml-mode'.
61 `text-mode-hook' is run first."
65 ;; As long as Emacs' syntax can't be complemented with predicates to context
66 ;; sensitively confirm the syntax of characters, we have to live with this
67 ;; kludgy kind of tradeoff.
68 (defvar sgml-specials
'(?
\")
69 "List of characters that have a special meaning for SGML mode.
70 This list is used when first loading the `sgml-mode' library.
71 The supported characters and potential disadvantages are:
73 ?\\\" Makes \" in text start a string.
74 ?' Makes ' in text start a string.
75 ?- Makes -- in text start a comment.
77 When only one of ?\\\" or ?' are included, \"'\" or '\"', as can be found in
78 DTDs, start a string. To partially avoid this problem this also makes these
79 self insert as named entities depending on `sgml-quick-keys'.
81 Including ?- has the problem of affecting dashes that have nothing to do
82 with comments, so we normally turn it off.")
84 (defvar sgml-quick-keys nil
85 "Use <, >, &, /, SPC and `sgml-specials' keys \"electrically\" when non-nil.
86 This takes effect when first loading the `sgml-mode' library.")
89 (let ((map (make-keymap)) ;`sparse' doesn't allow binding to charsets.
90 (menu-map (make-sparse-keymap "SGML")))
91 (define-key map
"\C-c\C-i" 'sgml-tags-invisible
)
92 (define-key map
"/" 'sgml-slash
)
93 (define-key map
"\C-c\C-n" 'sgml-name-char
)
94 (define-key map
"\C-c\C-t" 'sgml-tag
)
95 (define-key map
"\C-c\C-a" 'sgml-attributes
)
96 (define-key map
"\C-c\C-b" 'sgml-skip-tag-backward
)
97 (define-key map
[?\C-c left
] 'sgml-skip-tag-backward
)
98 (define-key map
"\C-c\C-f" 'sgml-skip-tag-forward
)
99 (define-key map
[?\C-c right
] 'sgml-skip-tag-forward
)
100 (define-key map
"\C-c\C-d" 'sgml-delete-tag
)
101 (define-key map
"\C-c\^?" 'sgml-delete-tag
)
102 (define-key map
"\C-c?" 'sgml-tag-help
)
103 (define-key map
"\C-c/" 'sgml-close-tag
)
104 (define-key map
"\C-c8" 'sgml-name-8bit-mode
)
105 (define-key map
"\C-c\C-v" 'sgml-validate
)
106 (when sgml-quick-keys
107 (define-key map
"&" 'sgml-name-char
)
108 (define-key map
"<" 'sgml-tag
)
109 (define-key map
" " 'sgml-auto-attributes
)
110 (define-key map
">" 'sgml-maybe-end-tag
)
111 (when (memq ?
\" sgml-specials
)
112 (define-key map
"\"" 'sgml-name-self
))
113 (when (memq ?
' sgml-specials
)
114 (define-key map
"'" 'sgml-name-self
)))
115 (define-key map
(vector (make-char 'latin-iso8859-1
))
116 'sgml-maybe-name-self
)
119 (while (< (setq c
(1+ c
)) 256)
120 (aset map c
'sgml-maybe-name-self
)))
121 (define-key map
[menu-bar sgml
] (cons "SGML" menu-map
))
122 (define-key menu-map
[sgml-validate
] '("Validate" . sgml-validate
))
123 (define-key menu-map
[sgml-name-8bit-mode
]
124 '("Toggle 8 Bit Insertion" . sgml-name-8bit-mode
))
125 (define-key menu-map
[sgml-tags-invisible
]
126 '("Toggle Tag Visibility" . sgml-tags-invisible
))
127 (define-key menu-map
[sgml-tag-help
]
128 '("Describe Tag" . sgml-tag-help
))
129 (define-key menu-map
[sgml-delete-tag
]
130 '("Delete Tag" . sgml-delete-tag
))
131 (define-key menu-map
[sgml-skip-tag-forward
]
132 '("Forward Tag" . sgml-skip-tag-forward
))
133 (define-key menu-map
[sgml-skip-tag-backward
]
134 '("Backward Tag" . sgml-skip-tag-backward
))
135 (define-key menu-map
[sgml-attributes
]
136 '("Insert Attributes" . sgml-attributes
))
137 (define-key menu-map
[sgml-tag
] '("Insert Tag" . sgml-tag
))
139 "Keymap for SGML mode. See also `sgml-specials'.")
141 (defun sgml-make-syntax-table (specials)
142 (let ((table (make-syntax-table text-mode-syntax-table
)))
143 (modify-syntax-entry ?
< "(>" table
)
144 (modify-syntax-entry ?
> ")<" table
)
145 (modify-syntax-entry ?
: "_" table
)
146 (modify-syntax-entry ?_
"_" table
)
147 (modify-syntax-entry ?.
"_" table
)
148 (if (memq ?- specials
)
149 (modify-syntax-entry ?-
"_ 1234" table
))
150 (if (memq ?
\" specials
)
151 (modify-syntax-entry ?
\" "\"\"" table
))
152 (if (memq ?
' specials
)
153 (modify-syntax-entry ?
\' "\"'" table
))
156 (defvar sgml-mode-syntax-table
(sgml-make-syntax-table sgml-specials
)
157 "Syntax table used in SGML mode. See also `sgml-specials'.")
159 (defconst sgml-tag-syntax-table
160 (let ((table (sgml-make-syntax-table '(?- ?
\" ?
\'))))
161 (dolist (char '(?\
( ?\
) ?\
{ ?\
} ?\
[ ?\
] ?$ ?% ?
& ?
* ?
+ ?
/))
162 (modify-syntax-entry char
"." table
))
164 "Syntax table used to parse SGML tags.")
166 (defcustom sgml-name-8bit-mode nil
167 "*When non-nil, insert non-ASCII characters as named entities."
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
176 "nbsp" "excl" "quot" "num" "dollar" "percnt" "amp" "apos"
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"
195 "cedil" "sup1" "ordm" "raquo" "frac14" "frac12" "frac34" "iquest"
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 `;'.")
206 (put 'sgml-table
'char-table-extra-slots
0)
208 (defvar sgml-char-names-table
209 (let ((table (make-char-table 'sgml-table
))
213 (setq elt
(aref sgml-char-names i
))
214 (if elt
(aset table
(make-char 'latin-iso8859-1 i
) elt
))
217 "A table for mapping non-ASCII characters into SGML entity names.
218 Currently, only Latin-1 characters are supported.")
220 ;; nsgmls is a free SGML parser in the SP suite available from
221 ;; ftp.jclark.com and otherwise packaged for GNU systems.
222 ;; Its error messages can be parsed by next-error.
223 ;; The -s option suppresses output.
225 (defcustom sgml-validate-command
"nsgmls -s" ; replaced old `sgmls'
226 "*The command to validate an SGML document.
227 The file name of current buffer file name will be appended to this,
228 separated by a space."
233 (defvar sgml-saved-validate-command nil
234 "The command last used to validate in this buffer.")
236 ;; I doubt that null end tags are used much for large elements,
237 ;; so use a small distance here.
238 (defcustom sgml-slash-distance
1000
239 "*If non-nil, is the maximum distance to search for matching `/'."
240 :type
'(choice (const nil
) integer
)
243 (defconst sgml-namespace-re
"[_[:alpha:]][-_.[:alnum:]]*")
244 (defconst sgml-name-re
"[_:[:alpha:]][-_.:[:alnum:]]*")
245 (defconst sgml-tag-name-re
(concat "<\\([!/?]?" sgml-name-re
"\\)"))
246 (defconst sgml-attrs-re
"\\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*")
247 (defconst sgml-start-tag-regex
(concat "<" sgml-name-re sgml-attrs-re
)
248 "Regular expression that matches a non-empty start tag.
249 Any terminating `>' or `/' is not matched.")
251 (defface sgml-namespace
252 '((t (:inherit font-lock-builtin-face
)))
253 "`sgml-mode' face used to highlight the namespace part of identifiers."
255 ;; backward-compatibility alias
256 (put 'sgml-namespace-face
'face-alias
'sgml-namespace
)
257 (defvar sgml-namespace-face
'sgml-namespace
)
260 (defconst sgml-font-lock-keywords-1
261 `((,(concat "<\\([!?]" sgml-name-re
"\\)") 1 font-lock-keyword-face
)
262 ;; We could use the simpler "\\(" sgml-namespace-re ":\\)?" instead,
263 ;; but it would cause a bit more backtracking in the re-matcher.
264 (,(concat "</?\\(" sgml-namespace-re
"\\)\\(?::\\(" sgml-name-re
"\\)\\)?")
265 (1 (if (match-end 2) sgml-namespace-face font-lock-function-name-face
))
266 (2 font-lock-function-name-face nil t
))
267 ;; FIXME: this doesn't cover the variables using a default value.
268 (,(concat "\\(" sgml-namespace-re
"\\)\\(?::\\("
269 sgml-name-re
"\\)\\)?=[\"']")
270 (1 (if (match-end 2) sgml-namespace-face font-lock-variable-name-face
))
271 (2 font-lock-variable-name-face nil t
))
272 (,(concat "[&%]" sgml-name-re
";?") . font-lock-variable-name-face
)))
274 (defconst sgml-font-lock-keywords-2
276 sgml-font-lock-keywords-1
279 (regexp-opt (mapcar 'car sgml-tag-face-alist
) t
)
280 "\\([ \t][^>]*\\)?>\\([^<]+\\)</\\1>")
281 '(3 (cdr (assoc (downcase (match-string 1))
282 sgml-tag-face-alist
)) prepend
))))))
284 ;; for font-lock, but must be defvar'ed after
285 ;; sgml-font-lock-keywords-1 and sgml-font-lock-keywords-2 above
286 (defvar sgml-font-lock-keywords sgml-font-lock-keywords-1
287 "*Rules for highlighting SGML code. See also `sgml-tag-face-alist'.")
289 (defvar sgml-font-lock-syntactic-keywords
290 ;; Use the `b' style of comments to avoid interference with the -- ... --
291 ;; comments recognized when `sgml-specials' includes ?-.
292 ;; FIXME: beware of <!--> blabla <!--> !!
293 '(("\\(<\\)!--" (1 "< b"))
294 ("--[ \t\n]*\\(>\\)" (1 "> b")))
295 "Syntactic keywords for `sgml-mode'.")
298 (defvar sgml-face-tag-alist
()
299 "Alist of face and tag name for facemenu.")
301 (defvar sgml-tag-face-alist
()
302 "Tag names and face or list of faces to fontify with when invisible.
303 When `font-lock-maximum-decoration' is 1 this is always used for fontifying.
304 When more these are fontified together with `sgml-font-lock-keywords'.")
306 (defvar sgml-display-text
()
307 "Tag names as lowercase symbols, and display string when invisible.")
310 (defvar sgml-tags-invisible nil
)
312 (defcustom sgml-tag-alist
313 '(("![" ("ignore" t
) ("include" t
))
318 "*Alist of tag names for completing read and insertion rules.
319 This alist is made up as
324 TAGRULE is a list of optionally t (no endtag) or `\\n' (separate endtag by
325 newlines) or a skeleton with nil, t or `\\n' in place of the interactor
326 followed by an ATTRIBUTERULE (for an always present attribute) or an
329 The attribute alist is made up as
331 ((\"attribute\" . ATTRIBUTERULE)
334 ATTRIBUTERULE is a list of optionally t (no value when no input) followed by
335 an optional alist of possible values."
336 :type
'(repeat (cons (string :tag
"Tag Name")
337 (repeat :tag
"Tag Rule" sexp
)))
340 (defcustom sgml-tag-help
341 '(("!" .
"Empty declaration for comment")
342 ("![" .
"Embed declarations with parser directive")
343 ("!attlist" .
"Tag attributes declaration")
344 ("!doctype" .
"Document type (DTD) declaration")
345 ("!element" .
"Tag declaration")
346 ("!entity" .
"Entity (macro) declaration"))
347 "*Alist of tag name and short description."
348 :type
'(repeat (cons (string :tag
"Tag Name")
349 (string :tag
"Description")))
352 (defcustom sgml-xml-mode nil
353 "*When non-nil, tag insertion functions will be XML-compliant.
354 If this variable is customized, the custom value is used always.
355 Otherwise, it is set to be buffer-local when the file has
356 a DOCTYPE or an XML declaration."
361 (defvar sgml-empty-tags nil
362 "List of tags whose !ELEMENT definition says EMPTY.")
364 (defvar sgml-unclosed-tags nil
365 "List of tags whose !ELEMENT definition says the end-tag is optional.")
367 (defun sgml-xml-guess ()
368 "Guess whether the current buffer is XML."
370 (goto-char (point-min))
371 (when (or (string= "xml" (file-name-extension (or buffer-file-name
"")))
372 (looking-at "\\s-*<\\?xml")
373 (when (re-search-forward
376 '("<!DOCTYPE" "\\(\\w+\\)" "\\(\\w+\\)"
377 "\"\\([^\"]+\\)\"" "\"\\([^\"]+\\)\"")
380 (string-match "X\\(HT\\)?ML" (match-string 3))))
381 (set (make-local-variable 'sgml-xml-mode
) t
))))
383 (defvar v2
) ; free for skeleton
385 (defun sgml-comment-indent-new-line (&optional soft
)
386 (let ((comment-start "-- ")
387 (comment-start-skip "\\(<!\\)?--[ \t]*")
389 (comment-style 'plain
))
390 (comment-indent-new-line soft
)))
392 (defun sgml-mode-facemenu-add-face-function (face end
)
393 (if (setq face
(cdr (assq face sgml-face-tag-alist
)))
395 (setq face
(funcall skeleton-transformation face
))
396 (setq facemenu-end-add-face
(concat "</" face
">"))
397 (concat "<" face
">"))
398 (error "Face not configured for %s mode" mode-name
)))
400 (defun sgml-fill-nobreak ()
401 ;; Don't break between a tag name and its first argument.
403 (skip-chars-backward " \t")
404 (and (not (zerop (skip-syntax-backward "w_")))
405 (skip-chars-backward "/?!")
406 (eq (char-before) ?
<))))
409 (define-derived-mode sgml-mode text-mode
"SGML"
410 "Major mode for editing SGML documents.
412 Keys <, &, SPC within <>, \", / and ' can be electric depending on
415 An argument of N to a tag-inserting command means to wrap it around
416 the next N words. In Transient Mark mode, when the mark is active,
417 N defaults to -1, which means to wrap it around the current region.
419 If you like upcased tags, put (setq sgml-transformation 'upcase) in
422 Use \\[sgml-validate] to validate your document with an SGML parser.
424 Do \\[describe-variable] sgml- SPC to see available variables.
425 Do \\[describe-key] on the following bindings to discover what they do.
427 (make-local-variable 'sgml-saved-validate-command
)
428 (make-local-variable 'facemenu-end-add-face
)
429 ;;(make-local-variable 'facemenu-remove-face-function)
430 ;; A start or end tag by itself on a line separates a paragraph.
431 ;; This is desirable because SGML discards a newline that appears
432 ;; immediately after a start tag or immediately before an end tag.
433 (set (make-local-variable 'paragraph-start
) (concat "[ \t]*$\\|\
434 \[ \t]*</?\\(" sgml-name-re sgml-attrs-re
"\\)?>"))
435 (set (make-local-variable 'paragraph-separate
)
436 (concat paragraph-start
"$"))
437 (set (make-local-variable 'adaptive-fill-regexp
) "[ \t]*")
438 (add-hook 'fill-nobreak-predicate
'sgml-fill-nobreak nil t
)
439 (set (make-local-variable 'indent-line-function
) 'sgml-indent-line
)
440 (set (make-local-variable 'comment-start
) "<!-- ")
441 (set (make-local-variable 'comment-end
) " -->")
442 (set (make-local-variable 'comment-indent-function
) 'sgml-comment-indent
)
443 (set (make-local-variable 'comment-line-break-function
)
444 'sgml-comment-indent-new-line
)
445 (set (make-local-variable 'skeleton-further-elements
)
446 '((completion-ignore-case t
)))
447 (set (make-local-variable 'skeleton-end-hook
)
450 (not (or (eq v2
'\n) (eq (car-safe v2
) '\n)))
451 (newline-and-indent))))
452 (set (make-local-variable 'font-lock-defaults
)
453 '((sgml-font-lock-keywords
454 sgml-font-lock-keywords-1
455 sgml-font-lock-keywords-2
)
457 (font-lock-syntactic-keywords
458 . sgml-font-lock-syntactic-keywords
)))
459 (set (make-local-variable 'facemenu-add-face-function
)
460 'sgml-mode-facemenu-add-face-function
)
463 (setq mode-name
"XML")
464 (set (make-local-variable 'skeleton-transformation
) sgml-transformation
))
465 ;; This will allow existing comments within declarations to be
467 (set (make-local-variable 'comment-start-skip
) "\\(?:<!\\)?--[ \t]*")
468 (set (make-local-variable 'comment-end-skip
) "[ \t]*--\\([ \t\n]*>\\)?")
469 ;; This definition has an HTML leaning but probably fits well for other modes.
470 (setq imenu-generic-expression
472 ,(concat "<!\\(element\\|entity\\)[ \t\n]+%?[ \t\n]*\\("
476 ,(concat "<[^>]+[ \t\n]+[Ii][Dd]=\\(['\"]"
477 (if sgml-xml-mode
"" "?")
478 "\\)\\(" sgml-name-re
"\\)\\1")
481 ,(concat "<[^>]+[ \t\n]+[Nn][Aa][Mm][Ee]=\\(['\"]"
482 (if sgml-xml-mode
"" "?")
483 "\\)\\(" sgml-name-re
"\\)\\1")
486 ;; Some programs (such as Glade 2) generate XML which has
487 ;; -*- mode: xml -*-.
489 (defalias 'xml-mode
'sgml-mode
)
491 (defun sgml-comment-indent ()
492 (if (looking-at "--") comment-column
0))
494 (defun sgml-slash (arg)
495 "Insert ARG slash characters.
496 Behaves electrically if `sgml-quick-keys' is non-nil."
499 ((not (and (eq (char-before) ?
<) (= arg
1)))
500 (sgml-slash-matching arg
))
501 ((eq sgml-quick-keys
'indent
)
503 (indent-according-to-mode))
504 ((eq sgml-quick-keys
'close
)
505 (delete-backward-char 1)
508 (sgml-slash-matching arg
))))
510 (defun sgml-slash-matching (arg)
511 "Insert `/' and display any previous matching `/'.
512 Two `/'s are treated as matching if the first `/' ends a net-enabling
513 start tag, and the second `/' is the corresponding null end tag."
517 (let ((oldpos (point))
522 (if sgml-slash-distance
523 (narrow-to-region (max (point-min)
524 (- (point) sgml-slash-distance
))
526 (if (and (re-search-backward sgml-start-tag-regex
(point-min) t
)
527 (eq (match-end 0) (1- oldpos
)))
529 (goto-char (1- oldpos
))
530 (while (and (not blinkpos
)
531 (search-backward "/" (point-min) t
))
532 (let ((tagend (save-excursion
533 (if (re-search-backward sgml-start-tag-regex
537 (if (eq tagend
(point))
539 (setq blinkpos
(point))
540 (setq level
(1- level
)))
541 (setq level
(1+ level
)))))))
544 (if (pos-visible-in-window-p)
546 (message "Matches %s"
547 (buffer-substring (line-beginning-position)
548 (1+ blinkpos
)))))))))
550 ;; Why doesn't this use the iso-cvt table or, preferably, generate the
551 ;; inverse of the extensive table in the SGML Quail input method? -- fx
552 ;; I guess that's moot since it only works with Latin-1 anyhow.
553 (defun sgml-name-char (&optional char
)
554 "Insert a symbolic character name according to `sgml-char-names'.
555 Non-ASCII chars may be inserted either with the meta key, as in M-SPC for
556 no-break space or M-- for a soft hyphen; or via an input method or
557 encoded keyboard operation."
561 (setq char
(read-quoted-char "Enter char or octal number")))
562 (delete-backward-char 1)
567 (defun sgml-namify-char ()
568 "Change the char before point into its `&name;' equivalent.
569 Uses `sgml-char-names'."
571 (let* ((char (char-before))
574 ((null char
) (error "No char before point"))
575 ((< char
256) (or (aref sgml-char-names char
) char
))
576 ((aref sgml-char-names-table char
))
577 ((encode-char char
'ucs
)))))
579 (error "Don't know the name of `%c'" char
)
580 (delete-backward-char 1)
581 (insert (format (if (numberp name
) "&#%d;" "&%s;") name
)))))
583 (defun sgml-name-self ()
584 "Insert a symbolic character name according to `sgml-char-names'."
586 (sgml-name-char last-command-char
))
588 (defun sgml-maybe-name-self ()
589 "Insert a symbolic character name according to `sgml-char-names'."
591 (if sgml-name-8bit-mode
592 (let ((mc last-command-char
))
594 (setq mc
(unibyte-char-to-multibyte mc
)))
595 (or mc
(setq mc last-command-char
))
597 (self-insert-command 1)))
599 (defun sgml-name-8bit-mode ()
600 "Toggle whether to insert named entities instead of non-ASCII characters.
601 This only works for Latin-1 input."
603 (setq sgml-name-8bit-mode
(not sgml-name-8bit-mode
))
604 (message "sgml name entity mode is now %s"
605 (if sgml-name-8bit-mode
"ON" "OFF")))
607 ;; When an element of a skeleton is a string "str", it is passed
608 ;; through skeleton-transformation and inserted. If "str" is to be
609 ;; inserted literally, one should obtain it as the return value of a
610 ;; function, e.g. (identity "str").
612 (defvar sgml-tag-last nil
)
613 (defvar sgml-tag-history nil
)
614 (define-skeleton sgml-tag
615 "Prompt for a tag and insert it, optionally with attributes.
616 Completion and configuration are done according to `sgml-tag-alist'.
617 If you like tags and attributes in uppercase do \\[set-variable]
618 skeleton-transformation RET upcase RET, or put this in your `.emacs':
619 (setq sgml-transformation 'upcase)"
620 (funcall (or skeleton-transformation
'identity
)
623 (if (> (length sgml-tag-last
) 0)
624 (format "Tag (default %s): " sgml-tag-last
)
626 sgml-tag-alist nil nil nil
'sgml-tag-history sgml-tag-last
)))
628 (("") -
1 '(undo-boundary) (identity "<")) |
; see comment above
629 `(("") '(setq v2
(sgml-attributes ,str t
)) ?
>
633 '(("") " [ " _
" ]]"))
634 ((and (eq v2 t
) sgml-xml-mode
(member ,str sgml-empty-tags
))
636 ((or (and (eq v2 t
) (not sgml-xml-mode
)) (string-match "^[/!?]" ,str
))
639 ;; Make sure we don't fall into an infinite loop.
640 ;; For xhtml's `tr' tag, we should maybe use \n instead.
641 (if (eq v2 t
) (setq v2 nil
))
642 ;; We use `identity' to prevent skeleton from passing
643 ;; `str' through skeleton-transformation a second time.
644 '(("") v2 _ v2
"</" (identity ',str
) ?
>))
646 (cons '("") (cdr v2
)))
648 (append '(("") (car v2
))
650 '(resume: (car v2
) _
"</" (identity ',str
) ?
>))))))
652 (autoload 'skeleton-read
"skeleton")
654 (defun sgml-attributes (tag &optional quiet
)
655 "When at top level of a tag, interactively insert attributes.
657 Completion and configuration of TAG are done according to `sgml-tag-alist'.
658 If QUIET, do not print a message when there are no attributes for TAG."
659 (interactive (list (save-excursion (sgml-beginning-of-tag t
))))
660 (or (stringp tag
) (error "Wrong context for adding attribute"))
662 (let ((completion-ignore-case t
)
663 (alist (cdr (assoc (downcase tag
) sgml-tag-alist
)))
665 (if (or (symbolp (car alist
))
666 (symbolp (car (car alist
))))
667 (setq car
(car alist
)
670 (message "No attributes configured."))
671 (if (stringp (car alist
))
673 (insert (if (eq (preceding-char) ?
) "" ?
)
674 (funcall skeleton-transformation
(car alist
)))
676 (setq i
(length alist
))
679 (insert (funcall skeleton-transformation
681 (skeleton-read '(completing-read
684 (if (string= "" attribute
)
686 (sgml-value (assoc (downcase attribute
) alist
))
688 (if (eq (preceding-char) ?
)
689 (delete-backward-char 1)))
692 (defun sgml-auto-attributes (arg)
693 "Self insert the character typed; at top level of tag, prompt for attributes.
694 With prefix argument, only self insert."
696 (let ((point (point))
699 (not sgml-tag-alist
) ; no message when nothing configured
700 (symbolp (setq tag
(save-excursion (sgml-beginning-of-tag t
))))
701 (eq (aref tag
0) ?
/))
702 (self-insert-command (prefix-numeric-value arg
))
703 (sgml-attributes tag
)
704 (setq last-command-char ?
)
705 (or (> (point) point
)
706 (self-insert-command 1)))))
708 (defun sgml-tag-help (&optional tag
)
709 "Display description of tag TAG. If TAG is omitted, use the tag at point."
713 (if (eq (following-char) ?
<)
715 (setq tag
(sgml-beginning-of-tag))))
717 (error "No tag selected"))
718 (setq tag
(downcase tag
))
720 (or (cdr (assoc (downcase tag
) sgml-tag-help
))
721 (and (eq (aref tag
0) ?
/)
722 (cdr (assoc (downcase (substring tag
1)) sgml-tag-help
)))
723 "No description available")))
725 (defun sgml-maybe-end-tag (&optional arg
)
726 "Name self unless in position to end a tag or a prefix ARG is given."
728 (if (or arg
(eq (car (sgml-lexical-context)) 'tag
))
729 (self-insert-command (prefix-numeric-value arg
))
732 (defun sgml-skip-tag-backward (arg)
733 "Skip to beginning of tag or matching opening tag if present.
734 With prefix argument ARG, repeat this ARG times."
736 ;; FIXME: use sgml-get-context or something similar.
738 (search-backward "<" nil t
)
739 (if (looking-at "</\\([^ \n\t>]+\\)")
740 ;; end tag, skip any nested pairs
741 (let ((case-fold-search t
)
742 (re (concat "</?" (regexp-quote (match-string 1))
743 ;; Ignore empty tags like <foo/>.
744 "\\([^>]*[^/>]\\)?>")))
745 (while (and (re-search-backward re nil t
)
746 (eq (char-after (1+ (point))) ?
/))
748 (sgml-skip-tag-backward 1))))
749 (setq arg
(1- arg
))))
751 (defun sgml-skip-tag-forward (arg)
752 "Skip to end of tag or matching closing tag if present.
753 With prefix argument ARG, repeat this ARG times.
754 Return t iff after a closing tag."
756 ;; FIXME: Use sgml-get-context or something similar.
757 ;; It currently might jump to an unrelated </P> if the <P>
758 ;; we're skipping has no matching </P>.
760 (with-syntax-table sgml-tag-syntax-table
762 (skip-chars-forward "^<>")
763 (if (eq (following-char) ?
>)
765 (if (looking-at "<\\([^/ \n\t>]+\\)\\([^>]*[^/>]\\)?>")
766 ;; start tag, skip any nested same pairs _and_ closing tag
767 (let ((case-fold-search t
)
768 (re (concat "</?" (regexp-quote (match-string 1))
769 ;; Ignore empty tags like <foo/>.
770 "\\([^>]*[^/>]\\)?>"))
774 ;; FIXME: This re-search-forward will mistakenly match
775 ;; tag-like text inside attributes.
776 (while (and (re-search-forward re nil t
)
778 (eq (char-after (1+ (match-beginning 0))) ?
/)))
779 (goto-char (match-beginning 0))
780 (sgml-skip-tag-forward 1))
789 (defun sgml-delete-tag (arg)
790 ;; FIXME: Should be called sgml-kill-tag or should not touch the kill-ring.
791 "Delete tag on or after cursor, and matching closing or opening tag.
792 With prefix argument ARG, repeat this ARG times."
797 (if (looking-at "[ \t\n]*<")
799 (if (eq (char-after (match-end 0)) ?
/)
803 (goto-char (match-end 0))))
805 (or (save-excursion (setq close
(sgml-beginning-of-tag)
806 close
(and (stringp close
)
807 (eq (aref close
0) ?
/)
809 ;; not on closing tag
810 (let ((point (point)))
811 (sgml-skip-tag-backward 1)
812 (if (or (not (eq (following-char) ?
<))
816 (error "Not on or before tag")))))
819 (sgml-skip-tag-backward 1)
824 (when (and (sgml-skip-tag-forward 1)
825 (not (looking-back "/>")))
827 ;; Delete any resulting empty line. If we didn't kill-sexp,
828 ;; this *should* do nothing, because we're right after the tag.
829 (if (progn (forward-line 0) (looking-at "\\(?:[ \t]*$\\)\n?"))
830 (delete-region (match-beginning 0) (match-end 0)))
833 (if (progn (forward-line 0) (looking-at "\\(?:[ \t]*$\\)\n?"))
834 (delete-region (match-beginning 0) (match-end 0)))))
835 (setq arg
(1- arg
))))
838 ;; Put read-only last to enable setting this even when read-only enabled.
839 (or (get 'sgml-tag
'invisible
)
841 (append '(invisible t
842 point-entered sgml-point-entered
845 (symbol-plist 'sgml-tag
))))
847 (defun sgml-tags-invisible (arg)
848 "Toggle visibility of existing tags."
850 (let ((modified (buffer-modified-p))
851 (inhibit-read-only t
)
852 (inhibit-modification-hooks t
)
853 ;; Avoid spurious the `file-locked' checks.
854 (buffer-file-name nil
)
855 ;; This is needed in case font lock gets called,
856 ;; since it moves point and might call sgml-point-entered.
857 ;; How could it get called? -stef
858 (inhibit-point-motion-hooks t
)
862 (goto-char (point-min))
863 (if (set (make-local-variable 'sgml-tags-invisible
)
865 (>= (prefix-numeric-value arg
) 0)
866 (not sgml-tags-invisible
)))
867 (while (re-search-forward sgml-tag-name-re nil t
)
869 (cdr (assq (intern-soft (downcase (match-string 1)))
871 (goto-char (match-beginning 0))
872 (and (stringp string
)
873 (not (overlays-at (point)))
874 (let ((ol (make-overlay (point) (match-beginning 1))))
875 (overlay-put ol
'before-string string
)
876 (overlay-put ol
'sgml-tag t
)))
877 (put-text-property (point)
878 (progn (forward-list) (point))
879 'category
'sgml-tag
))
880 (let ((pos (point-min)))
881 (while (< (setq pos
(next-overlay-change pos
)) (point-max))
882 (dolist (ol (overlays-at pos
))
883 (if (overlay-get ol
'sgml-tag
)
884 (delete-overlay ol
)))))
885 (remove-text-properties (point-min) (point-max) '(category nil
))))
886 (restore-buffer-modified-p modified
))
887 (run-hooks 'sgml-tags-invisible-hook
)
890 (defun sgml-point-entered (x y
)
891 ;; Show preceding or following hidden tag, depending of cursor direction.
892 (let ((inhibit-point-motion-hooks t
))
894 (message "Invisible tag: %s"
895 ;; Strip properties, otherwise, the text is invisible.
896 (buffer-substring-no-properties
899 (not (eq (following-char) ?
<)))
901 (eq (preceding-char) ?
>)))
906 (autoload 'compile-internal
"compile")
908 (defun sgml-validate (command)
909 "Validate an SGML document.
910 Runs COMMAND, a shell command, in a separate process asynchronously
911 with output going to the buffer `*compilation*'.
912 You can then use the command \\[next-error] to find the next error message
913 and move to the line in the SGML document that caused it."
915 (list (read-string "Validate command: "
916 (or sgml-saved-validate-command
917 (concat sgml-validate-command
919 (let ((name (buffer-file-name)))
921 (file-name-nondirectory name
))))))))
922 (setq sgml-saved-validate-command command
)
923 (save-some-buffers (not compilation-ask-about-save
) nil
)
924 (compile-internal command
"No more errors"))
926 (defsubst sgml-at-indentation-p
()
927 "Return true if point is at the first non-whitespace character on the line."
929 (skip-chars-backward " \t")
932 (defun sgml-lexical-context (&optional limit
)
933 "Return the lexical context at point as (TYPE . START).
934 START is the location of the start of the lexical element.
935 TYPE is one of `string', `comment', `tag', `cdata', or `text'.
937 Optional argument LIMIT is the position to start parsing from.
938 If nil, start from a preceding tag at indentation."
944 ;; Skip tags backwards until we find one at indentation
945 (while (and (ignore-errors (sgml-parse-tag-backward))
946 (not (sgml-at-indentation-p)))))
947 (with-syntax-table sgml-tag-syntax-table
948 (while (< (point) pos
)
949 ;; When entering this loop we're inside text.
950 (setq text-start
(point))
951 (skip-chars-forward "^<" pos
)
955 ;; We got to the end without seeing a tag.
957 ((looking-at "<!\\[[A-Z]+\\[")
958 ;; We've found a CDATA section or similar.
959 (let ((cdata-start (point)))
960 (unless (search-forward "]]>" pos
'move
)
961 (list 0 nil nil
'cdata nil nil nil nil cdata-start
))))
963 ;; We've reached a tag. Parse it.
964 ;; FIXME: Handle net-enabling start-tags
965 (parse-partial-sexp (point) pos
0))))))
967 ((eq (nth 3 state
) 'cdata
) (cons 'cdata
(nth 8 state
)))
968 ((nth 3 state
) (cons 'string
(nth 8 state
)))
969 ((nth 4 state
) (cons 'comment
(nth 8 state
)))
970 ((and state
(> (nth 0 state
) 0)) (cons 'tag
(nth 1 state
)))
971 (t (cons 'text text-start
))))))
973 (defun sgml-beginning-of-tag (&optional top-level
)
974 "Skip to beginning of tag and return its name.
975 If this can't be done, return nil."
976 (let ((context (sgml-lexical-context)))
977 (if (eq (car context
) 'tag
)
979 (goto-char (cdr context
))
980 (when (looking-at sgml-tag-name-re
)
981 (match-string-no-properties 1)))
983 (when (not (eq (car context
) 'text
))
984 (goto-char (cdr context
))
985 (sgml-beginning-of-tag t
))))))
987 (defun sgml-value (alist)
988 "Interactively insert value taken from attribute-rule ALIST.
989 See `sgml-tag-alist' for info about attribute rules."
990 (setq alist
(cdr alist
))
991 (if (stringp (car alist
))
992 (insert "=\"" (car alist
) ?
\")
993 (if (and (eq (car alist
) t
) (not sgml-xml-mode
))
996 (setq alist
(skeleton-read '(completing-read "Value: " (cdr alist
))))
997 (if (string< "" alist
)
999 (delete-backward-char 2)))
1002 (insert (skeleton-read '(completing-read "Value: " alist
))))
1005 (defun sgml-quote (start end
&optional unquotep
)
1006 "Quote SGML text in region START ... END.
1007 Only &, < and > are quoted, the rest is left untouched.
1008 With prefix argument UNQUOTEP, unquote the region."
1009 (interactive "r\nP")
1011 (narrow-to-region start end
)
1012 (goto-char (point-min))
1014 ;; FIXME: We should unquote other named character references as well.
1015 (while (re-search-forward
1016 "\\(&\\(amp\\|\\(l\\|\\(g\\)\\)t\\)\\)[][<>&;\n\t \"%!'(),/=?]"
1018 (replace-match (if (match-end 4) ">" (if (match-end 3) "<" "&")) t t
1019 nil
(if (eq (char-before (match-end 0)) ?\
;) 0 1)))
1020 (while (re-search-forward "[&<>]" nil t
)
1021 (replace-match (cdr (assq (char-before) '((?
& .
"&")
1026 (defun sgml-pretty-print (beg end
)
1027 "Simple-minded pretty printer for SGML.
1028 Re-indents the code and inserts newlines between BEG and END.
1029 You might want to turn on `auto-fill-mode' to get better results."
1031 ;; - insert newline between some start-tag and text.
1032 ;; - don't insert newline in front of some end-tags.
1040 ;; Don't use narrowing because it screws up auto-indent.
1041 (setq end
(copy-marker end t
))
1042 (with-syntax-table sgml-tag-syntax-table
1043 (while (re-search-forward "<" end t
)
1044 (goto-char (match-beginning 0))
1045 (unless (or ;;(looking-at "</")
1046 (progn (skip-chars-backward " \t") (bolp)))
1047 (reindent-then-newline-and-indent))
1049 ;; (indent-region beg end)
1055 (defstruct (sgml-tag
1056 (:constructor sgml-make-tag
(type start end name
)))
1057 type start end name
)
1059 (defsubst sgml-parse-tag-name
()
1060 "Skip past a tag-name, and return the name."
1061 (buffer-substring-no-properties
1062 (point) (progn (skip-syntax-forward "w_") (point))))
1064 (defsubst sgml-looking-back-at
(str)
1065 "Return t if the test before point matches STR."
1066 (let ((start (- (point) (length str
))))
1067 (and (>= start
(point-min))
1068 (equal str
(buffer-substring-no-properties start
(point))))))
1070 (defun sgml-tag-text-p (start end
)
1071 "Return non-nil if text between START and END is a tag.
1072 Checks among other things that the tag does not contain spurious
1073 unquoted < or > chars inside, which would indicate that it
1074 really isn't a tag after all."
1076 (with-syntax-table sgml-tag-syntax-table
1077 (let ((pps (parse-partial-sexp start end
2)))
1078 (and (= (nth 0 pps
) 0))))))
1080 (defun sgml-parse-tag-backward (&optional limit
)
1081 "Parse an SGML tag backward, and return information about the tag.
1082 Assume that parsing starts from within a textual context.
1083 Leave point at the beginning of the tag."
1085 (let (tag-type tag-start tag-end name
)
1086 (or (re-search-backward "[<>]" limit
'move
)
1087 (error "No tag found"))
1088 (when (eq (char-after) ?
<)
1089 ;; Oops!! Looks like we were not in a textual context after all!.
1090 ;; Let's try to recover.
1091 (with-syntax-table sgml-tag-syntax-table
1092 (let ((pos (point)))
1096 ;; This < seems to be just a spurious one, let's ignore it.
1098 (throw 'found
(sgml-parse-tag-backward limit
))))
1099 ;; Check it is really a tag, without any extra < or > inside.
1100 (unless (sgml-tag-text-p pos
(point))
1102 (throw 'found
(sgml-parse-tag-backward limit
)))
1103 (forward-char -
1))))
1104 (setq tag-end
(1+ (point)))
1106 ((sgml-looking-back-at "--") ; comment
1107 (setq tag-type
'comment
1108 tag-start
(search-backward "<!--" nil t
)))
1109 ((sgml-looking-back-at "]]") ; cdata
1110 (setq tag-type
'cdata
1111 tag-start
(re-search-backward "<!\\[[A-Z]+\\[" nil t
)))
1114 (with-syntax-table sgml-tag-syntax-table
1119 ;; This > isn't really the end of a tag. Skip it.
1120 (goto-char (1- tag-end
))
1121 (throw 'found
(sgml-parse-tag-backward limit
))))
1123 (goto-char (1+ tag-start
))
1126 (setq tag-type
'decl
))
1127 (??
; processing-instruction
1128 (setq tag-type
'pi
))
1131 (setq tag-type
'close
1132 name
(sgml-parse-tag-name)))
1134 (setq tag-type
'jsp
))
1135 (t ; open or empty tag
1136 (setq tag-type
'open
1137 name
(sgml-parse-tag-name))
1138 (if (or (eq ?
/ (char-before (- tag-end
1)))
1139 (sgml-empty-tag-p name
))
1140 (setq tag-type
'empty
))))))
1141 (goto-char tag-start
)
1142 (sgml-make-tag tag-type tag-start tag-end name
))))
1144 (defun sgml-get-context (&optional until
)
1145 "Determine the context of the current position.
1146 By default, parse until we find a start-tag as the first thing on a line.
1147 If UNTIL is `empty', return even if the context is empty (i.e.
1148 we just skipped over some element and got to a beginning of line).
1150 The context is a list of tag-info structures. The last one is the tag
1151 immediately enclosing the current position.
1153 Point is assumed to be outside of any tag. If we discover that it's
1154 not the case, the first tag returned is the one inside which we are."
1155 (let ((here (point))
1160 ;; CONTEXT keeps track of the tag-stack
1161 ;; STACK keeps track of the end tags we've seen (and thus the start-tags
1162 ;; we'll have to ignore) when skipping over matching open..close pairs.
1163 ;; IGNORE is a list of tags that can be ignored because they have been
1164 ;; closed implicitly.
1165 (skip-chars-backward " \t\n") ; Make sure we're not at indentation.
1167 (and (not (eq until
'now
))
1169 (not (if until
(eq until
'empty
) context
))
1170 (not (sgml-at-indentation-p))
1172 (/= (point) (sgml-tag-start (car context
)))
1173 (sgml-unclosed-tag-p (sgml-tag-name (car context
)))))
1174 (setq tag-info
(ignore-errors (sgml-parse-tag-backward))))
1176 ;; This tag may enclose things we thought were tags. If so,
1179 (> (sgml-tag-end tag-info
)
1180 (sgml-tag-end (car context
))))
1181 (setq context
(cdr context
)))
1184 ((> (sgml-tag-end tag-info
) here
)
1185 ;; Oops!! Looks like we were not outside of any tag, after all.
1186 (push tag-info context
)
1190 ((eq (sgml-tag-type tag-info
) 'open
)
1193 (if (member-ignore-case (sgml-tag-name tag-info
) ignore
)
1194 ;; There was an implicit end-tag.
1196 (push tag-info context
)
1197 ;; We're changing context so the tags implicitly closed inside
1198 ;; the previous context aren't implicitly closed here any more.
1199 ;; [ Well, actually it depends, but we don't have the info about
1200 ;; when it doesn't and when it does. --Stef ]
1202 ((eq t
(compare-strings (sgml-tag-name tag-info
) nil nil
1203 (car stack
) nil nil t
))
1204 (setq stack
(cdr stack
)))
1206 ;; The open and close tags don't match.
1207 (if (not sgml-xml-mode
)
1208 (unless (sgml-unclosed-tag-p (sgml-tag-name tag-info
))
1209 (message "Unclosed tag <%s>" (sgml-tag-name tag-info
))
1211 ;; We could just assume that the tag is simply not closed
1212 ;; but it's a bad assumption when tags *are* closed but
1213 ;; not properly nested.
1214 (while (and (cdr tmp
)
1215 (not (eq t
(compare-strings
1216 (sgml-tag-name tag-info
) nil nil
1217 (cadr tmp
) nil nil t
))))
1218 (setq tmp
(cdr tmp
)))
1219 (if (cdr tmp
) (setcdr tmp
(cddr tmp
)))))
1220 (message "Unmatched tags <%s> and </%s>"
1221 (sgml-tag-name tag-info
) (pop stack
)))))
1223 (if (and (null stack
) (sgml-unclosed-tag-p (sgml-tag-name tag-info
)))
1224 ;; This is a top-level open of an implicitly closed tag, so any
1225 ;; occurrence of such an open tag at the same level can be ignored
1226 ;; because it's been implicitly closed.
1227 (push (sgml-tag-name tag-info
) ignore
)))
1230 ((eq (sgml-tag-type tag-info
) 'close
)
1231 (if (sgml-empty-tag-p (sgml-tag-name tag-info
))
1232 (message "Spurious </%s>: empty tag" (sgml-tag-name tag-info
))
1233 (push (sgml-tag-name tag-info
) stack
)))
1239 (defun sgml-show-context (&optional full
)
1240 "Display the current context.
1241 If FULL is non-nil, parse back to the beginning of the buffer."
1243 (with-output-to-temp-buffer "*XML Context*"
1245 (let ((context (sgml-get-context)))
1248 (while (setq more
(sgml-get-context))
1249 (setq context
(nconc more context
)))))
1253 ;; Editing shortcuts
1255 (defun sgml-close-tag ()
1256 "Close current element.
1257 Depending on context, inserts a matching close-tag, or closes
1258 the current start-tag or the current comment or the current cdata, ..."
1260 (case (car (sgml-lexical-context))
1261 (comment (insert " -->"))
1262 (cdata (insert "]]>"))
1264 (jsp (insert " %>"))
1265 (tag (insert " />"))
1267 (let ((context (save-excursion (sgml-get-context))))
1270 (insert "</" (sgml-tag-name (car (last context
))) ">")
1271 (indent-according-to-mode)))))
1273 (error "Nothing to close"))))
1275 (defun sgml-empty-tag-p (tag-name)
1276 "Return non-nil if TAG-NAME is an implicitly empty tag."
1277 (and (not sgml-xml-mode
)
1278 (member-ignore-case tag-name sgml-empty-tags
)))
1280 (defun sgml-unclosed-tag-p (tag-name)
1281 "Return non-nil if TAG-NAME is a tag for which an end-tag is optional."
1282 (and (not sgml-xml-mode
)
1283 (member-ignore-case tag-name sgml-unclosed-tags
)))
1285 (defun sgml-calculate-indent (&optional lcon
)
1286 "Calculate the column to which this line should be indented.
1287 LCON is the lexical context, if any."
1288 (unless lcon
(setq lcon
(sgml-lexical-context)))
1290 ;; Indent comment-start markers inside <!-- just like comment-end markers.
1291 (if (and (eq (car lcon
) 'tag
)
1293 (save-excursion (goto-char (cdr lcon
)) (looking-at "<!--")))
1294 (setq lcon
(cons 'comment
(+ (cdr lcon
) 2))))
1299 ;; Go back to previous non-empty line.
1300 (while (and (> (point) (cdr lcon
))
1301 (zerop (forward-line -
1))
1302 (looking-at "[ \t]*$")))
1303 (if (> (point) (cdr lcon
))
1304 ;; Previous line is inside the string.
1305 (current-indentation)
1306 (goto-char (cdr lcon
))
1307 (1+ (current-column))))
1310 (let ((mark (looking-at "--")))
1311 ;; Go back to previous non-empty line.
1312 (while (and (> (point) (cdr lcon
))
1313 (zerop (forward-line -
1))
1314 (or (looking-at "[ \t]*$")
1315 (if mark
(not (looking-at "[ \t]*--"))))))
1316 (if (> (point) (cdr lcon
))
1317 ;; Previous line is inside the comment.
1318 (skip-chars-forward " \t")
1319 (goto-char (cdr lcon
))
1320 ;; Skip `<!' to get to the `--' with which we want to align.
1321 (search-forward "--")
1322 (goto-char (match-beginning 0)))
1323 (when (and (not mark
) (looking-at "--"))
1324 (forward-char 2) (skip-chars-forward " \t"))
1327 ;; We don't know how to indent it. Let's be honest about it.
1331 (goto-char (1+ (cdr lcon
)))
1332 (skip-chars-forward "^ \t\n") ;Skip tag name.
1333 (skip-chars-forward " \t")
1336 ;; This is the first attribute: indent.
1337 (goto-char (1+ (cdr lcon
)))
1338 (+ (current-column) sgml-basic-offset
)))
1341 (while (looking-at "</")
1343 (skip-chars-forward " \t"))
1344 (let* ((here (point))
1345 (unclosed (and ;; (not sgml-xml-mode)
1346 (looking-at sgml-tag-name-re
)
1347 (member-ignore-case (match-string 1)
1351 ;; If possible, align on the previous non-empty text line.
1352 ;; Otherwise, do a more serious parsing to find the
1353 ;; tag(s) relative to which we should be indenting.
1354 (if (and (not unclosed
) (skip-chars-backward " \t")
1355 (< (skip-chars-backward " \t\n") 0)
1356 (back-to-indentation)
1357 (> (point) (cdr lcon
)))
1360 (nreverse (sgml-get-context (if unclosed nil
'empty
)))))
1362 ;; Ignore previous unclosed start-tag in context.
1363 (while (and context unclosed
1364 (eq t
(compare-strings
1365 (sgml-tag-name (car context
)) nil nil
1366 unclosed nil nil t
)))
1367 (setq context
(cdr context
)))
1368 ;; Indent to reflect nesting.
1370 ;; If we were not in a text context after all, let's try again.
1371 ((and context
(> (sgml-tag-end (car context
)) here
))
1373 (sgml-calculate-indent
1374 (cons (if (memq (sgml-tag-type (car context
)) '(comment cdata
))
1375 (sgml-tag-type (car context
)) 'tag
)
1376 (sgml-tag-start (car context
)))))
1377 ;; Align on the first element after the nearest open-tag, if any.
1379 (goto-char (sgml-tag-end (car context
)))
1380 (skip-chars-forward " \t\n")
1381 (< (point) here
) (sgml-at-indentation-p))
1386 (* sgml-basic-offset
(length context
)))))))
1389 (error "Unrecognized context %s" (car lcon
)))
1393 (defun sgml-indent-line ()
1394 "Indent the current line as SGML."
1396 (let* ((savep (point))
1399 (back-to-indentation)
1400 (if (>= (point) savep
) (setq savep nil
))
1401 (sgml-calculate-indent))))
1402 (if (null indent-col
)
1405 (save-excursion (indent-line-to indent-col
))
1406 (indent-line-to indent-col
)))))
1408 (defun sgml-guess-indent ()
1409 "Guess an appropriate value for `sgml-basic-offset'.
1410 Base the guessed identation level on the first indented tag in the buffer.
1411 Add this to `sgml-mode-hook' for convenience."
1414 (goto-char (point-min))
1415 (if (re-search-forward "^\\([ \t]+\\)<" 500 'noerror
)
1417 (set (make-local-variable 'sgml-basic-offset
)
1418 (1- (current-column)))
1419 (message "Guessed sgml-basic-offset = %d"
1423 (defun sgml-parse-dtd ()
1424 "Simplistic parse of the current buffer as a DTD.
1425 Currently just returns (EMPTY-TAGS UNCLOSED-TAGS)."
1426 (goto-char (point-min))
1429 (while (re-search-forward "<!ELEMENT[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+[-O][ \t\n]+\\([-O]\\)[ \t\n]+\\([^ \t\n]+\\)" nil t
)
1431 ((string= (match-string 3) "EMPTY")
1432 (push (match-string-no-properties 1) empty
))
1433 ((string= (match-string 2) "O")
1434 (push (match-string-no-properties 1) unclosed
))))
1435 (setq empty
(sort (mapcar 'downcase empty
) 'string
<))
1436 (setq unclosed
(sort (mapcar 'downcase unclosed
) 'string
<))
1437 (list empty unclosed
)))
1441 (defcustom html-mode-hook nil
1442 "Hook run by command `html-mode'.
1443 `text-mode-hook' and `sgml-mode-hook' are run first."
1446 :options
'(html-autoview-mode))
1448 (defvar html-quick-keys sgml-quick-keys
1449 "Use C-c X combinations for quick insertion of frequent tags when non-nil.
1450 This defaults to `sgml-quick-keys'.
1451 This takes effect when first loading the library.")
1453 (defvar html-mode-map
1454 (let ((map (make-sparse-keymap))
1455 (menu-map (make-sparse-keymap "HTML")))
1456 (set-keymap-parent map sgml-mode-map
)
1457 (define-key map
"\C-c6" 'html-headline-6
)
1458 (define-key map
"\C-c5" 'html-headline-5
)
1459 (define-key map
"\C-c4" 'html-headline-4
)
1460 (define-key map
"\C-c3" 'html-headline-3
)
1461 (define-key map
"\C-c2" 'html-headline-2
)
1462 (define-key map
"\C-c1" 'html-headline-1
)
1463 (define-key map
"\C-c\r" 'html-paragraph
)
1464 (define-key map
"\C-c\n" 'html-line
)
1465 (define-key map
"\C-c\C-c-" 'html-horizontal-rule
)
1466 (define-key map
"\C-c\C-co" 'html-ordered-list
)
1467 (define-key map
"\C-c\C-cu" 'html-unordered-list
)
1468 (define-key map
"\C-c\C-cr" 'html-radio-buttons
)
1469 (define-key map
"\C-c\C-cc" 'html-checkboxes
)
1470 (define-key map
"\C-c\C-cl" 'html-list-item
)
1471 (define-key map
"\C-c\C-ch" 'html-href-anchor
)
1472 (define-key map
"\C-c\C-cn" 'html-name-anchor
)
1473 (define-key map
"\C-c\C-ci" 'html-image
)
1474 (when html-quick-keys
1475 (define-key map
"\C-c-" 'html-horizontal-rule
)
1476 (define-key map
"\C-co" 'html-ordered-list
)
1477 (define-key map
"\C-cu" 'html-unordered-list
)
1478 (define-key map
"\C-cr" 'html-radio-buttons
)
1479 (define-key map
"\C-cc" 'html-checkboxes
)
1480 (define-key map
"\C-cl" 'html-list-item
)
1481 (define-key map
"\C-ch" 'html-href-anchor
)
1482 (define-key map
"\C-cn" 'html-name-anchor
)
1483 (define-key map
"\C-ci" 'html-image
))
1484 (define-key map
"\C-c\C-s" 'html-autoview-mode
)
1485 (define-key map
"\C-c\C-v" 'browse-url-of-buffer
)
1486 (define-key map
[menu-bar html
] (cons "HTML" menu-map
))
1487 (define-key menu-map
[html-autoview-mode
]
1488 '("Toggle Autoviewing" . html-autoview-mode
))
1489 (define-key menu-map
[browse-url-of-buffer
]
1490 '("View Buffer Contents" . browse-url-of-buffer
))
1491 (define-key menu-map
[nil] '("--"))
1492 ;;(define-key menu-map "6" '("Heading 6" . html-headline-6))
1493 ;;(define-key menu-map "5" '("Heading 5" . html-headline-5))
1494 ;;(define-key menu-map "4" '("Heading 4" . html-headline-4))
1495 (define-key menu-map "3" '("Heading 3" . html-headline-3))
1496 (define-key menu-map "2" '("Heading 2" . html-headline-2))
1497 (define-key menu-map "1" '("Heading 1" . html-headline-1))
1498 (define-key menu-map "l" '("Radio Buttons" . html-radio-buttons))
1499 (define-key menu-map "c" '("Checkboxes" . html-checkboxes))
1500 (define-key menu-map "l" '("List Item" . html-list-item))
1501 (define-key menu-map "u" '("Unordered List" . html-unordered-list))
1502 (define-key menu-map "o" '("Ordered List" . html-ordered-list))
1503 (define-key menu-map "-" '("Horizontal Rule" . html-horizontal-rule))
1504 (define-key menu-map "\n" '("Line Break" . html-line))
1505 (define-key menu-map "\r" '("Paragraph" . html-paragraph))
1506 (define-key menu-map "i" '("Image" . html-image))
1507 (define-key menu-map "h" '("Href Anchor" . html-href-anchor))
1508 (define-key menu-map "n" '("Name Anchor" . html-name-anchor))
1510 "Keymap for commands for use in HTML mode.")
1512 (defvar html-face-tag-alist
1517 "Value of `sgml-face-tag-alist' for HTML mode.")
1519 (defvar html-tag-face-alist
1522 ("blink" . highlight)
1525 ("h1" bold underline)
1526 ("h2" bold-italic underline)
1527 ("h3" italic underline)
1536 ("title" bold underline)
1540 "Value of `sgml-tag-face-alist' for HTML mode.")
1542 (defvar html-display-text
1546 "Value of `sgml-display-text' for HTML mode.")
1549 ;; should code exactly HTML 3 here when that is finished
1550 (defvar html-tag-alist
1551 (let* ((1-7 '(("1") ("2") ("3") ("4") ("5") ("6") ("7")))
1552 (1-9 `(,@1-7 ("8") ("9")))
1553 (align '(("align" ("left") ("center") ("right"))))
1554 (valign '(("top") ("middle") ("bottom") ("baseline")))
1555 (rel '(("next") ("previous") ("parent") ("subdocument") ("made")))
1556 (href '("href" ("ftp:") ("file:") ("finger:") ("gopher:") ("http:")
1557 ("mailto:") ("news:") ("rlogin:") ("telnet:") ("tn3270:")
1558 ("wais:") ("/cgi-bin/")))
1564 (list '((nil \n ("List item: " "<li>" str
1565 (if sgml-xml-mode "</li>") \n))))
1572 ;; put ,-expressions first, else byte-compile chokes (as of V19.29)
1573 ;; and like this it's more efficient anyway
1574 `(("a" ,name ,@link)
1577 ("font" nil "size" ("-1") ("+1") ("-2") ("+2") ,@1-7)
1578 ("form" (\n _ \n "<input type=\"submit\" value=\"\""
1579 (if sgml-xml-mode " />" ">"))
1580 ("action" ,@(cdr href)) ("method" ("get") ("post")))
1587 ("hr" t ("size" ,@1-9) ("width") ("noshade" t) ,@align)
1588 ("img" t ("align" ,@valign ("texttop") ("absmiddle") ("absbottom"))
1589 ("src") ("alt") ("width" "1") ("height" "1")
1590 ("border" "1") ("vspace" "1") ("hspace" "1") ("ismap" t))
1591 ("input" t ("size" ,@1-9) ("maxlength" ,@1-9) ("checked" t) ,name
1592 ("type" ("text") ("password") ("checkbox") ("radio")
1593 ("submit") ("reset"))
1597 ("ol" ,@list ("type" ("A") ("a") ("I") ("i") ("1")))
1601 "<option>" str (if sgml-xml-mode "</option>") \n))
1602 ,name ("size" ,@1-9) ("multiple" t))
1604 ((completing-read "Cell kind: " '(("td") ("th"))
1607 (if sgml-xml-mode (concat "<" str "></tr>")) \n))
1608 ("border" t ,@1-9) ("width" "10") ("cellpadding"))
1610 ("textarea" ,name ("rows" ,@1-9) ("cols" ,@1-9))
1612 ("ul" ,@list ("type" ("disc") ("circle") ("square")))
1620 ("Item: " "<item>" str (if sgml-xml-mode "</item>") \n))
1627 ("body" \n ("background" ".gif") ("bgcolor" "#") ("text" "#")
1628 ("link" "#") ("alink" "#") ("vlink" "#"))
1629 ("box" (nil _ "<over>" _ (if sgml-xml-mode "</over>")))
1630 ("br" t ("clear" ("left") ("right")))
1631 ("caption" ("valign" ("top") ("bottom")))
1635 ("dd" ,(not sgml-xml-mode))
1641 "<dt>" str (if sgml-xml-mode "</dt>")
1642 "<dd>" _ (if sgml-xml-mode "</dd>") \n)))
1643 ("dt" (t _ (if sgml-xml-mode "</dt>")
1644 "<dd>" (if sgml-xml-mode "</dd>") \n))
1646 ;("fn" "id" "fn") ; ???
1650 "<title>" (setq str (read-input "Title: ")) "</title>\n"
1652 "<body>\n<h1>" str "</h1>\n" _
1653 "\n<address>\n<a href=\"mailto:"
1655 "\">" (user-full-name) "</a>\n</address>\n"
1660 ("isindex" t ("action") ("prompt"))
1663 ("li" ,(not sgml-xml-mode))
1666 ("option" t ("value") ("label") ("selected" t))
1695 "*Value of `sgml-tag-alist' for HTML mode.")
1697 (defvar html-tag-help
1699 ("a" . "Anchor of point or link elsewhere")
1702 ("address" . "Formatted mail address")
1703 ("array" . "Math array")
1706 ("base" . "Base address for URLs")
1707 ("big" . "Font size")
1708 ("blink" . "Blinking text")
1709 ("blockquote" . "Indented quotation")
1710 ("body" . "Document body")
1711 ("box" . "Math fraction")
1712 ("br" . "Line break")
1713 ("caption" . "Table caption")
1714 ("center" . "Centered text")
1715 ("changed" . "Change bars")
1716 ("cite" . "Citation of a document")
1717 ("code" . "Formatted source code")
1718 ("dd" . "Definition of term")
1721 ("dir" . "Directory list (obsolete)")
1722 ("dl" . "Definition list")
1723 ("dt" . "Term to be definined")
1724 ("em" . "Emphasized")
1725 ("embed" . "Embedded data in foreign format")
1727 ("figa" . "Figure anchor")
1728 ("figd" . "Figure description")
1729 ("figt" . "Figure text")
1731 ("font" . "Font size")
1732 ("form" . "Form with input fields")
1733 ("group" . "Document grouping")
1734 ("h1" . "Most important section headline")
1735 ("h2" . "Important section headline")
1736 ("h3" . "Section headline")
1737 ("h4" . "Minor section headline")
1738 ("h5" . "Unimportant section headline")
1739 ("h6" . "Least important section headline")
1740 ("head" . "Document header")
1741 ("hr" . "Horizontal rule")
1742 ("html" . "HTML Document")
1743 ("i" . "Italic face")
1744 ("img" . "Graphic image")
1745 ("input" . "Form input field")
1747 ("isindex" . "Input field for index search")
1748 ("kbd" . "Keybard example face")
1749 ("lang" . "Natural language")
1750 ("li" . "List item")
1751 ("link" . "Link relationship")
1752 ("math" . "Math formula")
1753 ("menu" . "Menu list (obsolete)")
1754 ("mh" . "Form mail header")
1755 ("nextid" . "Allocate new id")
1756 ("nobr" . "Text without line break")
1757 ("ol" . "Ordered list")
1758 ("option" . "Selection list item")
1759 ("over" . "Math fraction rule")
1760 ("p" . "Paragraph start")
1761 ("panel" . "Floating panel")
1763 ("pre" . "Preformatted fixed width text")
1765 ("rev" . "Reverse video")
1767 ("samp" . "Sample text")
1768 ("select" . "Selection list")
1769 ("small" . "Font size")
1770 ("sp" . "Nobreak space")
1771 ("strong" . "Standout text")
1772 ("sub" . "Subscript")
1773 ("sup" . "Superscript")
1774 ("table" . "Table with rows and columns")
1775 ("tb" . "Table vertical break")
1776 ("td" . "Table data cell")
1777 ("textarea" . "Form multiline edit area")
1778 ("th" . "Table header cell")
1779 ("title" . "Document title")
1780 ("tr" . "Table row separator")
1781 ("tt" . "Typewriter face")
1782 ("u" . "Underlined text")
1783 ("ul" . "Unordered list")
1784 ("var" . "Math variable face")
1785 ("wbr" . "Enable <br> within <nobr>"))
1786 "*Value of `sgml-tag-help' for HTML mode.")
1790 (define-derived-mode html-mode sgml-mode "HTML"
1791 "Major mode based on SGML mode for editing HTML documents.
1792 This allows inserting skeleton constructs used in hypertext documents with
1793 completion. See below for an introduction to HTML. Use
1794 \\[browse-url-of-buffer] to see how this comes out. See also `sgml-mode' on
1795 which this is based.
1797 Do \\[describe-variable] html- SPC and \\[describe-variable] sgml- SPC to see available variables.
1799 To write fairly well formatted pages you only need to know few things. Most
1800 browsers have a function to read the source code of the page being seen, so
1801 you can imitate various tricks. Here's a very short HTML primer which you
1802 can also view with a browser to see what happens:
1804 <title>A Title Describing Contents</title> should be on every page. Pages can
1805 have <h1>Very Major Headlines</h1> through <h6>Very Minor Headlines</h6>
1806 <hr> Parts can be separated with horizontal rules.
1808 <p>Paragraphs only need an opening tag. Line breaks and multiple spaces are
1809 ignored unless the text is <pre>preformatted.</pre> Text can be marked as
1810 <b>bold</b>, <i>italic</i> or <u>underlined</u> using the normal M-o or
1811 Edit/Text Properties/Face commands.
1813 Pages can have <a name=\"SOMENAME\">named points</a> and can link other points
1814 to them with <a href=\"#SOMENAME\">see also somename</a>. In the same way <a
1815 href=\"URL\">see also URL</a> where URL is a filename relative to current
1816 directory, or absolute as in `http://www.cs.indiana.edu/elisp/w3/docs.html'.
1818 Images in many formats can be inlined with <img src=\"URL\">.
1820 If you mainly create your own documents, `sgml-specials' might be
1821 interesting. But note that some HTML 2 browsers can't handle `''.
1822 To work around that, do:
1823 (eval-after-load \"sgml-mode\" '(aset sgml-char-names ?' nil))
1826 (set (make-local-variable 'sgml-display-text) html-display-text)
1827 (set (make-local-variable 'sgml-tag-face-alist) html-tag-face-alist)
1828 (make-local-variable 'sgml-tag-alist)
1829 (make-local-variable 'sgml-face-tag-alist)
1830 (make-local-variable 'sgml-tag-help)
1831 (make-local-variable 'outline-regexp)
1832 (make-local-variable 'outline-heading-end-regexp)
1833 (make-local-variable 'outline-level)
1834 (make-local-variable 'sentence-end)
1836 (if sentence-end-double-space
1837 "[.?!][]\"')}]*\\(<[^>]*>\\)*\\($\\| $\\|\t\\| \\)[ \t\n]*"
1838 "[.?!][]\"')}]*\\(<[^>]*>\\)*\\($\\|[ \t]\\)[ \t\n]*"))
1839 (setq sgml-tag-alist html-tag-alist
1840 sgml-face-tag-alist html-face-tag-alist
1841 sgml-tag-help html-tag-help
1842 outline-regexp "^.*<[Hh][1-6]\\>"
1843 outline-heading-end-regexp "</[Hh][1-6]>"
1844 outline-level (lambda ()
1845 (char-before (match-end 0))))
1846 (setq imenu-create-index-function 'html-imenu-index)
1847 (when sgml-xml-mode (setq mode-name "XHTML"))
1848 (set (make-local-variable 'sgml-empty-tags)
1849 ;; From HTML-4.01's loose.dtd, parsed with `sgml-parse-dtd',
1850 ;; plus manual addition of "wbr".
1851 '("area" "base" "basefont" "br" "col" "frame" "hr" "img" "input"
1852 "isindex" "link" "meta" "param" "wbr"))
1853 (set (make-local-variable 'sgml-unclosed-tags)
1854 ;; From HTML-4.01's loose.dtd, parsed with `sgml-parse-dtd'.
1855 '("body" "colgroup" "dd" "dt" "head" "html" "li" "option"
1856 "p" "tbody" "td" "tfoot" "th" "thead" "tr"))
1857 ;; It's for the user to decide if it defeats it or not -stef
1858 ;; (make-local-variable 'imenu-sort-function)
1859 ;; (setq imenu-sort-function nil) ; sorting the menu defeats the purpose
1862 (defvar html-imenu-regexp
1863 "\\s-*<h\\([1-9]\\)[^\n<>]*>\\(<[^\n<>]*>\\)*\\s-*\\([^\n<>]*\\)"
1864 "*A regular expression matching a head line to be added to the menu.
1865 The first `match-string' should be a number from 1-9.
1866 The second `match-string' matches extra tags and is ignored.
1867 The third `match-string' will be the used in the menu.")
1869 (defun html-imenu-index ()
1870 "Return a table of contents for an HTML buffer for use with Imenu."
1873 (goto-char (point-min))
1874 (while (re-search-forward html-imenu-regexp nil t)
1876 (cons (cons (concat (make-string
1877 (* 2 (1- (string-to-number (match-string 1))))
1880 (line-beginning-position))
1882 (nreverse toc-index)))
1884 (define-minor-mode html-autoview-mode
1885 "Toggle automatic viewing via `browse-url-of-buffer' upon saving buffer.
1886 With positive prefix ARG always turns viewing on, with negative ARG always off.
1887 Can be used as a value for `html-mode-hook'."
1890 (if html-autoview-mode
1891 (add-hook 'after-save-hook 'browse-url-of-buffer nil t)
1892 (remove-hook 'after-save-hook 'browse-url-of-buffer t)))
1895 (define-skeleton html-href-anchor
1896 "HTML anchor tag with href attribute."
1898 ;; '(setq input "http:")
1899 "<a href=\"" str "\">" _ "</a>")
1901 (define-skeleton html-name-anchor
1902 "HTML anchor tag with name attribute."
1904 "<a name=\"" str "\""
1905 (if sgml-xml-mode (concat " id=\"" str "\""))
1908 (define-skeleton html-headline-1
1909 "HTML level 1 headline tags."
1913 (define-skeleton html-headline-2
1914 "HTML level 2 headline tags."
1918 (define-skeleton html-headline-3
1919 "HTML level 3 headline tags."
1923 (define-skeleton html-headline-4
1924 "HTML level 4 headline tags."
1928 (define-skeleton html-headline-5
1929 "HTML level 5 headline tags."
1933 (define-skeleton html-headline-6
1934 "HTML level 6 headline tags."
1938 (define-skeleton html-horizontal-rule
1939 "HTML horizontal rule tag."
1941 (if sgml-xml-mode "<hr />" "<hr>") \n)
1943 (define-skeleton html-image
1946 "<img src=\"" str "\" alt=\"" _ "\""
1947 (if sgml-xml-mode " />" ">"))
1949 (define-skeleton html-line
1950 "HTML line break tag."
1952 (if sgml-xml-mode "<br />" "<br>") \n)
1954 (define-skeleton html-ordered-list
1955 "HTML ordered list tags."
1958 "<li>" _ (if sgml-xml-mode "</li>") \n
1961 (define-skeleton html-unordered-list
1962 "HTML unordered list tags."
1965 "<li>" _ (if sgml-xml-mode "</li>") \n
1968 (define-skeleton html-list-item
1969 "HTML list item tag."
1972 "<li>" _ (if sgml-xml-mode "</li>"))
1974 (define-skeleton html-paragraph
1975 "HTML paragraph tag."
1978 "<p>" _ (if sgml-xml-mode "</p>"))
1980 (define-skeleton html-checkboxes
1981 "Group of connected checkbox inputs."
1986 "<input type=\"" (identity "checkbox") ; see comment above about identity
1987 "\" name=\"" (or v1 (setq v1 (skeleton-read "Name: ")))
1988 "\" value=\"" str ?\"
1989 (when (y-or-n-p "Set \"checked\" attribute? ")
1990 (funcall skeleton-transformation
1991 (if sgml-xml-mode " checked=\"checked\"" " checked")))
1992 (if sgml-xml-mode " />" ">")
1993 (skeleton-read "Text: " (capitalize str))
1994 (or v2 (setq v2 (if (y-or-n-p "Newline after text? ")
1995 (funcall skeleton-transformation
1996 (if sgml-xml-mode "<br />" "<br>"))
2000 (define-skeleton html-radio-buttons
2001 "Group of connected radio button inputs."
2006 "<input type=\"" (identity "radio") ; see comment above about identity
2007 "\" name=\"" (or (car v2) (setcar v2 (skeleton-read "Name: ")))
2008 "\" value=\"" str ?\"
2009 (when (and (not v1) (setq v1 (y-or-n-p "Set \"checked\" attribute? ")))
2010 (funcall skeleton-transformation
2011 (if sgml-xml-mode " checked=\"checked\"" " checked")))
2012 (if sgml-xml-mode " />" ">")
2013 (skeleton-read "Text: " (capitalize str))
2014 (or (cdr v2) (setcdr v2 (if (y-or-n-p "Newline after text? ")
2015 (funcall skeleton-transformation
2016 (if sgml-xml-mode "<br />" "<br>"))
2020 (provide 'sgml-mode)
2022 ;; arch-tag: 9675da94-b7f9-4bda-ad19-73ed7b4fb401
2023 ;;; sgml-mode.el ends here