insert-template(3)
[Home]
[Commands]
[Variables]
[Macro-Dev]
[Glossary]
NAME
insert-template - Insert template file into current buffer
%company-ref - Company reference template
SYNOPSIS
n insert-template [ "template" ]
%company-ref "string" ; See $COMPANY_REF$ below for default when undefined
DESCRIPTION
insert-template is generally called by file hooks when the new buffer has been created as opposed to loaded from a file (see
$buffer-fhook(5)).
insert-template uses
&find(4) to locate and insert the required "template.etf" file. If successful, insert-template then replaces the following strings in the template:
$ASCII_TIME$
To the current time. Inserts the output of
ascii-time(3). The default format of the time string may be changed by setting variable
%ascii-time(5).
$COMPANY_NAME$
To the value of
%company-name(5), or, if not defined, to the value used for $USER_NAME$. %company-name is usually set up in the company setup file defined in User setup.
$COMPANY_REF$
This is set to either "$COMPANY_NAME$ ($COMPANY_URL$)" if the %company-url is defined, or simply "$COMPANY_NAME$" if not, the tags are then replaced as defined in this help. The value can be altered by setting the %company-ref variable.
$COMPANY_URL$
To the value of
%company-url(5), or if not defined to an empty string (i.e. ""). %company-url is usually set up in the company setup file defined in User setup.
$FILE_NAME$
To the buffer name which is typically the buffer's file name without a path. A trailing "<##>" string (used to make the buffer name unique) is removed.
$FILE_BASENAME$
To the buffer name, which is typically the buffer's file name without a path, and without the file extension. A trailing "<##>" string is removed before the extension is removed.
$FILE_NAME_UD$
Same as $FILE_NAME$, but with the name capitalized and '.'s are replaced with '_'.
$USER_NAME$
To the value of the registry entry "/history/user-name", or if not defined to the value "<unknown>". The user name is usually set up in the User setup dialog.
$YEAR$
To the current year (4 digit number).
$CURSOR$
To leave the cursor at this point, only one of these tokens should be used in the template and the token is removed.
The numeric argument n is used to modify the default behavior of the command, where the values are defined as follows:
0 insert-template
Inserts the default template for the current file hook, for example if the current file is a MicroEmacs macros file the hook will be fhook-emf so this will insert "emf.etf".
0 insert-template '<template-name>'
In this form "<template-name>" must be given in the execution line, i.e. will not be prompted for, and only the
&find(4) macro function is used to locate the template file, this will include the
$user-path(5) and the other paths on the
$search-path(5) but will not include directory "$user-path/<fhook>/", see next option.
insert-template '<template-name>'
When no argument is supplied, the file of the given template is first search for within the directory "$user-path/<fhook>/" and only if not found will it then use the
&find(4) macro function to locate the file.
# insert-template
When n is non-zero insert-template inserts the template matching "$user-path/<fhook>/#_<name>.etf" where'#' can be prefixed with zeros, i.e. '3 insert-template' would insert templates 3_test.etf or 003_hello.etf if located in the correct directory. If multiple files match this base criteria the first file will be inserted.
EXAMPLE
The following is taken from hkmake.emf and inserts the "makefile.etf" template if the buffer has been created.
define-macro fhook-make
; if arg is 0 this is a new file so add template
!if ¬ @#
insert-template "makefile"
!endif
set-variable $buffer-hilight .hilight.make
-1 buffer-mode "tab" ; Normal tabs please !!!
1 buffer-mode "indent"
1 buffer-mode "time"
!emacro
NOTES
insert-template is a macro defined in etfinsrt.emf.
magic(2m) mode is always used to perform the the search/replace so the replace strings should be appropriate for magic.
SEE ALSO
(c) Copyright JASSPA 2025
Last Modified: 2025/03/26
Generated On: 2025/09/29