Skip to main content

C'est la Z

Using Emacs - 13 - Yasnippet

It turns out that Elpy, a popular emacs package for python development is much easier to set up than I remember. It turns out all you need is:

(use-package elpy
:ensure t
:config
(elpy-enable))

The video shows how to install and a bit of use. I don't think it's a package I'm going to use much since I use other tools to do similar things but it's worth checking out.

The main event this week is yasnippet, a package that lets you expand text aliases. Let's say you want to put the fairly standard:

in my file. I can just type ifm and then hit the TAB key and it would expand to the above code. Yasnippet also lets you leave placeholders for variables, function names and more. It's a pretty neat package.

I use it for boilerplate code. The example in the video shows how I set up a snippet for the boilerplate code used when creating an application with the Flask python microframework.

Setting up yasnippet is as easy as:

(use-package yasnippet
:ensure t
:init
(yas-global-mode 1))

and it has built in support for tons of langauges. You can also easily create your own snippets. See the documentation for details on the file format. Just create a text file for the snippet and place it in a subidectory under the snippets subdirectory of .emacs.d. The name of the subdirectory should be the name of the emacs mode for which the snippet is defined. I put up the snippet I use for flask so feel free to check that out.

Relevant links:

comments powered by Disqus