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