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