HTML helper mode now supports the ability to add new tags, override existing tags, or add entire new classes of tags after the mode is loaded. You don't have to modify the sources anymore! This is a great convenience for adding in your favourite extensions to HTML 2.0, your own special macros, or overriding some tags that are currently in the mode. It is helpful to know something about lisp to extend the mode, but if you don't and you're patient you can probably figure it out from the examples.
I have a simple test module that is
well commented and describes how to extend HTML helper mode to add
a new tag in an existing type, override an existing tag, and add an
entire new type into the mode. The
user contributed tags page will have
useful examples. The
mode itself also uses these same
functions to construct the tags it uses, but my fondness
for mapcar might make the code a bit confusing to read.
The core of HTML helper mode mode is the function
html-helper-add-tag: this adds a new HTML tag with a tag
type, a keybinding, a template, a completion string, and an expert menu
definition. Here is an example:
(html-helper-add-tag
'(phys "c" "<center>" "Center" ("<center>" (r "Text:") "</center>")))
This creates a new tag of type "phys" (more on that in a minute)
that inserts the text
<center></center>
when the key C-cC-pc or the menu item "Center"
is used. It completes on the string <center>.
The general form for html-helper-add-tag is
(html-helper-add-tag '(type keybinding completion-string menu-name template))
tempo-define-template, or just copy the examples here and in
html-helper-mode.
Each tag in HTML helper mode is a member of some "type": types are an attempt at grouping all the HTML tags into some logical structure. Each type of tag is associated with a keymap prefix and a submenu (that is how the prefix C-cC-p was associated to the <center> tag mentioned above.) Install a new type only if you're really supporting a whole new realm of HTML markup.
Before defining tags in a type, the type itself must be defined
using html-helper-add-type-to-alist. Here is
an example of definining a new type:
(html-helper-add-type-to-alist
'(phys . (html-helper-phys-map "\C-c\C-p" html-helper-phys-menu "Insert Physical Styles")))
This creates a new tag type called "phys", with a key prefix of
\C-c\C-p and a menu title of "Insert Physical Styles".
The general form of html-helper-add-type-to-alist is
(html-helper-add-type-to-alist
'(type . (keymap-var keymap-entry menu-var menu-name")))
After a type is defined in the mode, it also has to be installed to make it visible. This is done via the function html-helper-install-type
(html-helper-install-type 'phys)
HTML helper mode already has a few types used in the mode. If you're truly defining a new type of tag you should create your own type with its own keybinding. But if you're just augmenting an existing type, you can simply add to one of these. In any case you should be careful not to clobber existing keybindings unless you mean to. Don't forget, C-cC-z is also bound to special mode functions.
Type Key Prefix Menu Name ---- ---------- -------------------------- entity none Insert Character Entitites textel none Insert Text Elements head C-cC-b Insert Structural Elements header C-cC-t Insert Headers anchor C-cC-a Insert Hyperlinks logical C-cC-s Insert Logical Styles phys C-cC-p Insert Physical Styles list C-cC-l Insert List Elements form C-cC-f Insert Form Elements image C-cC-i Insert Inlined Images
Once a type is installed, you get the keybindings and menu entries for free. But you have to force HTML helper mode to rebuild its menus to show all the new tags that have been defined. This is done by executing
(html-helper-rebuild-menu)