This is an old revision of the document!


Templates

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.

File Templates

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.).

  • system: /usr/share/geany/templates/files/
  • user: ~/.config/geany/templates/files/

Overriding File Templates

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.

Adding File Templates

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

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 do not include the strings used to start single-line comments (e.g., '#' in shell scripts) – these are added when the file header is added using the strings to start single-line comments based on the filetype of the file being edited.

Whereas there may be multiple file templates (e.g., templates for PHP files, HTML files, etc.), there is but one file header template.

  • system: /usr/share/geany/templates/fileheader
  • user: ~/.config/geany/templates/fileheader

Including File Header Templates in File Templates

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

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.

However, like file header templates, function templates do not include the strings to start single-line comments and there is only a single function template.

  • system: /usr/share/geany/templates/function
  • user: ~/.config/geany/templates/function

Licensing Templates

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 templates, the strings to start comments are added to the start of lines included in the license templates, as per the current document's filetype.

As with file header, and function, there is only a single changelog template.

  • GPL License
    • system: /usr/share/geany/templates/gpl
    • user: ~/.config/geany/templates/gpl
  • 3-Clause BSD License
    • system: /usr/share/geany/templates/bsd
    • user: ~/.config/geany/templates/bsd

Including Licensing Templates in File Headers

One may include a licensing template in the file header template by using either the {gpl} or {bsd} template wildcards.

Changelog Templates

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.

  • system: /usr/share/geany/templates/changelog
  • user: ~/.config/geany/templates/changelog

Template Documentation

Documentation from the Geany manual regarding templates is available at Templates Documentation

Print/export