forked from ajaxorg/ace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherlang.snippets.js
161 lines (132 loc) · 3.27 KB
/
erlang.snippets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
module.exports = `# 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}]).
# 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
# 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}, {
\${2:field}=\${3:value}}).\${4}
# todo comment
snippet todo
%% TODO: \${1}
## Snippets below (starting with '%') are in EDoc format.
## See http://www.erlang.org/doc/apps/edoc/chapter.html#id56887 for more details
# doc comment
snippet %d
%% @doc \${1}
# end of doc comment
snippet %e
%% @end
# specification comment
snippet %s
%% @spec \${1}
# 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
%%%===================================================================
`;