Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #106 from tormaroe/erlang

Erlang snippets
  • Loading branch information...
commit a65f5d921a032fd56be33bcb0224eda6d3a4aa84 2 parents d6c84f9 + 5e48d74
@honza honza authored
Showing with 104 additions and 0 deletions.
  1. +104 −0 snippets/erlang.snippets
View
104 snippets/erlang.snippets
@@ -33,6 +33,16 @@ snippet case
${2:pattern} ->
${3:body};
end
+# anonymous function
+snippet fun
+ fun (${1:Parameters}) -> ${2:body} end${3}
+# try...catch
+snippet try
+ try
+ ${1}
+ catch
+ ${2:_:_} -> ${3:got_some_exception}
+ end
# record directive
snippet rec
-record(${1:record}, {
@@ -54,3 +64,97 @@ snippet %s
# private function marker
snippet %p
%% @private
+# OTP application
+snippet application
+ -module(${1:`Filename('', 'my')`}).
+
+ -behaviour(application).
+
+ -export([start/2, stop/1]).
+
+ start(_Type, _StartArgs) ->
+ case ${2:root_supervisor}:start_link() of
+ {ok, Pid} ->
+ {ok, Pid};
+ Other ->
+ {error, Other}
+ end.
+
+ stop(_State) ->
+ ok.
+# OTP supervisor
+snippet supervisor
+ -module(${1:`Filename('', 'my')`}).
+
+ -behaviour(supervisor).
+
+ %% API
+ -export([start_link/0]).
+
+ %% Supervisor callbacks
+ -export([init/1]).
+
+ -define(SERVER, ?MODULE).
+
+ start_link() ->
+ supervisor:start_link({local, ?SERVER}, ?MODULE, []).
+
+ init([]) ->
+ Server = {${2:my_server}, {$2, start_link, []},
+ permanent, 2000, worker, [$2]},
+ Children = [Server],
+ RestartStrategy = {one_for_one, 0, 1},
+ {ok, {RestartStrategy, Children}}.
+# OTP gen_server
+snippet gen_server
+ -module(${1:`Filename('', 'my')`}).
+
+ -behaviour(gen_server).
+
+ %% API
+ -export([
+ start_link/0
+ ]).
+
+ %% gen_server callbacks
+ -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+ -define(SERVER, ?MODULE).
+
+ -record(state, {}).
+
+ %%%===================================================================
+ %%% API
+ %%%===================================================================
+
+ start_link() ->
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
+
+ %%%===================================================================
+ %%% gen_server callbacks
+ %%%===================================================================
+
+ init([]) ->
+ {ok, #state{}}.
+
+ handle_call(_Request, _From, State) ->
+ Reply = ok,
+ {reply, Reply, State}.
+
+ handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+ handle_info(_Info, State) ->
+ {noreply, State}.
+
+ terminate(_Reason, _State) ->
+ ok.
+
+ code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+ %%%===================================================================
+ %%% Internal functions
+ %%%===================================================================
+
Please sign in to comment.
Something went wrong with that request. Please try again.