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