0
|
1 ;;; psgml-html.el --- HTML mode in conjunction with PSGML
|
|
2
|
|
3 ;; Copyright (C) 1994 Nelson Minar.
|
|
4 ;; Copyright (C) 1995 Nelson Minar and Ulrik Dickow.
|
|
5 ;; Copyright (C) 1996 Ben Wing.
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
70
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
21 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
0
|
22
|
|
23 ;;; Synched up with: FSF 19.30.
|
|
24
|
|
25 ;;; Author: Ben Wing.
|
|
26
|
|
27 ;;; Commentary:
|
|
28
|
|
29 ; Parts were taken from html-helper-mode and from code by Alastair Burt.
|
|
30
|
100
|
31 ; Feb 18 1997, Heiko Muenkel: Added the hook variable html-mode-hook.
|
|
32 ; With that you can now use the hm--html-minor-mode together
|
|
33 ; with this mode. For that you've to add the following line
|
|
34 ; to your ~/.emacs:
|
|
35 ; (add-hook 'html-mode-hook 'hm--html-minor-mode)
|
|
36
|
0
|
37 ;;; Code:
|
|
38
|
88
|
39 (defvar html-auto-sgml-entity-conversion nil
|
|
40 "*Control automatic sgml entity to ISO-8859-1 conversion")
|
|
41
|
0
|
42 (require 'psgml)
|
|
43 (require 'derived)
|
88
|
44 (when html-auto-sgml-entity-conversion
|
|
45 (require 'iso-sgml))
|
0
|
46 (require 'tempo) ;essential part of html-helper-mode
|
|
47
|
|
48 ;;{{{ user variables
|
|
49
|
|
50 ;; Set this to be whatever signature you want on the bottom of your pages.
|
|
51 (defvar html-helper-address-string
|
114
|
52 (concat "<a href=\"mailto:" (user-mail-address) "\">"
|
0
|
53 (user-full-name) "</a>")
|
|
54 "*The default author string of each file.")
|
|
55
|
|
56 (defvar html-helper-htmldtd-version "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
|
|
57 "*Version of HTML DTD you're using.")
|
|
58
|
|
59 (defvar html-helper-do-write-file-hooks t
|
|
60 "*If not nil, then modify `local-write-file-hooks' to do timestamps.")
|
|
61
|
|
62 (defvar html-helper-build-new-buffer t
|
|
63 "*If not nil, then insert `html-helper-new-buffer-strings' for new buffers.")
|
|
64
|
|
65 (defvar html-helper-timestamp-hook 'html-helper-default-insert-timestamp
|
|
66 "*Hook called for timestamp insertion.
|
|
67 Override this for your own timestamp styles.")
|
|
68
|
|
69 ;; strings you might want to change
|
|
70
|
|
71 (defvar html-helper-new-buffer-template
|
|
72 '(html-helper-htmldtd-version
|
|
73 "<html>\n"
|
|
74 " <head>\n"
|
|
75 " <title>" (p "Document Title: " title) "</title>\n"
|
|
76 " </head>\n"
|
|
77 "\n"
|
|
78 " <body>\n"
|
110
|
79 " <h1>" (s title) "</h1>\n\n"
|
0
|
80 p
|
110
|
81 "\n\n <hr>\n"
|
|
82 " <address>" html-helper-address-string "</address>\n"
|
0
|
83 (html-helper-return-created-string)
|
|
84 html-helper-timestamp-start
|
|
85 html-helper-timestamp-end
|
|
86 "\n </body>\n</html>\n")
|
|
87 "*Template for new buffers.
|
|
88 Inserted by `html-helper-insert-new-buffer-strings' if
|
|
89 `html-helper-build-new-buffer' is set to t")
|
|
90
|
|
91 (defvar html-helper-timestamp-start "<!-- hhmts start -->\n"
|
|
92 "*Start delimiter for timestamps.
|
|
93 Everything between `html-helper-timestamp-start' and
|
|
94 `html-helper-timestamp-end' will be deleted and replaced with the output
|
|
95 of the functions `html-helper-timestamp-hook' if
|
|
96 `html-helper-do-write-file-hooks' is t")
|
|
97
|
|
98 (defvar html-helper-timestamp-end "<!-- hhmts end -->"
|
|
99 "*End delimiter for timestamps.
|
|
100 Everything between `html-helper-timestamp-start' and
|
|
101 `html-helper-timestamp-end' will be deleted and replaced with the output
|
|
102 of the function `html-helper-insert-timestamp' if
|
|
103 `html-helper-do-write-file-hooks' is t")
|
|
104
|
|
105 ;; control over what types of tags to load. By default, we load all the
|
|
106 ;; ones we know of.
|
|
107
|
|
108 (defvar html-helper-types-to-install
|
|
109 '(anchor header logical phys list textel entity image head form)
|
|
110 "*List of tag types to install when html-helper-mode is first loaded.
|
|
111 If you want to not install some type of tag, override this variable.
|
|
112 Order is significant: menus go in this order.")
|
|
113
|
100
|
114 (defvar html-mode-hook nil
|
|
115 "*Hook called by `html-mode'.")
|
|
116
|
0
|
117 ;;}}} end of user variables
|
|
118 ;;{{{ type based keymap and menu variable and function setup
|
|
119
|
|
120 ;; html-helper-mode has a concept of "type" of tags. Each type is a
|
|
121 ;; list of tags that all go together in one keymap and one menu.
|
|
122 ;; Types can be added to the system after html-helper has been loaded,
|
|
123 ;; briefly by doing html-helper-add-type-to-alist, then
|
|
124 ;; html-helper-install-type, then html-helper-add-tag (for each tag)
|
|
125 ;; then html-helper-rebuild-menu. See the mode documentation for more detail.
|
|
126
|
|
127 (defconst html-helper-type-alist nil
|
|
128 "Alist: type of tag -> keymap, keybinding, menu, menu string.
|
|
129 Add to this with `html-helper-add-type-to-alist'.")
|
|
130
|
|
131 ;;{{{ accessor functions for html-helper-type-alist
|
|
132
|
|
133 (defun html-helper-keymap-for (type)
|
|
134 "Accessor function for alist: for type, return keymap or nil"
|
|
135 (nth 0 (cdr-safe (assq type html-helper-type-alist))))
|
|
136
|
|
137 (defun html-helper-key-for (type)
|
|
138 "Accessor function for alist: for type, return keybinding or nil"
|
|
139 (nth 1 (cdr-safe (assq type html-helper-type-alist))))
|
|
140
|
|
141 (defun html-helper-menu-for (type)
|
|
142 "Accessor function for alist: for type, return menu or nil"
|
|
143 (nth 2 (cdr-safe (assq type html-helper-type-alist))))
|
|
144
|
|
145 (defun html-helper-menu-string-for (type)
|
|
146 "Accessor function for alist: for type, return menustring or nil"
|
|
147 (nth 3 (cdr-safe (assq type html-helper-type-alist))))
|
|
148
|
|
149 (defun html-helper-normalized-menu-for (type)
|
|
150 "Helper function for building menus from submenus: add on string to menu."
|
|
151 (cons (html-helper-menu-string-for type)
|
|
152 (eval (html-helper-menu-for type))))
|
|
153
|
|
154 ;;}}}
|
|
155
|
|
156 (define-derived-mode html-mode sgml-mode "HTML"
|
|
157 "Major mode for editing HTML documents.
|
|
158 This is based on PSGML mode, and has a sophisticated SGML parser in it.
|
|
159 It knows how to properly indent HTML/SGML documents, and it can do
|
70
|
160 a form of document validation (use \\[sgml-next-trouble-spot\\] to find
|
0
|
161 the next error in your document).
|
|
162 Commands beginning with C-z insert various types of HTML tags
|
|
163 (prompting for the required information); to iconify or suspend,
|
|
164 use C-z C-z.
|
|
165 To literally insert special characters such as < and &, use C-c followed
|
|
166 by the character.
|
|
167 Use \\[sgml-insert-end-tag] to insert the proper closing tag.
|
|
168 Use \\[sgml-edit-attributes] to edit the attributes for a tag.
|
|
169 Use \\[sgml-show-context] to show the current HTML context.
|
|
170
|
|
171 More specifically:
|
|
172 \\{html-mode-map}
|
|
173 "
|
|
174 (make-local-variable 'sgml-declaration)
|
|
175 (make-local-variable 'sgml-default-doctype-name)
|
|
176 (setq sgml-declaration (expand-file-name "html.decl"
|
|
177 sgml-data-directory)
|
|
178 sgml-default-doctype-name "html"
|
|
179 sgml-always-quote-attributes t
|
|
180 sgml-indent-step 2
|
|
181 sgml-indent-data t
|
|
182 sgml-inhibit-indent-tags '("pre")
|
|
183 sgml-minimize-attributes nil
|
|
184 sgml-omittag t
|
|
185 sgml-shortag t)
|
|
186
|
|
187 ;; font-lock setup for various emacsen: XEmacs, Emacs 19.29+, Emacs <19.29.
|
|
188 ;; By Ulrik Dickow <dickow@nbi.dk>. (Last update: 05-Sep-1995).
|
|
189 (cond ((string-match "XEmacs\\|Lucid" (emacs-version)) ; XEmacs/Lucid
|
|
190 (put major-mode 'font-lock-keywords-case-fold-search t))
|
|
191 ;; XEmacs (19.13, at least) guesses the rest correctly.
|
|
192 ;; If any older XEmacsen don't, then tell me.
|
|
193 ;;
|
|
194 ((string-lessp "19.28.89" emacs-version) ; Emacs 19.29 and later
|
|
195 (make-local-variable 'font-lock-defaults)
|
|
196 (setq font-lock-defaults '(html-font-lock-keywords t t)))
|
|
197 ;;
|
|
198 (t ; Emacs 19.28 and older
|
|
199 (make-local-variable 'font-lock-keywords-case-fold-search)
|
|
200 (make-local-variable 'font-lock-keywords)
|
|
201 (make-local-variable 'font-lock-no-comments)
|
|
202 (setq font-lock-keywords-case-fold-search t)
|
|
203 (setq font-lock-keywords html-font-lock-keywords)
|
|
204 (setq font-lock-no-comments t)))
|
|
205
|
|
206 (if html-helper-do-write-file-hooks
|
|
207 (add-hook 'local-write-file-hooks 'html-helper-update-timestamp))
|
|
208
|
|
209 (if (and html-helper-build-new-buffer (zerop (buffer-size)))
|
|
210 (html-helper-insert-new-buffer-strings))
|
|
211
|
|
212 (set (make-local-variable 'sgml-custom-markup)
|
|
213 '(("<A>" "<A HREF=\"\">\r</a>")))
|
84
|
214
|
|
215 ;; Set up the syntax table.
|
|
216 (modify-syntax-entry ?< "(>" html-mode-syntax-table)
|
|
217 (modify-syntax-entry ?> ")<" html-mode-syntax-table)
|
|
218 (modify-syntax-entry ?\" ". " html-mode-syntax-table)
|
|
219 (modify-syntax-entry ?\\ ". " html-mode-syntax-table)
|
|
220 (modify-syntax-entry ?' "w " html-mode-syntax-table)
|
|
221
|
0
|
222 ; sigh ... need to call this now to get things working.
|
|
223 (sgml-build-custom-menus)
|
|
224 (add-submenu nil sgml-html-menu "SGML")
|
100
|
225 (delete-menu-item '("SGML"))
|
|
226 (run-hooks 'html-mode-hook))
|
0
|
227
|
|
228 (defun html-helper-add-type-to-alist (type)
|
|
229 "Add a type specification to the alist.
|
|
230 The spec goes (type . (keymap-symbol keyprefix menu-symbol menu-string)).
|
|
231 See code for an example."
|
|
232 (setq html-helper-type-alist (cons type html-helper-type-alist)))
|
|
233
|
|
234 ;; Here are the types provided by html-helper-mode.
|
|
235 (mapcar 'html-helper-add-type-to-alist
|
|
236 '((entity . (nil nil html-helper-entity-menu "Insert Character Entities"))
|
|
237 (textel . (nil nil html-helper-textel-menu "Insert Text Elements"))
|
|
238 (head . (html-helper-head-map "\C-zb" html-helper-head-menu "Insert Structural Elements"))
|
|
239 (header . (html-helper-base-map "\C-z" html-helper-header-menu "Insert Headers"))
|
|
240 (anchor . (html-helper-base-map "\C-z" html-helper-anchor-menu "Insert Hyperlinks"))
|
|
241 (logical . (html-helper-base-map "\C-z" html-helper-logical-menu "Insert Logical Styles"))
|
|
242 (phys . (html-helper-base-map "\C-z" html-helper-phys-menu "Insert Physical Styles"))
|
|
243 (list . (html-helper-list-map "\C-zl" html-helper-list-menu "Insert List Elements"))
|
|
244 (form . (html-helper-form-map "\C-zf" html-helper-form-menu "Insert Form Elements"))
|
|
245 (image . (html-helper-image-map "\C-zm" html-helper-image-menu "Insert Inlined Images"))))
|
|
246
|
|
247 ;; Once html-helper-mode is aware of a type, it can then install the
|
|
248 ;; type: arrange for keybindings, menus, etc.
|
|
249
|
|
250 (defconst html-helper-installed-types nil
|
|
251 "The types that have been installed (used when building menus).
|
|
252 There is no support for removing a type once it has been installed.")
|
|
253
|
|
254 (defun html-helper-install-type (type)
|
|
255 "Install a new tag type: add it to the keymap, menu structures, etc.
|
|
256 For this to work, the type must first have been added to the list of types
|
|
257 with html-helper-add-type-to-alist."
|
|
258 (setq html-helper-installed-types (cons type html-helper-installed-types))
|
|
259 (let ((keymap (html-helper-keymap-for type))
|
|
260 (key (html-helper-key-for type))
|
|
261 (menu (html-helper-menu-for type))
|
|
262 (menu-string (html-helper-menu-string-for type)))
|
|
263 (and key
|
|
264 (progn
|
|
265 (set keymap nil)
|
|
266 (define-prefix-command keymap)
|
|
267 (define-key html-mode-map key keymap)))
|
|
268 (and menu
|
|
269 (progn
|
|
270 (set menu nil)))))
|
|
271
|
|
272 ;; install the default types.
|
|
273 (mapcar 'html-helper-install-type html-helper-types-to-install)
|
|
274
|
|
275 ;;}}}
|
|
276
|
|
277 ;;{{{ html-helper-add-tag function for building basic tags
|
|
278
|
|
279 (defvar html-helper-tempo-tags nil
|
|
280 "List of tags used in completion.")
|
|
281
|
|
282 ;; this while loop is awfully Cish
|
|
283 ;; isn't there an emacs lisp function to do this?
|
|
284 (defun html-helper-string-to-symbol (input-string)
|
|
285 "Given a string, downcase it and replace spaces with -.
|
|
286 We use this to turn menu entries into good symbols for functions.
|
|
287 It's not entirely successful, but fortunately emacs lisp is forgiving."
|
|
288 (let* ((s (copy-sequence input-string))
|
|
289 (l (1- (length s))))
|
|
290 (while (> l 0)
|
|
291 (if (char-equal (aref s l) ?\ )
|
|
292 (aset s l ?\-))
|
|
293 (setq l (1- l)))
|
|
294 (concat "html-" (downcase s))))
|
|
295
|
|
296
|
|
297 (defun html-helper-add-tag (l)
|
|
298 "Add a new tag to html-helper-mode.
|
|
299 Builds a tempo-template for the tag and puts it into the
|
|
300 appropriate keymap if a key is requested. Format:
|
|
301 `(html-helper-add-tag '(type keybinding completion-tag menu-name template doc)'"
|
|
302 (let* ((type (car l))
|
|
303 (keymap (html-helper-keymap-for type))
|
|
304 (menu (html-helper-menu-for type))
|
|
305 (key (nth 1 l))
|
|
306 (completer (nth 2 l))
|
|
307 (name (nth 3 l))
|
|
308 (tag (nth 4 l))
|
|
309 (doc (nth 5 l))
|
|
310 (command (tempo-define-template (html-helper-string-to-symbol name)
|
|
311 tag completer doc
|
|
312 'html-helper-tempo-tags)))
|
|
313
|
|
314 (if (null (memq type html-helper-installed-types)) ;type loaded?
|
|
315 t ;no, do nothing.
|
|
316 (if (stringp key) ;bind key somewhere?
|
|
317 (if keymap ;special keymap?
|
|
318 (define-key (eval keymap) key command) ;t: bind to prefix
|
|
319 (define-key html-mode-map key command)) ;nil: bind to global
|
|
320 t)
|
|
321 (if menu ;is there a menu?
|
|
322 (set menu ;good, cons it in
|
|
323 (cons (vector name command t) (eval menu))))
|
|
324 )))
|
|
325
|
|
326 ;;}}}
|
|
327
|
|
328 ;;{{{ most of the HTML tags
|
|
329
|
|
330 ;; These tags are an attempt to be HTML/2.0 compliant, with the exception
|
|
331 ;; of container <p>, <li>, <dd>, <dt> (we adopt 3.0 behaviour).
|
|
332 ;; For reference see <URL:http://www.w3.org/hypertext/WWW/MarkUp/MarkUp.html>
|
|
333
|
|
334 ;; order here is significant: within a tag type, menus and mode help
|
|
335 ;; go in the reverse order of what you see here. Sorry about that, it's
|
|
336 ;; not easy to fix.
|
|
337
|
|
338 (mapcar
|
|
339 'html-helper-add-tag
|
|
340 '(
|
|
341 ;;entities
|
|
342 (entity "\C-c#" "&#" "Ascii Code" ("&#" (r "Ascii: ") ";"))
|
|
343 (entity "\C-c\"" """ "Quotation mark" ("""))
|
|
344 (entity "\C-c$" "®" "Registered" ("®"))
|
|
345 (entity "\C-c@" "©" "Copyright" ("©"))
|
|
346 (entity "\C-c-" "­" "Soft Hyphen" ("­"))
|
|
347 (entity "\C-c " " " "Nonbreaking Space" (" "))
|
|
348 (entity "\C-c&" "&" "Ampersand" ("&"))
|
|
349 (entity "\C-c>" ">" "Greater Than" (">"))
|
|
350 (entity "\C-c<" "<" "Less Than" ("<"))
|
|
351
|
|
352 ;; logical styles
|
|
353 (logical "q" "<blockquote>" "Blockquote" ("<blockquote>" (r "Quote: ") "</blockquote>"))
|
|
354 (logical "c" "<code>" "Code" ("<code>" (r "Code: ") "</code>"))
|
|
355 (logical "x" "<samp>" "Sample" ("<samp>" (r "Sample code") "</samp>"))
|
|
356 (logical "r" "<cite>" "Citation" ("<cite>" (r "Citation: ") "</cite>"))
|
|
357 (logical "k" "<kbd>" "Keyboard Input" ("<kbd>" (r "Keyboard: ") "</kbd>"))
|
|
358 (logical "v" "<var>" "Variable" ("<var>" (r "Variable: ") "</var>"))
|
|
359 (logical "d" "<dfn>" "Definition" ("<dfn>" (r "Definition: ") "</dfn>"))
|
|
360 (logical "a" "<address>" "Address" ("<address>" r "</address>"))
|
|
361 (logical "e" "<em>" "Emphasized" ("<em>" (r "Text: ") "</em>"))
|
|
362 (logical "s" "<strong>" "Strong" ("<strong>" (r "Text: ") "</strong>"))
|
|
363 (logical "p" "<pre>" "Preformatted" ("<pre>" (r "Text: ") "</pre>"))
|
|
364
|
|
365 ;;physical styles
|
|
366 (phys "-" "<strike>" "Strikethru" ("<strike>" (r "Text: ") "</strike>"))
|
|
367 (phys "u" "<u>" "Underline" ("<u>" (r "Text: ") "</u>"))
|
|
368 (phys "o" "<i>" "Italic" ("<i>" (r "Text: ") "</i>"))
|
|
369 (phys "b" "<b>" "Bold" ("<b>" (r "Text: ") "</b>"))
|
|
370 (phys "t" "<tt>" "Fixed" ("<tt>" (r "Text: ") "</tt>"))
|
|
371
|
|
372 ;;headers
|
|
373 (header "6" "<h6>" "Header 6" ("<h6>" (r "Header: ") "</h6>"))
|
|
374 (header "5" "<h5>" "Header 5" ("<h5>" (r "Header: ") "</h5>"))
|
|
375 (header "4" "<h4>" "Header 4" ("<h4>" (r "Header: ") "</h4>"))
|
|
376 (header "3" "<h3>" "Header 3" ("<h3>" (r "Header: ") "</h3>"))
|
|
377 (header "2" "<h2>" "Header 2" ("<h2>" (r "Header: ") "</h2>"))
|
|
378 (header "1" "<h1>" "Header 1" ("<h1>" (r "Header: ") "</h1>"))
|
|
379
|
|
380 ;; forms
|
|
381 (form "o" "<option>" "Option" (& "<option>" > ))
|
|
382 (form "v" "<option value" "Option with Value" (& "<option value=\"" (r "Value: ") "\">" >))
|
|
383 (form "s" "<select" "Selections" ("<select name=\"" (p "Name: ") "\">\n<option>" > "\n</select>")"<select")
|
|
384 (form "z" "<input" "Reset Form" ("<input type=\"RESET\" value=\"" (p "Reset button text: ") "\">"))
|
|
385 (form "b" "<input" "Submit Form" ("<input type=\"SUBMIT\" value=\"" (p "Submit button text: ") "\">"))
|
|
386 (form "i" "<input" "Image Field" ("<input type=\"IMAGE\" name=\"" (p "Name: ") "\" src=\"" (p "Image URL: ") "\">"))
|
|
387 (form "h" "<input" "Hidden Field" ("<input type=\"HIDDEN\" name=\"" (p "Name: ") "\" value=\"" (p "Value: ") "\">"))
|
|
388 (form "p" "<textarea" "Text Area" ("<textarea name=\"" (p "Name: ") "\" rows=\"" (p "Rows: ") "\" cols=\"" (p "Columns: ") "\">" r "</textarea>"))
|
|
389 (form "c" "<input" "Checkbox" ("<input type=\"CHECKBOX\" name=\"" (p "Name: ") "\">"))
|
|
390 (form "r" "<input" "Radiobutton" ("<input type=\"RADIO\" name=\"" (p "Name: ") "\">"))
|
|
391 (form "t" "<input" "Text Field" ("<input type=\"TEXT\" name=\"" (p "Name: ") "\" size=\"" (p "Size: ") "\">"))
|
|
392 (form "f" "<form" "Form" ("<form action=\"" (p "Action: ") "\" method=\"" (p "Method: ") "\">\n</form>\n"))
|
|
393
|
|
394 ;;lists
|
|
395 (list "t" "<dt>" "Definition Item" (& "<dt>" > (p "Term: ") "\n<dd>" > (r "Definition: ")))
|
|
396 (list "l" "<li>" "List Item" (& "<li>" > (r "Item: ")))
|
|
397 (list "r" "<dir>" "DirectoryList" (& "<dir>" > "\n<li>" > (r "Item: ") "\n</dir>" >))
|
|
398 (list "m" "<menu>" "Menu List" (& "<menu>" > "\n<li>" > (r "Item: ") "\n</menu>" >))
|
|
399 (list "o" "<ol>" "Ordered List" (& "<ol>" > "\n<li>" > (r "Item: ") "\n</ol>" >))
|
|
400 (list "d" "<dl>" "Definition List" (& "<dl>" > "\n<dt>" > (p "Term: ") "\n<dd>" > (r "Definition: ") "\n</dl>" >))
|
|
401 (list "u" "<ul>" "Unordered List" (& "<ul>" > "\n<li>" > (r "Item: ") "\n</ul>" >))
|
|
402
|
|
403 ;;anchors
|
|
404 (anchor "n" "<a name=" "Link Target" ("<a name=\"" (p "Anchor name: ") "\">" (r "Anchor text: ") "</a>"))
|
|
405 (anchor "h" "<a href=" "Hyperlink" ("<a href=\"" (p "URL: ") "\">" (r "Anchor text: ") "</a>"))
|
|
406
|
|
407 ;;graphics
|
|
408 (image "a" nil "Aligned Image" ("<img align=\"" (r "Alignment: ") "\" src=\"" (r "Image URL: ") "\">"))
|
|
409 (image "i" "<img src=" "Image" ("<img src=\"" (r "Image URL: ") "\">"))
|
|
410 (image "e" "<img align=" "Aligned Image With Alt. Text" ("<img align=\"" (r "Alignment: ") "\" src=\"" (r "Image URL: ") "\" alt=\"" (r "Text URL: ") "\">"))
|
|
411 (image "t" "<img alt=" "Image With Alternate Text" ("<img alt=\"" (r "Text URL: ") "\" src=\"" (r "Image URL: ") "\">"))
|
|
412
|
|
413 ;;text elements
|
|
414 (textel "\C-c=" nil "Horizontal Line" (& "<hr>\n"))
|
|
415 (textel "\C-c\C-m" nil "Line Break" ("<br>\n"))
|
|
416 (textel "\e\C-m" nil "Paragraph" ("<p>" (progn (sgml-indent-line) nil) "\n"))
|
|
417
|
|
418 ;;head elements
|
|
419 (head "H" "<head>" "Head" ("<head>\n" "</head>\n"))
|
|
420 (head "B" "<body>" "Body" ("<body>\n" "</body>\n"))
|
|
421 (head "i" "<isindex>" "Isindex" ("<isindex>\n"))
|
|
422 (head "n" "<nextid>" "Nextid" ("<nextid>\n"))
|
|
423 (head "h" "<meta http-equiv=" "HTTP Equivalent" ("<meta http-equiv=\"" (p "Equivalent: ") "\" content=\"" (r "Content: ") "\">\n"))
|
|
424 (head "m" "<meta name=" "Meta Name" ("<meta name=\"" (p "Name: ") "\" content=\"" (r "Content: ") "\">\n"))
|
|
425 (head "l" "<link" "Link" ("<link href=\"" p "\">"))
|
|
426 (head "b" "<base" "Base" ("<base href=\"" r "\">"))
|
|
427 (head "t" "<title>" "Title" ("<title>" (r "Document title: ") "</title>"))
|
|
428 ))
|
|
429
|
|
430 ;;}}}
|
|
431 ;;{{{ html-helper-smart-insert-item
|
|
432
|
|
433 ;; there are two different kinds of items in HTML - those in regular
|
|
434 ;; lists <li> and those in dictionaries <dt>..<dd>
|
|
435 ;; This command will insert the appropriate one depending on context.
|
|
436
|
|
437 (defun html-helper-smart-insert-item (&optional arg)
|
|
438 "Insert a new item, either in a regular list or a dictionary."
|
|
439 (interactive "*P")
|
|
440 (let ((case-fold-search t))
|
|
441 (if
|
|
442 (save-excursion
|
|
443 (re-search-backward "<li>\\|<dt>\\|<ul>\\|<ol>\\|<dd>\\|<menu>\\|<dir>\\|<dl>" nil t)
|
|
444 (looking-at "<dt>\\|<dl>\\|<dd>"))
|
|
445 (tempo-template-html-definition-item arg)
|
|
446 (tempo-template-html-list-item arg))))
|
|
447
|
|
448 ;; special keybindings in the prefix maps (not in the list of tags)
|
|
449 (and (boundp 'html-helper-base-map)
|
|
450 (define-key html-helper-base-map "i" 'html-helper-smart-insert-item))
|
|
451
|
|
452 (define-key html-mode-map "\C-z\C-z" 'suspend-or-iconify-emacs)
|
|
453 (define-key html-mode-map "\C-zg" 'html-insert-mailto-reference-from-click)
|
|
454
|
|
455 ;; and, special menu bindings
|
|
456 (and (boundp 'html-helper-list-menu)
|
|
457 (setq html-helper-list-menu
|
|
458 (cons '["List Item" html-helper-smart-insert-item t] html-helper-list-menu)))
|
|
459
|
|
460 ;;}}}
|
|
461 ;;{{{ patterns for font-lock
|
|
462
|
|
463 ; Old patterns from html-mode.el
|
|
464 ;(defvar html-font-lock-keywords
|
|
465 ; (list
|
|
466 ; '("\\(<[^>]*>\\)+" . font-lock-comment-face)
|
|
467 ; '("[Hh][Rr][Ee][Ff]=\"\\([^\"]*\\)\"" 1 font-lock-string-face t)
|
|
468 ; '("[Ss][Rr][Cc]=\"\\([^\"]*\\)\"" 1 font-lock-string-face t))
|
|
469 ; "Patterns to highlight in HTML buffers.")
|
|
470
|
|
471 ;; By Ulrik Dickow <dickow@nbi.dk>.
|
|
472 ;;
|
|
473 ;; Originally aimed at Emacs 19.29. Later on disabled syntactic fontification
|
|
474 ;; and reordered regexps completely, to be compatible with XEmacs (it doesn't
|
|
475 ;; understand OVERRIDE=`keep').
|
|
476 ;;
|
|
477 ;; We make an effort on handling nested tags intelligently.
|
|
478
|
|
479 ;; font-lock compatibility with XEmacs/Lucid and older Emacsen (<19.29).
|
|
480 ;;
|
|
481 (if (string-match "XEmacs\\|Lucid" (emacs-version))
|
|
482 ;; XEmacs/Lucid
|
|
483 ;; Make needed faces if the user hasn't already done so.
|
|
484 ;; Respect X resources (`make-face' uses them when they exist).
|
|
485 (let ((change-it
|
|
486 (function (lambda (face)
|
|
487 (or (if (fboundp 'facep)
|
|
488 (facep face)
|
|
489 (memq face (face-list)))
|
|
490 (make-face face))
|
|
491 (not (face-differs-from-default-p face))))))
|
|
492 (if (funcall change-it 'html-helper-bold-face)
|
|
493 (copy-face 'bold 'html-helper-bold-face))
|
|
494 (if (funcall change-it 'html-helper-italic-face)
|
|
495 (copy-face 'italic 'html-helper-italic-face))
|
|
496 (if (funcall change-it 'html-helper-underline-face)
|
|
497 (set-face-underline-p 'html-helper-underline-face t))
|
|
498 (if (funcall change-it 'font-lock-variable-name-face)
|
|
499 (set-face-foreground 'font-lock-variable-name-face "salmon"))
|
|
500 (if (funcall change-it 'font-lock-reference-face)
|
|
501 (set-face-foreground 'font-lock-reference-face "violet")))
|
|
502 ;; Emacs (any version)
|
|
503 ;;
|
|
504 ;; Note that Emacs evaluates the face entries in `font-lock-keywords',
|
|
505 ;; while XEmacs doesn't. So XEmacs doesn't use the following *variables*,
|
|
506 ;; but instead the faces with the same names as the variables.
|
|
507 (defvar html-helper-bold-face 'bold
|
|
508 "Face used as bold. Typically `bold'.")
|
|
509 (defvar html-helper-italic-face 'italic
|
|
510 "Face used as italic. Typically `italic'.")
|
|
511 (defvar html-helper-underline-face 'underline
|
|
512 "Face used as underline. Typically `underline'.")
|
|
513 ;;
|
|
514 (if (string-lessp "19.28.89" emacs-version)
|
|
515 () ; Emacs 19.29 and later
|
|
516 ;; Emacs 19.28 and older
|
|
517 ;; Define face variables that don't exist until Emacs 19.29.
|
|
518 (defvar font-lock-variable-name-face 'font-lock-doc-string-face
|
|
519 "Face to use for variable names -- and some HTML keywords.")
|
|
520 (defvar font-lock-reference-face 'underline ; Ugly at line breaks
|
|
521 "Face to use for references -- including HTML hyperlink texts.")))
|
|
522
|
|
523 (defvar html-font-lock-keywords
|
|
524 (let (;; Titles and H1's, like function defs.
|
|
525 ;; We allow for HTML 3.0 attributes, like `<h1 align=center>'.
|
|
526 (tword "\\(h1\\|title\\)\\([ \t\n]+[^>]+\\)?")
|
|
527 ;; Names of tags to boldify.
|
|
528 (bword "\\(b\\|h[2-4]\\|strong\\)\\([ \t\n]+[^>]+\\)?")
|
|
529 ;; Names of tags to italify.
|
|
530 (iword "\\(address\\|cite\\|em\\|i\\|var\\)\\([ \t\n]+[^>]+\\)?")
|
|
531 ;; Regexp to match shortest sequence that surely isn't a bold end.
|
|
532 ;; We simplify a bit by extending "</strong>" to "</str.*".
|
|
533 ;; Do similarly for non-italic and non-title ends.
|
|
534 (not-bend (concat "\\([^<]\\|<\\([^/]\\|/\\([^bhs]\\|"
|
|
535 "b[^>]\\|"
|
|
536 "h\\([^2-4]\\|[2-4][^>]\\)\\|"
|
|
537 "s\\([^t]\\|t[^r]\\)\\)\\)\\)"))
|
|
538 (not-iend (concat "\\([^<]\\|<\\([^/]\\|/\\([^aceiv]\\|"
|
|
539 "a\\([^d]\\|d[^d]\\)\\|"
|
|
540 "c\\([^i]\\|i[^t]\\)\\|"
|
|
541 "e\\([^m]\\|m[^>]\\)\\|"
|
|
542 "i[^>]\\|"
|
|
543 "v\\([^a]\\|a[^r]\\)\\)\\)\\)"))
|
|
544 (not-tend (concat "\\([^<]\\|<\\([^/]\\|/\\([^ht]\\|"
|
|
545 "h[^1]\\|t\\([^i]\\|i[^t]\\)\\)\\)\\)")))
|
|
546 (list ; Avoid use of `keep', since XEmacs will treat it the same as `t'.
|
|
547 ;; First fontify the text of a HREF anchor. It may be overridden later.
|
|
548 ;; Anchors in headings will be made bold, for instance.
|
|
549 '("<a\\s-+href[^>]*>\\([^>]+\\)</a>"
|
|
550 1 font-lock-reference-face t)
|
|
551 ;; Tag pairs like <b>...</b> etc.
|
|
552 ;; Cunning repeated fontification to handle common cases of overlap.
|
|
553 ;; Bold complex --- possibly with arbitrary other non-bold stuff inside.
|
|
554 (list (concat "<" bword ">\\(" not-bend "*\\)</\\1>")
|
|
555 3 'html-helper-bold-face t)
|
|
556 ;; Italic complex --- possibly with arbitrary non-italic kept inside.
|
|
557 (list (concat "<" iword ">\\(" not-iend "*\\)</\\1>")
|
|
558 3 'html-helper-italic-face t)
|
|
559 ;; Bold simple --- first fontify bold regions with no tags inside.
|
|
560 (list (concat "<" bword ">\\(" "[^<]" "*\\)</\\1>")
|
|
561 3 'html-helper-bold-face t)
|
|
562 ;; Any tag, general rule, just after bold/italic stuff.
|
|
563 '("\\(<[^>]*>\\)" 1 font-lock-type-face t)
|
|
564 ;; Titles and level 1 headings (anchors do sometimes appear in h1's)
|
|
565 (list (concat "<" tword ">\\(" not-tend "*\\)</\\1>")
|
|
566 3 'font-lock-function-name-face t)
|
|
567 ;; Underline is rarely used. Only handle it when no tags inside.
|
|
568 '("<u>\\([^<]*\\)</u>" 1 html-helper-underline-face t)
|
|
569 ;; Forms, anchors & images (also fontify strings inside)
|
|
570 '("\\(<\\(form\\|i\\(mg\\|nput\\)\\)\\>[^>]*>\\)"
|
|
571 1 font-lock-variable-name-face t)
|
|
572 '("</a>" 0 font-lock-keyword-face t)
|
|
573 '("\\(<a\\b[^>]*>\\)" 1 font-lock-keyword-face t)
|
|
574 '("=[ \t\n]*\\(\"[^\"]+\"\\)" 1 font-lock-string-face t)
|
|
575 ;; Large-scale structure keywords (like "program" in Fortran).
|
|
576 ;; "<html>" "</html>" "<body>" "</body>" "<head>" "</head>" "</form>"
|
|
577 '("</?\\(body\\|form\\|h\\(ead\\|tml\\)\\)>"
|
|
578 0 font-lock-variable-name-face t)
|
|
579 ;; HTML special characters
|
|
580 '("&[^;\n]*;" 0 font-lock-string-face t)
|
|
581 ;; SGML things like <!DOCTYPE ...> with possible <!ENTITY...> inside.
|
|
582 '("\\(<![a-z]+\\>[^<>]*\\(<[^>]*>[^<>]*\\)*>\\)"
|
|
583 1 font-lock-comment-face t)
|
|
584 ;; Comments: <!-- ... -->. They traditionally override anything else.
|
|
585 ;; It's complicated 'cause we won't allow "-->" inside a comment, and
|
|
586 ;; font-lock colours the *longest* possible match of the regexp.
|
|
587 '("\\(<!--\\([^-]\\|-[^-]\\|--[^>]\\)*-->\\)"
|
|
588 1 font-lock-comment-face t)))
|
|
589 "Additional expressions to highlight in HTML mode.")
|
|
590
|
|
591 (put 'html-mode 'font-lock-defaults '(html-font-lock-keywords))
|
|
592 (put 'html3-mode 'font-lock-defaults '(html-font-lock-keywords))
|
|
593
|
|
594 ;;}}}
|
|
595
|
|
596 ;;{{{ patterns for hilit19
|
|
597
|
|
598 ;; Define some useful highlighting patterns for the hilit19 package.
|
|
599 ;; These will activate only if hilit19 has already been loaded.
|
|
600 ;; Thanks to <dickow@nbi.dk> for some pattern suggestions
|
|
601
|
|
602 (if (featurep 'hilit19)
|
|
603 (hilit-set-mode-patterns
|
|
604 'html-helper-mode
|
|
605 '(("<!--" "-->" comment)
|
|
606 ("<![a-z]+\\>[^<>]*\\(<[^>]*>[^<>]*\\)*>" nil comment) ;<!DOCTYPE ...>
|
|
607 ("<title>" "</title>" defun)
|
|
608 ("<h[1-6]>" "</h[1-6]>" bold) ;only colour inside tag
|
|
609 ("<a\\b" ">" define)
|
|
610 ("</a>" nil define)
|
|
611 ("<img\\b" ">" include)
|
|
612 ("<option\\|</?select\\|<input\\|</?form\\|</?textarea" ">" include)
|
|
613 ;; First <i> highlighting just handles unnested tags, then do nesting
|
|
614 ("<i>[^<]*</i>" nil italic)
|
|
615 ("<b>" "</b>" bold)
|
|
616 ("<i>" "</i>" italic)
|
|
617 ("<u>" "</u>" underline)
|
|
618 ("&[^;\n]*;" nil string)
|
|
619 ("<" ">" keyword))
|
|
620 nil 'case-insensitive)
|
|
621 nil)
|
|
622
|
|
623 ;;}}}
|
|
624
|
|
625 ;;{{{ timestamps
|
|
626
|
|
627 (defun html-helper-update-timestamp ()
|
|
628 "Basic function for updating timestamps.
|
|
629 It finds the timestamp in the buffer by looking for
|
|
630 `html-helper-timestamp-start', deletes all text up to
|
|
631 `html-helper-timestamp-end', and runs `html-helper-timestamp-hook' which
|
|
632 will should insert an appropriate timestamp in the buffer."
|
|
633 (save-excursion
|
|
634 (goto-char (point-max))
|
|
635 (if (not (search-backward html-helper-timestamp-start nil t))
|
|
636 (message "timestamp delimiter start was not found")
|
|
637 (let ((ts-start (+ (point) (length html-helper-timestamp-start)))
|
|
638 (ts-end (if (search-forward html-helper-timestamp-end nil t)
|
|
639 (- (point) (length html-helper-timestamp-end))
|
|
640 nil)))
|
|
641 (if (not ts-end)
|
|
642 (message "timestamp delimiter end was not found. Type C-c C-t to insert one.")
|
|
643 (delete-region ts-start ts-end)
|
|
644 (goto-char ts-start)
|
|
645 (run-hooks 'html-helper-timestamp-hook)))))
|
|
646 nil)
|
|
647
|
|
648 (defun html-helper-return-created-string ()
|
|
649 "Return a \"Created:\" string."
|
|
650 (let ((time (current-time-string)))
|
|
651 (concat "<!-- Created: "
|
|
652 (substring time 0 20)
|
|
653 (nth 1 (current-time-zone))
|
|
654 " "
|
|
655 (substring time -4)
|
|
656 " -->\n")))
|
|
657
|
|
658 (defun html-helper-default-insert-timestamp ()
|
|
659 "Default timestamp insertion function."
|
|
660 (let ((time (current-time-string)))
|
|
661 (insert "Last modified: "
|
|
662 (substring time 0 20)
|
|
663 (nth 1 (current-time-zone))
|
|
664 " "
|
2
|
665 (substring time -4)
|
0
|
666 "\n")))
|
|
667
|
|
668 (defun html-helper-insert-timestamp-delimiter-at-point ()
|
|
669 "Simple function that inserts timestamp delimiters at point.
|
|
670 Useful for adding timestamps to existing buffers."
|
|
671 (interactive)
|
|
672 (insert html-helper-timestamp-start)
|
|
673 (insert html-helper-timestamp-end))
|
|
674
|
|
675 ;;}}}
|
|
676
|
|
677 (defun mail-address-at-point (pos &optional buffer)
|
|
678 "Return a list (NAME ADDRESS) of the address at POS in BUFFER."
|
|
679 (or buffer (setq buffer (current-buffer)))
|
|
680 (let (beg end)
|
|
681 (save-excursion
|
|
682 (set-buffer buffer)
|
|
683 (save-excursion
|
|
684 (goto-char pos)
|
|
685 (or (re-search-forward "[\n,]" nil t)
|
|
686 (error "Can't find address at position"))
|
|
687 (backward-char)
|
|
688 (setq end (point))
|
|
689 (or (re-search-backward "[\n,:]" nil t)
|
|
690 (error "Can't find address at position"))
|
|
691 (forward-char)
|
|
692 (re-search-forward "[ \t]*" nil t)
|
|
693 (setq beg (point))
|
|
694 (mail-extract-address-components (buffer-substring beg end))))))
|
|
695
|
|
696 (defun html-insert-mailto-reference-from-click ()
|
|
697 "Insert a mailto: reference for the clicked-on e-mail address."
|
|
698 (interactive)
|
|
699 (let (event)
|
|
700 (message "Click on a mail address:")
|
|
701 (save-excursion
|
|
702 (setq event (next-command-event))
|
|
703 (or (mouse-event-p event)
|
|
704 (error "Aborted.")))
|
|
705 (let ((lis (mail-address-at-point (event-closest-point event)
|
|
706 (event-buffer event))))
|
|
707 (insert "<a href=\"mailto:" (car (cdr lis)) "\">"
|
|
708 (or (car lis) (car (cdr lis))) "</a>"))))
|
|
709
|
|
710 (defun html-quote-region (begin end)
|
|
711 "\"Quote\" any characters in the region that have special HTML meanings.
|
|
712 This converts <'s, >'s, and &'s into the HTML commands necessary to
|
|
713 get those characters to appear literally in the output."
|
|
714 (interactive "r")
|
|
715 (save-excursion
|
|
716 (goto-char begin)
|
|
717 (while (search-forward "&" end t)
|
|
718 (forward-char -1)
|
|
719 (delete-char 1)
|
|
720 (insert "&"))
|
|
721 (goto-char begin)
|
|
722 (while (search-forward "<" end t)
|
|
723 (forward-char -1)
|
|
724 (delete-char 1)
|
|
725 (insert "<"))
|
|
726 (goto-char begin)
|
|
727 (while (search-forward ">" end t)
|
|
728 (forward-char -1)
|
|
729 (delete-char 1)
|
|
730 (insert ">"))))
|
|
731
|
|
732 ;;{{{ html-helper-insert-new-buffer-strings
|
|
733
|
|
734 (tempo-define-template "html-skeleton" html-helper-new-buffer-template
|
|
735 nil
|
|
736 "Insert a skeleton for a HTML document")
|
|
737
|
|
738 (defun html-helper-insert-new-buffer-strings ()
|
|
739 "Insert `html-helper-new-buffer-strings'."
|
|
740 (tempo-template-html-skeleton))
|
|
741
|
|
742 ;;}}}
|
|
743
|
|
744 ;;;###autoload
|
|
745 (autoload 'html-mode "psgml-html" "HTML mode." t)
|
|
746
|
|
747 ;;;###autoload
|
|
748 (autoload 'html3-mode "psgml-html" "HTML3 mode." t)
|
|
749
|
|
750 (defvar sgml-html-menu
|
|
751 (cons "HTML"
|
|
752 (append '(["View in Netscape" sgml-html-netscape-file
|
|
753 (buffer-file-name
|
|
754 (current-buffer))]
|
|
755 ["View in W3" w3-preview-this-buffer t]
|
|
756 "---"
|
|
757 ["HTML-Quote Region" html-quote-region t]
|
|
758 "---")
|
2
|
759 (cdr sgml-main-menu))))
|
0
|
760
|
|
761 (defun sgml-html-netscape-file ()
|
|
762 "Preview the file for the current buffer in Netscape."
|
|
763 (interactive)
|
|
764 (highlight-headers-follow-url-netscape
|
|
765 (concat "file:" (buffer-file-name (current-buffer)))))
|
|
766
|
|
767 (define-derived-mode html3-mode html-mode "HTML3"
|
|
768 (setq sgml-declaration (expand-file-name "html3.decl"
|
|
769 sgml-data-directory)
|
|
770 sgml-default-doctype-name "html-3"
|
|
771 sgml-shortag nil ))
|
|
772
|