Skip to content

Instantly share code, notes, and snippets.

@brb
Last active October 10, 2015 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brb/3770823 to your computer and use it in GitHub Desktop.
Save brb/3770823 to your computer and use it in GitHub Desktop.
Erlang code snippets for snipmate.vim
# module and export all
snippet mod
-module(${1:`Filename('', 'my')`}).
-compile([export_all]).
start() ->
${2}
stop() ->
ok.
# define directive
snippet def
-define(${1:macro}, ${2:body}).${3}
# export directive
snippet exp
-export([${1:function}/${2:arity}]).
# compile_all directive
snippet call
-compile(export_all).${1} # include directive
snippet inc
-include("${1:file}").${2}
# behavior directive
snippet beh
-behaviour(${1:behaviour}).${2}
# if expression
snippet if
if
${1:guard} ->
${2:body}
end
# case expression
snippet case
case ${1:expression} of
${2:pattern} ->
${3:body};
end
# record directive
snippet rec
-record(${1:record}, {
${2:field}=${3:value}}).${4}
# gen_server
snippet genservmod
-behaviour(gen_server).
%% API
-export([start_link/0]).
%% gen_server callbacks
-export([
init/1,
terminate/2,
handle_call/3,
handle_cast/2,
handle_info/2,
code_change/3
]).
-record(state, {}).
%%%============================================================================
%%% API
%%%============================================================================
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
%%%============================================================================
%%% gen_server callbacks
%%%============================================================================
init([]) ->
{ok, #state{}}.
terminate(normal, _State) ->
ok.
handle_call(_Call, _, State) ->
{reply, ok, State}.
handle_cast(_Cast, State) ->
{noreply, State}.
handle_info(_Msg, State) ->
{noreply, State}.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
snippet %=
%% ----------------------------------------------------------------------------
snippet m%
%% ${1:section}${2}
%% ----------------------------------------------------------------------------
snippet modhead
%%% @author `system("git config --get user.name")` <`system("git config --get user.email")`>
%%% @doc
-module(`Filename('', 'my')`).
${1}
snippet sumup
%%%----------------------------------------------------------------------------
%%% @author `system("git config --get user.name")` <`system("git config --get user.email")`>
%%% @copyright (C) 2013, SumUp Limited.
%%% @doc
%%% @end
%%%----------------------------------------------------------------------------
-module(`Filename('', 'my')`).
${1}
snippet supmod
-behaviour(supervisor).
%% API
-export([start_link/0]).
%% Supervisor callbacks
-export([init/1]).
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
%%%============================================================================
%%% API functions
%%%============================================================================
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
%%%============================================================================
%%% Supervisor callbacks
%%%============================================================================
init([]) ->
{ok, { {one_for_one, 5, 10}, []} }.
snippet appmod
-behaviour(application).
%% Application callbacks
-export([start/2, stop/1]).
%%%============================================================================
%%% Application callbacks
%%%============================================================================
start(_StartType, _StartArgs) ->
${1:`Filename('', 'my')`}_sup:start_link().
stop(_State) ->
ok.
snippet eunitmod
%%% @author `system("git config --get user.name")` <`system("git config --get user.email")`>
-module(`Filename('', 'my')`).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
%%%=============================================================================
`Filename('', 'my')`_test_() ->
{foreach,
fun () -> ok end,
fun (_) -> ok end,
[
{"${4:description}", fun test_${1:foobar}/0}
]
}.
%%%=============================================================================
test_${2:$1}() ->
${3:?assert(false)}.
snippet eunitm
%%%============================================================================
%%% Tests
%%%============================================================================
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
$1
-endif.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment