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