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