1 ;; erlang.el --- Major modes for editing and running Erlang
2 ;; The contents of this file are subject to the Erlang Public License,
3 ;; Version 1.1, (the "License"); you may not use this file except in
4 ;; compliance with the License. You should have received a copy of the
5 ;; Erlang Public License along with this software. If not, it can be
6 ;; retrieved via the world wide web at http://www.erlang.org/.
8 ;; Software distributed under the License is distributed on an "AS IS"
9 ;; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
10 ;; the License for the specific language governing rights and limitations
13 ;; The Initial Developer of the Original Code is Ericsson Utvecklings AB.
14 ;; All Rights Reserved.
19 '(("If" "if" erlang-skel-if
)
20 ("Case" "case" erlang-skel-case
)
21 ("Receive" "receive" erlang-skel-receive
)
22 ("Receive After" "after" erlang-skel-receive-after
)
23 ("Receive Loop" "loop" erlang-skel-receive-loop
)
24 ("Module" "module" erlang-skel-module
)
25 ("Author" "author" erlang-skel-author
)
26 ("Function" "function" erlang-skel-function
)
28 ("Small Header" "small-header"
29 erlang-skel-small-header erlang-skel-header
)
30 ("Normal Header" "normal-header"
31 erlang-skel-normal-header erlang-skel-header
)
32 ("Large Header" "large-header"
33 erlang-skel-large-header erlang-skel-header
)
35 ("Small Server" "small-server"
36 erlang-skel-small-server erlang-skel-header
)
38 ("Application" "application"
39 erlang-skel-application erlang-skel-header
)
40 ("Supervisor" "supervisor"
41 erlang-skel-supervisor erlang-skel-header
)
42 ("supervisor_bridge" "supervisor-bridge"
43 erlang-skel-supervisor-bridge erlang-skel-header
)
44 ("gen_server" "generic-server"
45 erlang-skel-generic-server erlang-skel-header
)
46 ("gen_event" "gen-event"
47 erlang-skel-gen-event erlang-skel-header
)
49 erlang-skel-gen-fsm erlang-skel-header
)
50 ("Library module" "gen-lib"
51 erlang-skel-lib erlang-skel-header
)
52 ("Corba callback" "gen-corba-cb"
53 erlang-skel-corba-callback erlang-skel-header
)
54 ("Erlang test suite TS frontend" "ts-test-suite"
55 erlang-skel-ts-test-suite erlang-skel-header
)
56 ("Erlang test suite CT frontend" "ct-test-suite"
57 erlang-skel-ct-test-suite erlang-skel-header
)
59 "*Description of all skeleton templates.
60 Both functions and menu entries will be created.
62 Each entry in `erlang-skel' should be a list with three or four
63 elements, or the empty list.
65 The first element is the name which shows up in the menu. The second
66 is the `tempo' identifier (The string \"erlang-\" will be added in
67 front of it). The third is the skeleton descriptor, a variable
68 containing `tempo' attributes as described in the function
69 `tempo-define-template'. The optional fourth elements denotes a
70 function which should be called when the menu is selected.
72 Functions corresponding to every template will be created. The name
73 of the function will be `tempo-template-erlang-X' where `X' is the
74 tempo identifier as specified in the second argument of the elements
77 A list with zero elements means that the a horizontal line should
78 be placed in the menu.")
80 ;; In XEmacs `user-mail-address' returns "x@y.z (Foo Bar)" ARGH!
81 ;; What's wrong with that? RFC 822 says it's legal. [sverkerw]
82 ;; This needs to use the customized value. If that's not sane, things like
83 ;; add-log will lose anyhow. Avoid it if there _is_ a paren.
84 (defvar erlang-skel-mail-address
85 (if (or (not user-mail-address
) (string-match "(" user-mail-address
))
86 (concat (user-login-name) "@"
87 (or (and (boundp 'mail-host-address
)
91 "Mail address of the user.")
93 ;; Expression templates:
94 (defvar erlang-skel-case
95 '((erlang-skel-skip-blank) o
>
96 "case " p
" of" n
> p
"_ ->" n
> p
"ok" n
> "end" p
)
97 "*The skeleton of a `case' expression.
98 Please see the function `tempo-define-template'.")
100 (defvar erlang-skel-if
101 '((erlang-skel-skip-blank) o
>
102 "if" n
> p
" ->" n
> p
"ok" n
> "end" p
)
103 "The skeleton of an `if' expression.
104 Please see the function `tempo-define-template'.")
106 (defvar erlang-skel-receive
107 '((erlang-skel-skip-blank) o
>
108 "receive" n
> p
"_ ->" n
> p
"ok" n
> "end" p
)
109 "*The skeleton of a `receive' expression.
110 Please see the function `tempo-define-template'.")
112 (defvar erlang-skel-receive-after
113 '((erlang-skel-skip-blank) o
>
114 "receive" n
> p
"_ ->" n
> p
"ok" n
> "after " p
"T ->" n
>
116 "*The skeleton of a `receive' expression with an `after' clause.
117 Please see the function `tempo-define-template'.")
119 (defvar erlang-skel-receive-loop
120 '(& o
"loop(" p
") ->" n
> "receive" n
> p
"_ ->" n
>
121 "loop(" p
")" n
> "end.")
122 "*The skeleton of a simple `receive' loop.
123 Please see the function `tempo-define-template'.")
126 (defvar erlang-skel-function
127 '((erlang-skel-separator 2)
131 (erlang-skel-separator 2))
132 "*The template of a function skeleton.
133 Please see the function `tempo-define-template'.")
136 ;; Attribute templates
138 (defvar erlang-skel-module
140 (erlang-add-quotes-if-needed (erlang-get-module-from-file-name))
142 "*The skeleton of a `module' attribute.
143 Please see the function `tempo-define-template'.")
145 (defvar erlang-skel-author
146 '(& "-author('" erlang-skel-mail-address
"')." n
)
147 "*The skeleton of a `author' attribute.
148 Please see the function `tempo-define-template'.")
150 (defvar erlang-skel-vc nil
151 "*The skeleton template to generate a version control attribute.
152 The default is to insert nothing. Example of usage:
154 (setq erlang-skel-vc '(& \"-rcs(\\\"$\Id: $ \\\").\") n)
156 Please see the function `tempo-define-template'.")
158 (defvar erlang-skel-export
159 '(& "-export([" n
> "])." n
)
160 "*The skeleton of an `export' attribute.
161 Please see the function `tempo-define-template'.")
163 (defvar erlang-skel-import
164 '(& "%%-import(Module, [Function/Arity, ...])." n
)
165 "*The skeleton of an `import' attribute.
166 Please see the function `tempo-define-template'.")
168 (defvar erlang-skel-compile nil
169 ;; '(& "%%-compile(export_all)." n)
170 "*The skeleton of a `compile' attribute.
171 Please see the function `tempo-define-template'.")
174 ;; Comment templates.
176 (defvar erlang-skel-date-function
'erlang-skel-dd-mmm-yyyy
177 "*Function which returns date string.
178 Look in the module `time-stamp' for a battery of functions.")
180 (defvar erlang-skel-copyright-comment
181 (if (boundp '*copyright-organization
*)
182 '(& "%%% @copyright (C) " (format-time-string "%Y") ", "
183 *copyright-organization
* n
)
184 '(& "%%% @copyright (C) " (format-time-string "%Y") ", "
186 "*The template for a copyright line in the header, normally empty.
187 This variable should be bound to a `tempo' template, for example:
188 '(& \"%%% Copyright (C) 2000, Yoyodyne, Inc.\" n)
189 Please see the function `tempo-define-template'.")
191 (defvar erlang-skel-created-comment
192 '(& "%%% Created : " (funcall erlang-skel-date-function
) " by "
193 (user-full-name) " <" erlang-skel-mail-address
">" n
)
194 "*The template for the \"Created:\" comment line.")
196 (defvar erlang-skel-author-comment
197 '(& "%%% @author " (user-full-name) " <" erlang-skel-mail-address
">" n
)
198 "*The template for creating the \"Author:\" line in the header.
199 Please see the function `tempo-define-template'.")
201 (defvar erlang-skel-small-header
202 '(o (erlang-skel-include erlang-skel-module
)
204 (erlang-skel-include erlang-skel-compile erlang-skel-vc
))
205 "*The template of a small header without any comments.
206 Please see the function `tempo-define-template'.")
208 (defvar erlang-skel-normal-header
209 '(o (erlang-skel-include erlang-skel-author-comment
)
210 (erlang-skel-include erlang-skel-copyright-comment
)
214 (erlang-skel-include erlang-skel-created-comment
) n
215 (erlang-skel-include erlang-skel-small-header
) n
)
216 "*The template of a normal header.
217 Please see the function `tempo-define-template'.")
219 (defvar erlang-skel-large-header
220 '(o (erlang-skel-separator)
221 (erlang-skel-include erlang-skel-author-comment
)
222 (erlang-skel-include erlang-skel-copyright-comment
)
226 (erlang-skel-include erlang-skel-created-comment
)
227 (erlang-skel-separator)
228 (erlang-skel-include erlang-skel-small-header
) )
229 "*The template of a large header.
230 Please see the function `tempo-define-template'.")
234 (defvar erlang-skel-small-server
235 '((erlang-skel-include erlang-skel-large-header
)
236 "-export([start/0,init/1])." n n n
237 "start() ->" n
> "spawn(" (erlang-get-module-from-file-name)
238 ", init, [self()])." n n
247 "*Template of a small server.
248 Please see the function `tempo-define-template'.")
250 ;; Behaviour templates.
251 (defvar erlang-skel-application
252 '((erlang-skel-include erlang-skel-large-header
)
253 "-behaviour(application)." n n
254 "%% Application callbacks" n
255 "-export([start/2, stop/1])." n n
256 (erlang-skel-double-separator 2)
257 "%% Application callbacks" n
258 (erlang-skel-double-separator 2)
259 (erlang-skel-separator 2)
262 "%% This function is called whenever an application is started using" n
263 "%% application:start/[1,2], and should start the processes of the" n
264 "%% application. If the application is structured according to the OTP" n
265 "%% design principles as a supervision tree, this means starting the" n
266 "%% top supervisor of the tree." n
268 "%% @spec start(Type, StartArgs) -> {ok, Pid} |" n
269 "%% {ok, Pid, State} |" n
270 "%% {error, Reason}" n
272 (erlang-skel-separator 2)
273 "start(_Type, StartArgs) ->" n
>
274 "case 'TopSupervisor':start_link(StartArgs) of" n
>
281 (erlang-skel-separator 2)
284 "%% This function is called whenever an application has stopped. It" n
285 "%% is intended to be the opposite of Module:start/2 and should do" n
286 "%% any necessary cleaning up. The return value is ignored." n
288 "%% @spec stop(State) -> void()" n
290 (erlang-skel-separator 2)
294 (erlang-skel-double-separator 2)
295 "%% Internal functions" n
296 (erlang-skel-double-separator 2)
298 "*The template of an application behaviour.
299 Please see the function `tempo-define-template'.")
301 (defvar erlang-skel-supervisor
302 '((erlang-skel-include erlang-skel-large-header
)
303 "-behaviour(supervisor)." n n
306 "-export([start_link/0])." n n
308 "%% Supervisor callbacks" n
309 "-export([init/1])." n n
311 "-define(SERVER, ?MODULE)." n n
313 (erlang-skel-double-separator 2)
315 (erlang-skel-double-separator 2)
316 (erlang-skel-separator 2)
318 "%% Starts the supervisor" n
320 "%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
322 (erlang-skel-separator 2)
324 "supervisor:start_link({local, ?SERVER}, ?MODULE, [])." n
326 (erlang-skel-double-separator 2)
327 "%% Supervisor callbacks" n
328 (erlang-skel-double-separator 2)
329 (erlang-skel-separator 2)
332 "%% Whenever a supervisor is started using supervisor:start_link/[2,3]," n
333 "%% this function is called by the new process to find out about" n
334 "%% restart strategy, maximum restart frequency and child" n
335 "%% specifications." n
337 "%% @spec init(Args) -> {ok, {SupFlags, [ChildSpec]}} |" n
339 "%% {error, Reason}" n
341 (erlang-skel-separator 2)
343 "AChild = {'AName', {'AModule', start_link, []}," n
>
344 "permanent, 2000, worker, ['AModule']}," n
>
345 "{ok, {{one_for_all, 0, 1}, [AChild]}}." n
347 (erlang-skel-double-separator 2)
348 "%% Internal functions" n
349 (erlang-skel-double-separator 2)
351 "*The template of an supervisor behaviour.
352 Please see the function `tempo-define-template'.")
354 (defvar erlang-skel-supervisor-bridge
355 '((erlang-skel-include erlang-skel-large-header
)
356 "-behaviour(supervisor_bridge)." n n
359 "-export([start_link/0])." n n
361 "%% supervisor_bridge callbacks" n
362 "-export([init/1, terminate/2])." n n
364 "-define(SERVER, ?MODULE)." n n
366 "-record(state, {})." n n
368 (erlang-skel-double-separator 2)
370 (erlang-skel-double-separator 2)
371 (erlang-skel-separator 2)
373 "%% Starts the supervisor bridge" n
375 "%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
377 (erlang-skel-separator 2)
379 "supervisor_bridge:start_link({local, ?SERVER}, ?MODULE, [])." n
381 (erlang-skel-double-separator 2)
382 "%% supervisor_bridge callbacks" n
383 (erlang-skel-double-separator 2)
384 (erlang-skel-separator 2)
387 "%% Creates a supervisor_bridge process, linked to the calling process," n
388 "%% which calls Module:init/1 to start the subsystem. To ensure a" n
389 "%% synchronized start-up procedure, this function does not return" n
390 "%% until Module:init/1 has returned." n
392 "%% @spec init(Args) -> {ok, Pid, State} |" n
394 "%% {error, Reason}" n
396 (erlang-skel-separator 2)
398 "case 'AModule':start_link() of" n
>
400 "{ok, Pid, #state{}};" n
>
405 (erlang-skel-separator 2)
408 "%% This function is called by the supervisor_bridge when it is about" n
409 "%% to terminate. It should be the opposite of Module:init/1 and stop" n
410 "%% the subsystem and do any necessary cleaning up.The return value is" n
413 "%% @spec terminate(Reason, State) -> void()" n
415 (erlang-skel-separator 2)
416 "terminate(Reason, State) ->" n
>
417 "'AModule':stop()," n
>
420 (erlang-skel-double-separator 2)
421 "%% Internal functions" n
422 (erlang-skel-double-separator 2)
424 "*The template of an supervisor_bridge behaviour.
425 Please see the function `tempo-define-template'.")
427 (defvar erlang-skel-generic-server
428 '((erlang-skel-include erlang-skel-large-header
)
429 "-behaviour(gen_server)." n n
432 "-export([start_link/0])." n n
434 "%% gen_server callbacks" n
435 "-export([init/1, handle_call/3, handle_cast/2, "
437 "terminate/2, code_change/3])." n n
439 "-define(SERVER, ?MODULE). " n n
441 "-record(state, {})." n n
443 (erlang-skel-double-separator 2)
445 (erlang-skel-double-separator 2)
446 (erlang-skel-separator 2)
448 "%% Starts the server" n
450 "%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
452 (erlang-skel-separator 2)
454 "gen_server:start_link({local, ?SERVER}, ?MODULE, [], [])." n
456 (erlang-skel-double-separator 2)
457 "%% gen_server callbacks" n
458 (erlang-skel-double-separator 2)
460 (erlang-skel-separator 2)
463 "%% Initiates the server" n
465 "%% @spec init(Args) -> {ok, State} |" n
466 "%% {ok, State, Timeout} |" n
468 "%% {stop, Reason}" n
470 (erlang-skel-separator 2)
474 (erlang-skel-separator 2)
477 "%% Handling call messages" n
479 "%% @spec handle_call(Request, From, State) ->" n
480 "%% {reply, Reply, State} |" n
481 "%% {reply, Reply, State, Timeout} |" n
482 "%% {noreply, State} |" n
483 "%% {noreply, State, Timeout} |" n
484 "%% {stop, Reason, Reply, State} |" n
485 "%% {stop, Reason, State}" n
487 (erlang-skel-separator 2)
488 "handle_call(_Request, _From, State) ->" n
>
490 "{reply, Reply, State}." n
492 (erlang-skel-separator 2)
495 "%% Handling cast messages" n
497 "%% @spec handle_cast(Msg, State) -> {noreply, State} |" n
498 "%% {noreply, State, Timeout} |" n
499 "%% {stop, Reason, State}" n
502 (erlang-skel-separator 2)
503 "handle_cast(_Msg, State) ->" n
>
504 "{noreply, State}." n
506 (erlang-skel-separator 2)
509 "%% Handling all non call/cast messages" n
511 "%% @spec handle_info(Info, State) -> {noreply, State} |" n
512 "%% {noreply, State, Timeout} |" n
513 "%% {stop, Reason, State}" n
515 (erlang-skel-separator 2)
516 "handle_info(_Info, State) ->" n
>
517 "{noreply, State}." n
519 (erlang-skel-separator 2)
522 "%% This function is called by a gen_server when it is about to" n
523 "%% terminate. It should be the opposite of Module:init/1 and do any" n
524 "%% necessary cleaning up. When it returns, the gen_server terminates" n
525 "%% with Reason. The return value is ignored." n
527 "%% @spec terminate(Reason, State) -> void()" n
529 (erlang-skel-separator 2)
530 "terminate(_Reason, _State) ->" n
>
533 (erlang-skel-separator 2)
536 "%% Convert process state when code is changed" n
538 "%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
540 (erlang-skel-separator 2)
541 "code_change(_OldVsn, State, _Extra) ->" n
>
544 (erlang-skel-double-separator 2)
545 "%%% Internal functions" n
546 (erlang-skel-double-separator 2)
548 "*The template of a generic server.
549 Please see the function `tempo-define-template'.")
551 (defvar erlang-skel-gen-event
552 '((erlang-skel-include erlang-skel-large-header
)
553 "-behaviour(gen_event)." n
556 "-export([start_link/0, add_handler/0])." n n
558 "%% gen_event callbacks" n
559 "-export([init/1, handle_event/2, handle_call/2, " n
>
560 "handle_info/2, terminate/2, code_change/3])." n n
562 "-record(state, {})." n n
564 (erlang-skel-double-separator 2)
565 "%% gen_event callbacks" n
566 (erlang-skel-double-separator 2)
567 (erlang-skel-separator 2)
569 "%% Creates an event manager" n
571 "%% @spec start_link() -> {ok, Pid} | {error, Error}" n
573 (erlang-skel-separator 2)
575 "gen_event:start_link({local, ?SERVER})." n
577 (erlang-skel-separator 2)
579 "%% Adds an event handler" n
581 "%% @spec add_handler() -> ok | {'EXIT', Reason} | term()" n
583 (erlang-skel-separator 2)
584 "add_handler() ->" n
>
585 "gen_event:add_handler(?SERVER, ?MODULE, [])." n
587 (erlang-skel-double-separator 2)
588 "%% gen_event callbacks" n
589 (erlang-skel-double-separator 2)
590 (erlang-skel-separator 2)
593 "%% Whenever a new event handler is added to an event manager," n
594 "%% this function is called to initialize the event handler." n
596 "%% @spec init(Args) -> {ok, State}" n
598 (erlang-skel-separator 2)
602 (erlang-skel-separator 2)
605 "%% Whenever an event manager receives an event sent using" n
606 "%% gen_event:notify/2 or gen_event:sync_notify/2, this function is" n
607 "%% called for each installed event handler to handle the event." n
609 "%% @spec handle_event(Event, State) ->" n
611 "%% {swap_handler, Args1, State1, Mod2, Args2} |"n
612 "%% remove_handler" n
614 (erlang-skel-separator 2)
615 "handle_event(_Event, State) ->" n
>
618 (erlang-skel-separator 2)
621 "%% Whenever an event manager receives a request sent using" n
622 "%% gen_event:call/3,4, this function is called for the specified" n
623 "%% event handler to handle the request." n
625 "%% @spec handle_call(Request, State) ->" n
626 "%% {ok, Reply, State} |" n
627 "%% {swap_handler, Reply, Args1, State1, Mod2, Args2} |" n
628 "%% {remove_handler, Reply}" n
630 (erlang-skel-separator 2)
631 "handle_call(_Request, State) ->" n
>
633 "{ok, Reply, State}." n
635 (erlang-skel-separator 2)
638 "%% This function is called for each installed event handler when" n
639 "%% an event manager receives any other message than an event or a" n
640 "%% synchronous request (or a system message)." n
642 "%% @spec handle_info(Info, State) ->" n
644 "%% {swap_handler, Args1, State1, Mod2, Args2} |" n
645 "%% remove_handler" n
647 (erlang-skel-separator 2)
648 "handle_info(_Info, State) ->" n
>
651 (erlang-skel-separator 2)
654 "%% Whenever an event handler is deleted from an event manager, this" n
655 "%% function is called. It should be the opposite of Module:init/1 and" n
656 "%% do any necessary cleaning up." n
658 "%% @spec terminate(Reason, State) -> void()" n
660 (erlang-skel-separator 2)
661 "terminate(_Reason, _State) ->" n
>
664 (erlang-skel-separator 2)
667 "%% Convert process state when code is changed" n
669 "%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
671 (erlang-skel-separator 2)
672 "code_change(_OldVsn, State, _Extra) ->" n
>
675 (erlang-skel-double-separator 2)
676 "%%% Internal functions" n
677 (erlang-skel-double-separator 2)
679 "*The template of a gen_event.
680 Please see the function `tempo-define-template'.")
682 (defvar erlang-skel-gen-fsm
683 '((erlang-skel-include erlang-skel-large-header
)
684 "-behaviour(gen_fsm)." n n
687 "-export([start_link/0])." n n
689 "%% gen_fsm callbacks" n
690 "-export([init/1, state_name/2, state_name/3, handle_event/3," n
>
691 "handle_sync_event/4, handle_info/3, terminate/3, code_change/4])." n n
693 "-record(state, {})." n n
695 (erlang-skel-double-separator 2)
697 (erlang-skel-double-separator 2)
698 (erlang-skel-separator 2)
700 "%% Creates a gen_fsm process which calls Module:init/1 to" n
701 "%% initialize. To ensure a synchronized start-up procedure, this" n
702 "%% function does not return until Module:init/1 has returned." n
704 "%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
706 (erlang-skel-separator 2)
708 "gen_fsm:start_link({local, ?SERVER}, ?MODULE, [], [])." n
710 (erlang-skel-double-separator 2)
711 "%% gen_fsm callbacks" n
712 (erlang-skel-double-separator 2)
713 (erlang-skel-separator 2)
716 "%% Whenever a gen_fsm is started using gen_fsm:start/[3,4] or" n
717 "%% gen_fsm:start_link/[3,4], this function is called by the new" n
718 "%% process to initialize." n
720 "%% @spec init(Args) -> {ok, StateName, State} |" n
721 "%% {ok, StateName, State, Timeout} |" n
723 "%% {stop, StopReason}" n
725 (erlang-skel-separator 2)
727 "{ok, state_name, #state{}}." n
729 (erlang-skel-separator 2)
732 "%% There should be one instance of this function for each possible" n
733 "%% state name. Whenever a gen_fsm receives an event sent using" n
734 "%% gen_fsm:send_event/2, the instance of this function with the same" n
735 "%% name as the current state name StateName is called to handle" n
736 "%% the event. It is also called if a timeout occurs." n
738 "%% @spec state_name(Event, State) ->" n
739 "%% {next_state, NextStateName, NextState} |" n
740 "%% {next_state, NextStateName, NextState, Timeout} |" n
741 "%% {stop, Reason, NewState}" n
743 (erlang-skel-separator 2)
744 "state_name(_Event, State) ->" n
>
745 "{next_state, state_name, State}." n
747 (erlang-skel-separator 2)
750 "%% There should be one instance of this function for each possible" n
751 "%% state name. Whenever a gen_fsm receives an event sent using" n
752 "%% gen_fsm:sync_send_event/[2,3], the instance of this function with" n
753 "%% the same name as the current state name StateName is called to" n
754 "%% handle the event." n
756 "%% @spec state_name(Event, From, State) ->" n
757 "%% {next_state, NextStateName, NextState} |"n
758 "%% {next_state, NextStateName, NextState, Timeout} |" n
759 "%% {reply, Reply, NextStateName, NextState} |" n
760 "%% {reply, Reply, NextStateName, NextState, Timeout} |" n
761 "%% {stop, Reason, NewState} |" n
762 "%% {stop, Reason, Reply, NewState}" n
764 (erlang-skel-separator 2)
765 "state_name(_Event, _From, State) ->" n
>
767 "{reply, Reply, state_name, State}." n
769 (erlang-skel-separator 2)
772 "%% Whenever a gen_fsm receives an event sent using" n
773 "%% gen_fsm:send_all_state_event/2, this function is called to handle" n
776 "%% @spec handle_event(Event, StateName, State) ->" n
777 "%% {next_state, NextStateName, NextState} |" n
778 "%% {next_state, NextStateName, NextState, Timeout} |" n
779 "%% {stop, Reason, NewState}" n
781 (erlang-skel-separator 2)
782 "handle_event(_Event, StateName, State) ->" n
>
783 "{next_state, StateName, State}." n
785 (erlang-skel-separator 2)
788 "%% Whenever a gen_fsm receives an event sent using" n
789 "%% gen_fsm:sync_send_all_state_event/[2,3], this function is called" n
790 "%% to handle the event." n
792 "%% @spec handle_sync_event(Event, From, StateName, State) ->" n
793 "%% {next_state, NextStateName, NextState} |" n
794 "%% {next_state, NextStateName, NextState, Timeout} |" n
795 "%% {reply, Reply, NextStateName, NextState} |" n
796 "%% {reply, Reply, NextStateName, NextState, Timeout} |" n
797 "%% {stop, Reason, NewState} |" n
798 "%% {stop, Reason, Reply, NewState}" n
800 (erlang-skel-separator 2)
801 "handle_sync_event(Event, From, StateName, State) ->" n
>
803 "{reply, Reply, StateName, State}." n
805 (erlang-skel-separator 2)
808 "%% This function is called by a gen_fsm when it receives any" n
809 "%% message other than a synchronous or asynchronous event" n
810 "%% (or a system message)." n
812 "%% @spec handle_info(Info,StateName,State)->" n
813 "%% {next_state, NextStateName, NextState} |" n
814 "%% {next_state, NextStateName, NextState, Timeout} |" n
815 "%% {stop, Reason, NewState}" n
817 (erlang-skel-separator 2)
818 "handle_info(_Info, StateName, State) ->" n
>
819 "{next_state, StateName, State}." n
821 (erlang-skel-separator 2)
824 "%% This function is called by a gen_fsm when it is about to" n
825 "%% terminate. It should be the opposite of Module:init/1 and do any" n
826 "%% necessary cleaning up. When it returns, the gen_fsm terminates with" n
827 "%% Reason. The return value is ignored." n
829 "%% @spec terminate(Reason, StateName, State) -> void()" n
831 (erlang-skel-separator 2)
832 "terminate(_Reason, _StateName, _State) ->" n
>
835 (erlang-skel-separator 2)
838 "%% Convert process state when code is changed" n
840 "%% @spec code_change(OldVsn, StateName, State, Extra) ->" n
841 "%% {ok, StateName, NewState}" n
843 (erlang-skel-separator 2)
844 "code_change(_OldVsn, StateName, State, _Extra) ->" n
>
845 "{ok, StateName, State}." n
847 (erlang-skel-double-separator 2)
848 "%%% Internal functions" n
849 (erlang-skel-double-separator 2)
851 "*The template of a gen_fsm.
852 Please see the function `tempo-define-template'.")
854 (defvar erlang-skel-lib
855 '((erlang-skel-include erlang-skel-large-header
)
860 (erlang-skel-double-separator 2)
862 (erlang-skel-double-separator 2)
863 (erlang-skel-separator 2)
867 (erlang-skel-separator 2)
869 (erlang-skel-double-separator 2)
870 "%% Internal functions" n
871 (erlang-skel-double-separator 2)
873 "*The template of a library module.
874 Please see the function `tempo-define-template'.")
876 (defvar erlang-skel-corba-callback
877 '((erlang-skel-include erlang-skel-large-header
)
878 "%% Include files" n n
883 "%% Corba callbacks" n
884 "-export([init/1, terminate/2, code_change/3])." n n
886 "-record(state, {})." n n
888 (erlang-skel-double-separator 2)
889 "%% Corba callbacks" n
890 (erlang-skel-double-separator 2)
891 (erlang-skel-separator 2)
894 "%% Initiates the server" n
896 "%% @spec init(Args) -> {ok, State} |" n
897 "%% {ok, State, Timeout} |" n
899 "%% {stop, Reason}" n
901 (erlang-skel-separator 2)
905 (erlang-skel-separator 2)
908 "%% Shutdown the server" n
910 "%% @spec terminate(Reason, State) -> void()" n
912 (erlang-skel-separator 2)
913 "terminate(_Reason, _State) ->" n
>
916 (erlang-skel-separator 2)
919 "%% Convert process state when code is changed" n
921 "%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
923 (erlang-skel-separator 2)
924 "code_change(_OldVsn, State, _Extra) ->" n
>
927 (erlang-skel-double-separator 2)
928 "%% Internal functions" n
929 (erlang-skel-double-separator 2)
931 "*The template of a library module.
932 Please see the function `tempo-define-template'.")
934 (defvar erlang-skel-ts-test-suite
935 '((erlang-skel-include erlang-skel-large-header
)
936 "%% Note: This directive should only be used in test suites." n
937 "-compile(export_all)." n n
939 "-include(\"test_server.hrl\")." n n
941 "%% Test server callback functions" n
942 (erlang-skel-separator 2)
944 "%% Config - [tuple()]" n
945 "%% A list of key/value pairs, holding the test case configuration." n
947 "%% Initiation before the whole suite" n
949 "%% Note: This function is free to add any key/value pairs to the Config" n
950 "%% variable, but should NOT alter/remove any existing entries." n
952 "%% @spec init_per_suite(Config) -> Config" n
954 (erlang-skel-separator 2)
955 "init_per_suite(Config) ->" n
>
958 (erlang-skel-separator 2)
960 "%% Config - [tuple()]" n
961 "%% A list of key/value pairs, holding the test case configuration." n
963 "%% Cleanup after the whole suite" n
965 "%% @spec end_per_suite(Config) -> _" n
967 (erlang-skel-separator 2)
968 "end_per_suite(_Config) ->" n
>
971 (erlang-skel-separator 2)
974 "%% Name of the test case that is about to be run." n
975 "%% Config - [tuple()]" n
976 "%% A list of key/value pairs, holding the test case configuration." n
978 "%% Initiation before each test case" n
980 "%% Note: This function is free to add any key/value pairs to the Config" n
981 "%% variable, but should NOT alter/remove any existing entries." n
983 "%% @spec init_per_testcase(TestCase, Config) -> Config" n
985 (erlang-skel-separator 2)
986 "init_per_testcase(_TestCase, Config) ->" n
>
989 (erlang-skel-separator 2)
992 "%% Name of the test case that is about to be run." n
993 "%% Config - [tuple()]" n
994 "%% A list of key/value pairs, holding the test case configuration." n
996 "%% Cleanup after each test case" n
998 "%% @spec end_per_testcase(TestCase, Config) -> _" n
1000 (erlang-skel-separator 2)
1001 "end_per_testcase(_TestCase, _Config) ->" n
>
1004 (erlang-skel-separator 2)
1006 "%% Clause - atom() - suite | doc" n
1007 "%% TestCases - [Case]" n
1008 "%% Case - atom()" n
1009 "%% Name of a test case." n
1011 "%% Returns a list of all test cases in this test suite" n
1013 "%% @spec all(Clause) -> TestCases" n
1015 (erlang-skel-separator 2)
1017 "[\"Describe the main purpose of this suite\"];" n n
1021 "%% Test cases starts here." n
1022 (erlang-skel-separator 2)
1023 "test_case(doc) ->" n
>
1024 "[\"Describe the main purpose of test case\"];" n n
1025 "test_case(suite) ->" n
>
1027 "test_case(Config) when is_list(Config) ->" n
>
1030 "*The template of a library module.
1031 Please see the function `tempo-define-template'.")
1033 (defvar erlang-skel-ct-test-suite
1034 '((erlang-skel-include erlang-skel-large-header
)
1035 "-suite_defaults([{timetrap, {minutes, 10}}])." n n
1037 "%% Note: This directive should only be used in test suites." n
1038 "-compile(export_all)." n n
1040 "-include(\"ct.hrl\")." n n
1042 "%% Test server callback functions" n
1043 (erlang-skel-separator 2)
1045 "%% Config - [tuple()]" n
1046 "%% A list of key/value pairs, holding the test case configuration." n
1048 "%% Initiation before the whole suite" n
1050 "%% Note: This function is free to add any key/value pairs to the Config" n
1051 "%% variable, but should NOT alter/remove any existing entries." n
1053 "%% @spec init_per_suite(Config) -> Config" n
1055 (erlang-skel-separator 2)
1056 "init_per_suite(Config) ->" n
>
1059 (erlang-skel-separator 2)
1061 "%% Config - [tuple()]" n
1062 "%% A list of key/value pairs, holding the test case configuration." n
1064 "%% Cleanup after the whole suite" n
1066 "%% @spec end_per_suite(Config) -> _" n
1068 (erlang-skel-separator 2)
1069 "end_per_suite(_Config) ->" n
>
1072 (erlang-skel-separator 2)
1074 "%% Case - atom()" n
1075 "%% Name of the test case that is about to be run." n
1076 "%% Config - [tuple()]" n
1077 "%% A list of key/value pairs, holding the test case configuration." n
1079 "%% Initiation before each test case" n
1081 "%% Note: This function is free to add any key/value pairs to the Config" n
1082 "%% variable, but should NOT alter/remove any existing entries." n
1083 "%% Initiation before each test case" n
1085 "%% @spec init_per_testcase(TestCase, Config) -> Config" n
1087 (erlang-skel-separator 2)
1088 "init_per_testcase(_TestCase, Config) ->" n
>
1091 (erlang-skel-separator 2)
1093 "%% Case - atom()" n
1094 "%% Name of the test case that is about to be run." n
1095 "%% Config - [tuple()]" n
1096 "%% A list of key/value pairs, holding the test case configuration." n
1098 "%% Cleanup after each test case" n
1100 "%% @spec end_per_testcase(TestCase, Config) -> _" n
1102 (erlang-skel-separator 2)
1103 "end_per_testcase(_TestCase, _Config) ->" n
>
1106 (erlang-skel-separator 2)
1108 "%% TestCases - [Case]" n
1109 "%% Case - atom()" n
1110 "%% Name of a test case." n
1112 "%% Returns a list of all test cases in this test suite" n
1114 "%% @spec all() -> TestCases" n
1116 (erlang-skel-separator 2)
1120 "%% Test cases starts here." n
1121 (erlang-skel-separator 2)
1122 "test_case() ->" n
>
1123 "[{doc, \"Describe the main purpose of this test case\"}]." n n
1124 "test_case(Config) when is_list(Config) ->" n
>
1127 "*The template of a library module.
1128 Please see the function `tempo-define-template'.")
1132 ;; This code is based on the package `tempo' which is part of modern
1133 ;; Emacsen. (GNU Emacs 19.25 (?) and XEmacs 19.14.)
1135 (defun erlang-skel-init ()
1136 "Generate the skeleton functions and menu items.
1137 The variable `erlang-skel' contains the name and descriptions of
1140 The skeleton routines are based on the `tempo' package. Should this
1141 package not be present, this function does nothing."
1146 (if (featurep 'tempo
)
1147 (let ((skel erlang-skel
)
1150 (cond ((null (car skel
))
1151 (setq menu
(cons nil menu
)))
1153 (funcall (symbol-function 'tempo-define-template
)
1154 (concat "erlang-" (nth 1 (car skel
)))
1155 ;; The tempo template used contains an `include'
1156 ;; function call only, hence changes to the
1157 ;; variables describing the templates take effect
1159 (list (list 'erlang-skel-include
(nth 2 (car skel
))))
1161 (setq menu
(cons (erlang-skel-make-menu-item
1162 (car skel
)) menu
))))
1163 (setq skel
(cdr skel
)))
1164 (setq erlang-menu-skel-items
1165 (list nil
(list "Skeletons" (nreverse menu
))))
1166 (setq erlang-menu-items
1167 (erlang-menu-add-above 'erlang-menu-skel-items
1168 'erlang-menu-version-items
1170 (erlang-menu-init))))
1172 (defun erlang-skel-make-menu-item (skel)
1173 (let ((func (intern (concat "tempo-template-erlang-" (nth 1 skel
)))))
1174 (cond ((null (nth 3 skel
))
1175 (list (car skel
) func
))
1181 (list 'quote
(nth 3 skel
))
1182 (list 'quote func
))))))))
1184 ;; Functions designed to be added to the skeleton menu.
1185 ;; (Not normally used)
1186 (defun erlang-skel-insert (func)
1187 "Insert skeleton generated by FUNC and goto first tempo mark."
1188 (save-excursion (funcall func
))
1189 (funcall (symbol-function 'tempo-forward-mark
)))
1191 (defun erlang-skel-header (func)
1192 "Insert the header generated by FUNC at the beginning of the buffer."
1193 (goto-char (point-min))
1194 (save-excursion (funcall func
))
1195 (funcall (symbol-function 'tempo-forward-mark
)))
1198 ;; Functions used inside the skeleton descriptions.
1199 (defun erlang-skel-skip-blank ()
1200 (skip-chars-backward " \t")
1203 (defun erlang-skel-include (&rest args
)
1204 "Include a template inside another template.
1206 Example of use, assuming that `erlang-skel-func' is defined:
1208 (defvar foo-skeleton '(\"%%% New function:\"
1209 (erlang-skel-include erlang-skel-func)))
1211 Technically, this function returns the `tempo' attribute`(l ...)' which
1212 can contain other `tempo' attributes. Please see the function
1213 `tempo-define-template' for a description of the `(l ...)' attribute."
1217 (setq entry
(car args
))
1219 (setq res
(cons (car entry
) res
))
1220 (setq entry
(cdr entry
)))
1221 (setq args
(cdr args
)))
1222 (cons 'l
(nreverse res
))))
1224 (defun erlang-skel-separator (&optional percent
)
1225 "Return a comment separator."
1226 (let ((percent (or percent
3)))
1227 (concat (make-string percent ?%
)
1228 (make-string (- 70 percent
) ?-
)
1231 (defun erlang-skel-double-separator (&optional percent
)
1232 "Return a comment separator."
1233 (let ((percent (or percent
3)))
1234 (concat (make-string percent ?%
)
1235 (make-string (- 70 percent
) ?
=)
1238 (defun erlang-skel-dd-mmm-yyyy ()
1239 "Return the current date as a string in \"DD Mon YYYY\" form.
1240 The first character of DD is space if the value is less than 10."
1241 (let ((date (current-time-string)))
1243 (string-to-int (substring date
8 10))
1244 (substring date
4 7)
1245 (substring date -
4))))
1248 ;; coding: iso-8859-1
1251 ;;; erlang.el ends here