Adding new tags to HTML helper mode

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.


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.


About Tags

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))
type
the type of tag: more information is below.
keybinding
The key to bind the new tag to. This keybinding is relative to the prefix map implied by the type: if the type has no prefix map, then the keybinding is to html-helper-mode-map.
completion-string
the most explicit substring to use when doing completion. It is generally the opening part of the HTML tag.
menu-name
the name to put in the menu. It should be a short descriptive bit of text about what you're inserting, see existing menus for stylistic examples. (This string is also used to produce the symbol for the command. You shouldn't have to worry about that.)
template
the strings to insert: for more information on templates, see the documentation in tempo.el for tempo-define-template, or just copy the examples here and in html-helper-mode.


About Types

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.

html-helper-add-type-to-alist

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")))
type
This is the symbol for your new type.
keymap-var and menu-var
These are symbols used to hold the keymap and menu. I recommend html-helper-<type>-map and html-helper-<type>-menu, respectively.
keymap-entry
The key to bind your new type to. Emacs convention dictates this be C-cC-letter. If this variable is nil, then all tags of that type are bound to the html-helper-mode-map.
menu-name
The name to put in the menu. I recommend "Insert <descriptive text>".

html-helper-install-type

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)

Existing Types

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

Installing Menus

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)


Nelson Minar <nelson@santafe.edu>
Last modified: Thu Feb 22 15:23:49 MST 1996