[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1. Overview

Tempo is a package that provides writers and users of Emacs editing modes with functions for creating and inserting templates into an Emacs buffer in a convenient way. The template insertion commands can be bound to keys or can be automatically expanded from words written in the buffer.

1.1 A short example  Example
1.2 Tempo basics  
1.3 Tag lists and automatic completion  

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 A short example

A good way to get a general idea of what tempo is about is through an introductory example. The follwoing short example of a tempo template builds a template for inserting a for loop in a C program.

(tempo-define-template "c-for"
                       '("for ("
                         (p "Initialization: ") ","
                         (p "Increment: ") ","
                         (p "End condition: ") " {" n>
                         r n>
                         "}" > %))

This creates a command tempo-template-c-for which, when executed, inserts the following at the point:

for (-!-,,) {

The point is placed at the -!-, which is not included in the text. The command M-x tempo-forward-mark will, at this point, move the point to after the first comma. Successive executions will move the point to after the second comma, to the second line and to after the closing brace. In a mode customized for tempo, tempo-forward-mark will of course be bound to some convenient keystroke combination.

If the variable tempo-interactive was set to non-nil, the result would have been a little different. Instead of inserting nothing inside the parenthesis, the user would be prompted for the text to be written in the three positions, with the prompt strings `Initialization:', `Increment:' and `End condition:', respectively, and the point would be placed on the second line, properly indented.

Also, if there was a currently active region (see section `The Mark and the Region' in the GNU Emacs Manual), and the template command was used with a prefix argument (such as C-u M-x tempo-template-c-for) the for loop would be inserted around the region, so that the contents of the region would be placed between the the opening and closing braces.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 Tempo basics

The most inportant function in tempo is tempo-define-template, which defines a template, together with a function to insert it. See section 2.1 Template syntax, for a complete description of this function.

A simple definition has the form

(tempo-define-template name elements)

When this is evaluated, the variable tempo-template-name is bound to elements, and the function tempo-template-name is a command that will insert the template when invoked.

The elements is supplied as a list whose elements have different meanings. Strings are simply inserted and lisp expressions are evaluated to strings. There are also some symbols with special meanings, such as:

(p prompt [name])
The symbol p marks a "hot spot" in a template. When this is encountered, the current position of the point is saved as a marker and saved on the tempo-marks list. These marks can later easily be jumped to with the functions tempo-forward-mark and tempo-backward-mark.

If the form (p prompt) is used, and the variable tempo-interactive is non-nil, prompt is used to prompt the user for a string in the minibuffer. If tempo-interactive is nil, it works just like a single p.

(r prompt)
This works very much like p, but when the template was invoked with a prefix (as with C-u template-cmd) and a region is active, the template will be wrapped around the region, so that the text of the region is placed where the r element is.

A greater-than sign in a template means that the current line should be indented according to the current mode. The function indent-line is called, which usually gives the desired result. not that often it is advisable to insert the > after the text to be put on the line, to help the indention function.

There are many more thing you can put in a template, but the above are some of the more essential. See section 2.2 Template elements, for a full description of the possible template elements.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 Tag lists and automatic completion

If you supply a third argument tag to tempo-define-template, it can be used as an abbrevation for the template. If you gave the C for-loop in the example above a third argument "for", you could use the completion capabilities in tempo. If you write in a buffer (with the point at -!-):


and type M-x tempo-complete-tag, the string `foo' would be replaced by the for-loop template. For this to be really useful, tempo-complete-tag should be bound to a convenient keystroke. But there is more power in this command. If you have defined a template with the tag `procedure' you can hit M-x tempo-complete-tag as soon as you have written a unique prefix of the word. For example


could expand to

procedure -!-();


when you type M-x tempo-complete-tag had you defined a Pascal procedure template with the tag `procedure'. If there is no unique match, tempo-complete-tag will complete the tag as much as possible, and show a buffer with the possible completions. You can then type another character, which will hopefully make it unique and press M-x tempo-complete-tag again.

Unfortunaly, there is no good way to use the mouse in the completion buffer, although it claims to be so.

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on October, 2 2007 using texi2html