Templates are based on files stored in Configuration file paths. Geany reads when they are saved or by selecting Tools | Reload Configuration except for file templates which are read when they are used to create a new file.
Most templates (fileheader, function, gpl, bsd) will automatically include the comment strings (e.g., '#' to start a shell script comment) when they are inserted; however, file templates and the changelog template do not include the strings to signal comments. The exact comment strings are determined based on the filetype of the document into which they are being inserted. By default, multi-line comments are preferred to single-line comments if both single- and multi-line comments are available.
File templates are used when creating new files (i.e., File | New (with Template)). File templates are stored in templates/files/
and are named with the extension of their corresponding file type to assist Geany in determining the filetype (e.g., file.php
is a PHP file with the filetype of 'PHP'). File templates may include content that isn't necessarily a comment (e.g., lines to include other files, pragmas, etc.); therefore, to include comments, one must include the strings to start the comments. (e.g., to include the comment 'hello world' in a shell script, one must use '# hello world
').
File templates are unique in that there may be multiple file templates (i.e., a PHP file template, an HTML file template, etc.).
/usr/share/geany/templates/files/
~/.config/geany/templates/files/
Users may override templates by copying the original template from the system-wide templates/files
directory (e.g., /usr/share/geany/templates/files/
) to their user templates directory (e.g., ~/.config/geany/templates/files/
) and editing the copy.
New file templates may be created by writing to user templates directory. It is not recommended for one to modify the system-wide file templates as they will be overridden when upgrading Geany.
File header templates are used at the top of files and may be included in an existing file (i.e., Edit | Insert Comments | Insert File Header). File header templates automatically include the strings used to start single-line comments (e.g., '#' in shell scripts)
Whereas there may be multiple file templates (e.g., templates for PHP files, HTML files, etc.), there is but one file header template.
/usr/share/geany/templates/fileheader
~/.config/geany/templates/fileheader
One may include the file header template in a file template by using the {fileheader}
template wildcard. Doing so automatically adds the strings needed to start single-line comments based on the filetype.
Function templates are used to document functions within a file and may be included in an existing file (i.e., Edit | Insert Comments | Insert Function Description). Unlike file header templates, one must place the cursor inside of the function being described so that Geany knows which function to describe.
Like file header templates, there is only a single function template.
/usr/share/geany/templates/function
~/.config/geany/templates/function
There are two license templates included with Geany the short forms of the: GPL and BSD (3-Clause) licenses. The content of these templates may be added to the current file at the location of the cursor (i.e., Edit | Insert Comments | Insert GPL Notice or Edit | Insert Comments | Insert BSD License).
As with file header, and function, there is only a single changelog template.
/usr/share/geany/templates/gpl
~/.config/geany/templates/gpl
/usr/share/geany/templates/bsd
~/.config/geany/templates/bsd
One may include a licensing template in the file header template by using either the {gpl}
or {bsd}
template wildcards.
Changelog templates are used to add changelog entries to a change log; they're not usually used inside a source file. As a result, there are several differences with changelog templates as compared to other types of templates.
When a changelog template is inserted (i.e., Edit | Insert Comments | Insert ChangeLog Entry), the content of the template is added to the top of the current file without regard to any existing comments, shell processing directives, etc.. Moreover, changelog entries do not include the strings to start comments – they're added as-is to the top of the current file.
However, as with file header, function, and license templates, there is only a single changelog template.
/usr/share/geany/templates/changelog
~/.config/geany/templates/changelog
Documentation from the Geany manual regarding templates is available at Templates Documentation