[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This node describes the syntax and semantics of templates defined by
tempo-define-template
. The first part deals with the syntax of
the function itself, while the second part describes the different
template elements.
2.1 Template syntax | ||
2.2 Template elements | ||
2.3 Defining your own elements |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Templates are defined with the function tempo-define-tempalate
.
tempo-template-name
.
This function creates a template and binds it to a new variable named
tempo-template-name
. It also creates a new command under
the same name. This command expands the template at the current point,
when invoked.
The parameter elements is a list of template elements. The possible elements are described in 2.2 Template elements.
If a tag is supplied, it must be a string which is placed in
taglist or tempo-tags
. This string is used for automatic
completion. When tempo-complete-tag
is called and tag is
matched, the template template defined with tag is
inserted. (see section 1.3 Tag lists and automatic completion for more information on tags and tag
lists)
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
These are the predefined elements you can use in a template definition:
STRING
tempo-insert-string-functions
and the result is inserted.
p
r
p
element, but if the
template command is given a prefix command, the current region is placed
here. This means that the preceding part of the template is expanded
before the region, and the rest is expanded after. There can be only one
r
in a template. If transient-mark-mode
is active
(see section `The Mark and the Region' in the GNU Emacs Manual) the current region is used and the prefix argument is ignored.
If the variable tempo-insert-region
is non-nil, the behaviour of
the r
element is reversed.
(p prompt [name [noinsert]])
(P prompt [name [noinsert]])
(r prompt [name [noinsert]])
tempo-interactive
is nil, the elements (p
...))
and (P ...)
work exactly like a single p
,
and (r ...)
works like a single r
.
But, if you set tempo-interactive
to t
the user is
prompted for a string to insert when the template is expanded. The
prompt is taken from the prompt
parameter. The element (P
...)
works like (p ...)
with the exception that
tempo-interactive
is forced to t
, which means that the
user will always (almost always, see below) be prompted.
If you provide a name to any of these, and interactive prompting
is taking place, the resulting string is saved in a local list so it can
be inserted again later with the (s ...)
element. See section 5. The save list, for more detailed information.
As a special case, if the save list already contains something under
name, it is used directly, and no prompting is done, even with a
(P ...)
element.
The third argument, noinsert, disables insertion of text. If
tempo-interactive
it non-nil
, and a name has been
provided, normally a string is read through the minibuffer and then
inserted and saved. When noinsert is non-nil
, nothing is
inserted, and the text is only saved for later.
Stylistic conventions (invented by me) dictates that these elements should be placed as early as possible in template definitions.
r>
r
, but it also indents the region it is
expanded around.
(s name)
&
%
n
>
indent-according-to-mode
. Note that in
order to get best results, you often should place this after the text
you want to place on the line, as this could affect the indentation.
n>
n
followed by a >
.
o
%
, but leaves the point on the first line. Note that
this can cause great confusion if you are not careful. If the o
is the first element in a template which is inserted at the beginning of
a line, strange things happen. This is due to odd behaviour in
open-line
.
nil
nil
element is simply igonred. That means that a lisp
expression (see below) that returns nil does not insert anything.
(l element1 element2...)
Anything else
nil
. If you want to insert more than one
element, use the (l element1 element2...)
element.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The variable tempo-user-elements
contains a list of functions to
call when an unrecognized element is found.
tempo-insert
is called with an element
it doesn't recognize, it checks this list by calling each function with
the element as the single argument. A function in this list should take
a single element as argument and return nil
for elements it
doesn't recognize. If it does recognize an element, it should return
another element to be inserted, e.g. a string. If the function wants to
return an authorative nil
, it could return either ""
or
(l)
.
Do not use any one-charachter tags for your own elements. These are reserved for future tempo enhancements.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by XEmacs shared group account on December, 19 2009
using texi2html 1.65.