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