Created
December 8, 2014 06:34
-
-
Save evanmcc/0246e53212525f88c2ce to your computer and use it in GitHub Desktop.
simpler gen-server for lager-using projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file provides a simpler gen-server template for emacs' tempo mode. | |
To use it, drop the following: | |
`(load-file "/path/to/gen-server.el")` | |
in your .emacs or init.el or whatever somewhere after your erlang-mode initialization (so after package init if you're using packages). | |
It defines a function called `tempo-template-gen-server` which you can access from M-x as per usual. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(tempo-define-template "gen-server" | |
'((erlang-skel-include erlang-skel-small-header) | |
"-behaviour(gen_server)." n n | |
"%% API" n | |
"-export([start_link/0])." n n | |
"%% gen_server callbacks" n | |
"-export([init/1, handle_call/3, handle_cast/2, " | |
"handle_info/2," n> | |
"terminate/2, code_change/3])." n n | |
"-define(SERVER, ?MODULE)." n n | |
"-record(state, {})." n n | |
(erlang-skel-double-separator-start 3) | |
"%%% API" n | |
(erlang-skel-double-separator-end 3) n | |
"start_link() ->" n> | |
"gen_server:start_link({local, ?SERVER}, ?MODULE, [], [])." n | |
n | |
(erlang-skel-double-separator-start 3) | |
"%%% gen_server callbacks" n | |
(erlang-skel-double-separator-end 3) | |
n | |
"init([]) ->" n> | |
"{ok, #state{}}." n | |
n | |
"handle_call(_Request, _From, State) ->" n> | |
"lager:warning(\"unexpected call ~p from ~p\", [_Request, _From])," n> | |
"Reply = ok," n> | |
"{reply, Reply, State}." n | |
n | |
"handle_cast(_Msg, State) ->" n> | |
"lager:warning(\"unexpected cast ~p\", [_Msg])," n> | |
"{noreply, State}." n | |
n | |
"handle_info(_Info, State) ->" n> | |
"lager:warning(\"unexpected message ~p\", [_Info])," n> | |
"{noreply, State}." n | |
n | |
"terminate(_Reason, _State) ->" n> | |
"ok." n | |
n | |
"code_change(_OldVsn, State, _Extra) ->" n> | |
"{ok, State}." n | |
n | |
(erlang-skel-double-separator-start 3) | |
"%%% Internal functions" n | |
(erlang-skel-double-separator-end 3) | |
) | |
"uncluttered gen-server template for lager-using projects.") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment