:editor file-templates

Fill the void in your empty files

1. Description

This module pre-fills new, empty files with a file template, powered by yasnippet.

1.2. Module flags

This module has no flags.

1.4. Hacks

No hacks documented for this module.

2. Prerequisites

This module has no external prerequisites.

3. Usage

File templates are automatically expanded when opening empty files.

They are also regular yasnippet snippets, which can be expanded by typing their trigger and pressing TAB. By convention, the triggers for file templates are prefixed with two underscores __.

3.1. Inserting OSS licenses

A special command is available for inserting software licenses: M-x +file-templates/insert-license.

Licenses with a -bp suffix are boilerplate templates, which are shorter versions of OSS licenses suited for comment headers in code.

4. Configuration

4.1. Registering a new file template

Look into the documentation of set-file-template! and set-file-templates!.

4.2. Changing existing file templates

Simply register a new template (using set-file-template!) that matches the same file. The new template would be pushed to the top of +file-template-alist and thus would take priority while searching for a template to insert.

4.3. Adding new OSS licenses

The +file-templates/insert-license command searches for snippets under text-mode that are named __license-ABC, where ABC is the short name of the license. e.g. __license-mit.

So long as these files exist, +file-templates/insert-license will recognize them.

5. Troubleshooting

If a file template isn’t expanding where you expect it to, run M-x +file-templates/debug. This will report to you what file template rule would apply for the correct file.

6. TODO Appendix

This module’s appendix is incomplete. Write more?

6.1. API

  • set-file-template! PRED &rest PLIST
  • set-file-templates! &rest TEMPLATES

6.2. Commands

  • +file-templates/insert-license
  • +file-templates/debug

6.3. Variables

  • +file-templates-dir
  • +file-templates-default-trigger
  • +file-templates-alist