Next: compile-dwim, Previous: pde-util, Up: Top
template.el is exists, why template-simple? First of all, it is
simple, the there is only one core function template-compile
.
The parsed template contains a list of strings, symbols or lisp forms.
The strings is inserted directly.
The symbol can be a predefined value in template-default-alist
,
or can be translate by template-expand-function
. The lisp forms
is handled by template-expand-function
.
Functions to expand parsed template. There are two candicate functions available in template-simple:
template-skeleton-expand
andtemplate-tempo-expand
. Default function istemplate-tempo-expand
, because I think tempo provide more fetures and flexibility than skeleton.
Define a new type of
template-expand-function
. NAME is used to create a function template-<NAME>-expand. ALIST can be a symbol or a form to return a list of symbol table add totemplate-default-alist
. BODY is the code to expand and insert the template. the value of variable TEMPLATE is the translated template. The element of parsed template is translated bytemplate-expansion
Expand template in file. Parse the template to parsed templates with
template-compile
. Usetemplate-expand-function
to expand the parsed template.
Expand string template. template can be a string or a parsed template. If it is string, parse the template to parsed templates with
template-compile
. Usetemplate-expand-function
to expand the parsed template.
template-simple is designed to compatible to template.el, so the
default open and close parentheses is “(>>>” and “<<<)”. Note that
global value of template-expand-function
is saved in
template-simple-expand
. The same case happened to
template-parens
in template-compile
. So If you need
change them temporary for certain template, you can set
template-parens
and template-expand-function
like file
variable, for example:
(template-simple-expand ";; -*- template-parens: (\"{\" . \"}\"); template-expand-function: template-tempo-expand -*- (defun {p} ({p}) \"{p}\" {p} )")
This will expand by template-tempo-expand
but not default
expand function. Luckily in most case, template of tempo and skeleton
can be the same, so you don't have to set
template-expand-function
. If your template uses element that
only exists in tempo or skeleton, you'd better set it in template to
make sure the template-simple-expand
select the correct one.
The major purpose of template-simple is used for fill empty file using predefined template.
A list of directories for lookup template files. Default is “~/.templates/” and
auto-insert-directory
.
Find proper template for current file. The template file is a file with name “TEMPLATE” and the same extension of current file under
template-directory
. You can add a suffix “.tpl” to the template file name too, just for compatible with templates provide by template.el. If the file didn't have extension, the template file's extension is current file name, for example, “TEMPLATE.Makefile” is template file for “Makefile”.
Predefined symbol for template file. Symbols to lookup in this table is case insensitive.
Here is a list of predefined symbol:
template-date-format
template-cdate-format
with system-time-locale
value is “C”
template-time-format
A neat function provided by template.el is the file name in the header can automatic update when the file is renamed. template-simple also provide this feature.
update file header when needed. The file header is a line match
template-header-regexp
at first 3 lines in current file.
A typical file header is like:
;;; file-name --- short description
or
/* @(#)file-name short description */