Since I discovered YASnippet, I always try to automate text creation with the help of it. For those who don’t know, it is a template system for Emacs. The creators claim that the syntax is inspired by TextMate, which is not an text editor I use ;)

Anyway, templates can greatly accelerate text creation. For example, how often did you wrote the main function in C to just write some little program? Or, how many times did you wrote a for loop and typed all the characters like braces and semicolons? As the name suggest, you can write a template for every text fragment you frequently have to write. These templates then expand and either let you manually fill certain fields or it does it automatically.

You can configure, in what Emacs modes certain templates are “active” and you expand them by entering the key in your text file and then press the trigger key, which defaults to TAB. Here the template:

# name: Create a new Jekyll blog post
# key: post
# --
---
layout:     post
author:     Alex
title:      "${1:title}"
date:       `(format-time-string "%Y-%m-%d %H:%M:%S")`
categories: ${2:categories}
---

$0

Well, nothing really exciting. However, a really nice feature is to actually call any lisp code from a template. Just enclose it with backticks, as you can see it with calling (format-time-string). Entries which start with an $ are the fields which you customize during expansion. The text after the : is the default value, which you can interactively override.

When using YASnippet, you soon develop the habit to write templates for everything that you frequently repeat. It is easy to use and fast to create new templates. And of course, its Free Software!.