4
;; Copyright Ericsson AB 2010. All Rights Reserved.
6
;; The contents of this file are subject to the Erlang Public License,
7
;; Version 1.1, (the "License"); you may not use this file except in
8
;; compliance with the License. You should have received a copy of the
9
;; Erlang Public License along with this software. If not, it can be
10
;; retrieved online at http://www.erlang.org/.
12
;; Software distributed under the License is distributed on an "AS IS"
13
;; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
;; the License for the specific language governing rights and limitations
19
;;; Purpose: Provide Erlang code skeletons.
20
;;; See 'erlang-skel-file' variable.
22
(defvar erlang-tempo-tags nil
23
"Tempo tags for erlang mode")
26
'(("If" "if" erlang-skel-if)
27
("Case" "case" erlang-skel-case)
28
("Receive" "receive" erlang-skel-receive)
29
("Receive After" "after" erlang-skel-receive-after)
30
("Receive Loop" "loop" erlang-skel-receive-loop)
31
("Module" "module" erlang-skel-module)
32
("Author" "author" erlang-skel-author)
33
("Function" "function" erlang-skel-function)
35
("Small Header" "small-header"
36
erlang-skel-small-header erlang-skel-header)
37
("Normal Header" "normal-header"
38
erlang-skel-normal-header erlang-skel-header)
39
("Large Header" "large-header"
40
erlang-skel-large-header erlang-skel-header)
42
("Small Server" "small-server"
43
erlang-skel-small-server erlang-skel-header)
45
("Application" "application"
46
erlang-skel-application erlang-skel-header)
47
("Supervisor" "supervisor"
48
erlang-skel-supervisor erlang-skel-header)
49
("supervisor_bridge" "supervisor-bridge"
50
erlang-skel-supervisor-bridge erlang-skel-header)
51
("gen_server" "generic-server"
52
erlang-skel-generic-server erlang-skel-header)
53
("gen_event" "gen-event"
54
erlang-skel-gen-event erlang-skel-header)
56
erlang-skel-gen-fsm erlang-skel-header)
57
("Library module" "gen-lib"
58
erlang-skel-lib erlang-skel-header)
59
("Corba callback" "gen-corba-cb"
60
erlang-skel-corba-callback erlang-skel-header)
61
("Small Common Test suite" "ct-test-suite-s"
62
erlang-skel-ct-test-suite-s erlang-skel-header)
63
("Large Common Test suite" "ct-test-suite-l"
64
erlang-skel-ct-test-suite-l erlang-skel-header)
65
("Erlang TS test suite" "ts-test-suite"
66
erlang-skel-ts-test-suite erlang-skel-header)
68
"*Description of all skeleton templates.
69
Both functions and menu entries will be created.
71
Each entry in `erlang-skel' should be a list with three or four
72
elements, or the empty list.
74
The first element is the name which shows up in the menu. The second
75
is the `tempo' identifier (The string \"erlang-\" will be added in
76
front of it). The third is the skeleton descriptor, a variable
77
containing `tempo' attributes as described in the function
78
`tempo-define-template'. The optional fourth elements denotes a
79
function which should be called when the menu is selected.
81
Functions corresponding to every template will be created. The name
82
of the function will be `tempo-template-erlang-X' where `X' is the
83
tempo identifier as specified in the second argument of the elements
86
A list with zero elements means that the a horizontal line should
87
be placed in the menu.")
89
(defvar erlang-skel-use-separators t
90
"A boolean than determines whether the skeletons include horizontal
93
Should this variable be nil, the documentation for functions will not
94
include separators of the form %%--...")
96
;; In XEmacs `user-mail-address' returns "x@y.z (Foo Bar)" ARGH!
97
;; What's wrong with that? RFC 822 says it's legal. [sverkerw]
98
;; This needs to use the customized value. If that's not sane, things like
99
;; add-log will lose anyhow. Avoid it if there _is_ a paren.
100
(defvar erlang-skel-mail-address
101
(if (or (not user-mail-address) (string-match "(" user-mail-address))
102
(concat (user-login-name) "@"
103
(or (and (boundp 'mail-host-address)
107
"Mail address of the user.")
109
;; Expression templates:
110
(defvar erlang-skel-case
111
'((erlang-skel-skip-blank) o >
112
"case " p " of" n> p "_ ->" n> p "ok" n> "end" p)
113
"*The skeleton of a `case' expression.
114
Please see the function `tempo-define-template'.")
116
(defvar erlang-skel-if
117
'((erlang-skel-skip-blank) o >
118
"if" n> p " ->" n> p "ok" n> "end" p)
119
"The skeleton of an `if' expression.
120
Please see the function `tempo-define-template'.")
122
(defvar erlang-skel-receive
123
'((erlang-skel-skip-blank) o >
124
"receive" n> p "_ ->" n> p "ok" n> "end" p)
125
"*The skeleton of a `receive' expression.
126
Please see the function `tempo-define-template'.")
128
(defvar erlang-skel-receive-after
129
'((erlang-skel-skip-blank) o >
130
"receive" n> p "_ ->" n> p "ok" n> "after " p "T ->" n>
132
"*The skeleton of a `receive' expression with an `after' clause.
133
Please see the function `tempo-define-template'.")
135
(defvar erlang-skel-receive-loop
136
'(& o "loop(" p ") ->" n> "receive" n> p "_ ->" n>
137
"loop(" p ")" n> "end.")
138
"*The skeleton of a simple `receive' loop.
139
Please see the function `tempo-define-template'.")
142
(defvar erlang-skel-function
143
'((erlang-skel-separator-start 2)
146
(erlang-skel-separator-end 2))
147
"*The template of a function skeleton.
148
Please see the function `tempo-define-template'.")
151
;; Attribute templates
153
(defvar erlang-skel-module
155
(erlang-add-quotes-if-needed (erlang-get-module-from-file-name))
157
"*The skeleton of a `module' attribute.
158
Please see the function `tempo-define-template'.")
160
(defvar erlang-skel-author
161
'(& "-author('" erlang-skel-mail-address "')." n)
162
"*The skeleton of a `author' attribute.
163
Please see the function `tempo-define-template'.")
165
(defvar erlang-skel-vc nil
166
"*The skeleton template to generate a version control attribute.
167
The default is to insert nothing. Example of usage:
169
(setq erlang-skel-vc '(& \"-rcs(\\\"$\Id: $ \\\").\") n)
171
Please see the function `tempo-define-template'.")
173
(defvar erlang-skel-export
174
'(& "-export([" n> "])." n)
175
"*The skeleton of an `export' attribute.
176
Please see the function `tempo-define-template'.")
178
(defvar erlang-skel-import
179
'(& "%%-import(Module, [Function/Arity, ...])." n)
180
"*The skeleton of an `import' attribute.
181
Please see the function `tempo-define-template'.")
183
(defvar erlang-skel-compile nil
184
;; '(& "%%-compile(export_all)." n)
185
"*The skeleton of a `compile' attribute.
186
Please see the function `tempo-define-template'.")
189
;; Comment templates.
191
(defvar erlang-skel-date-function 'erlang-skel-dd-mmm-yyyy
192
"*Function which returns date string.
193
Look in the module `time-stamp' for a battery of functions.")
195
(defvar erlang-skel-copyright-comment
196
(if (boundp '*copyright-organization*)
197
'(& "%%% @copyright (C) " (format-time-string "%Y") ", "
198
*copyright-organization* n)
199
'(& "%%% @copyright (C) " (format-time-string "%Y") ", "
201
"*The template for a copyright line in the header, normally empty.
202
This variable should be bound to a `tempo' template, for example:
203
'(& \"%%% Copyright (C) 2000, Yoyodyne, Inc.\" n)
204
Please see the function `tempo-define-template'.")
206
(defvar erlang-skel-created-comment
207
'(& "%%% Created : " (funcall erlang-skel-date-function) " by "
208
(user-full-name) " <" erlang-skel-mail-address ">" n)
209
"*The template for the \"Created:\" comment line.")
211
(defvar erlang-skel-author-comment
212
'(& "%%% @author " (user-full-name) " <" erlang-skel-mail-address ">" n)
213
"*The template for creating the \"Author:\" line in the header.
214
Please see the function `tempo-define-template'.")
216
(defvar erlang-skel-small-header
217
'(o (erlang-skel-include erlang-skel-module)
219
(erlang-skel-include erlang-skel-compile erlang-skel-vc))
220
"*The template of a small header without any comments.
221
Please see the function `tempo-define-template'.")
223
(defvar erlang-skel-normal-header
224
'(o (erlang-skel-include erlang-skel-author-comment)
225
(erlang-skel-include erlang-skel-copyright-comment)
229
(erlang-skel-include erlang-skel-created-comment) n
230
(erlang-skel-include erlang-skel-small-header) n)
231
"*The template of a normal header.
232
Please see the function `tempo-define-template'.")
234
(defvar erlang-skel-large-header
235
'(o (erlang-skel-separator)
236
(erlang-skel-include erlang-skel-author-comment)
237
(erlang-skel-include erlang-skel-copyright-comment)
241
(erlang-skel-include erlang-skel-created-comment)
242
(erlang-skel-separator)
243
(erlang-skel-include erlang-skel-small-header) )
244
"*The template of a large header.
245
Please see the function `tempo-define-template'.")
249
(defvar erlang-skel-small-server
250
'((erlang-skel-include erlang-skel-large-header)
251
"-export([start/0, init/1])." n n n
252
"start() ->" n> "spawn(" (erlang-get-module-from-file-name)
253
", init, [self()])." n n
262
"*Template of a small server.
263
Please see the function `tempo-define-template'.")
265
;; Behaviour templates.
266
(defvar erlang-skel-application
267
'((erlang-skel-include erlang-skel-large-header)
268
"-behaviour(application)." n n
269
"%% Application callbacks" n
270
"-export([start/2, stop/1])." n n
271
(erlang-skel-double-separator-start 3)
272
"%%% Application callbacks" n
273
(erlang-skel-double-separator-end 3) n
274
(erlang-skel-separator-start 2)
277
"%% This function is called whenever an application is started using" n
278
"%% application:start/[1,2], and should start the processes of the" n
279
"%% application. If the application is structured according to the OTP" n
280
"%% design principles as a supervision tree, this means starting the" n
281
"%% top supervisor of the tree." n
283
"%% @spec start(StartType, StartArgs) -> {ok, Pid} |" n
284
"%% {ok, Pid, State} |" n
285
"%% {error, Reason}" n
286
"%% StartType = normal | {takeover, Node} | {failover, Node}" n
287
"%% StartArgs = term()" n
288
(erlang-skel-separator-end 2)
289
"start(_StartType, _StartArgs) ->" n>
290
"case 'TopSupervisor':start_link() of" n>
297
(erlang-skel-separator-start 2)
300
"%% This function is called whenever an application has stopped. It" n
301
"%% is intended to be the opposite of Module:start/2 and should do" n
302
"%% any necessary cleaning up. The return value is ignored." n
304
"%% @spec stop(State) -> void()" n
305
(erlang-skel-separator-end 2)
309
(erlang-skel-double-separator-start 3)
310
"%%% Internal functions" n
311
(erlang-skel-double-separator-end 3)
313
"*The template of an application behaviour.
314
Please see the function `tempo-define-template'.")
316
(defvar erlang-skel-supervisor
317
'((erlang-skel-include erlang-skel-large-header)
318
"-behaviour(supervisor)." n n
321
"-export([start_link/0])." n n
323
"%% Supervisor callbacks" n
324
"-export([init/1])." n n
326
"-define(SERVER, ?MODULE)." n n
328
(erlang-skel-double-separator-start 3)
329
"%%% API functions" n
330
(erlang-skel-double-separator-end 3) n
331
(erlang-skel-separator-start 2)
333
"%% Starts the supervisor" n
335
"%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
336
(erlang-skel-separator-end 2)
338
"supervisor:start_link({local, ?SERVER}, ?MODULE, [])." n
340
(erlang-skel-double-separator-start 3)
341
"%%% Supervisor callbacks" n
342
(erlang-skel-double-separator-end 3) n
343
(erlang-skel-separator-start 2)
346
"%% Whenever a supervisor is started using supervisor:start_link/[2,3]," n
347
"%% this function is called by the new process to find out about" n
348
"%% restart strategy, maximum restart frequency and child" n
349
"%% specifications." n
351
"%% @spec init(Args) -> {ok, {SupFlags, [ChildSpec]}} |" n
353
"%% {error, Reason}" n
354
(erlang-skel-separator-end 2)
356
"RestartStrategy = one_for_one," n>
357
"MaxRestarts = 1000," n>
358
"MaxSecondsBetweenRestarts = 3600," n
360
"SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}," n
362
"Restart = permanent," n>
363
"Shutdown = 2000," n>
366
"AChild = {'AName', {'AModule', start_link, []}," n>
367
"Restart, Shutdown, Type, ['AModule']}," n
369
"{ok, {SupFlags, [AChild]}}." n
371
(erlang-skel-double-separator-start 3)
372
"%%% Internal functions" n
373
(erlang-skel-double-separator-end 3)
375
"*The template of an supervisor behaviour.
376
Please see the function `tempo-define-template'.")
378
(defvar erlang-skel-supervisor-bridge
379
'((erlang-skel-include erlang-skel-large-header)
380
"-behaviour(supervisor_bridge)." n n
383
"-export([start_link/0])." n n
385
"%% supervisor_bridge callbacks" n
386
"-export([init/1, terminate/2])." n n
388
"-define(SERVER, ?MODULE)." n n
390
"-record(state, {})." n n
392
(erlang-skel-double-separator-start 3)
394
(erlang-skel-double-separator-end 3) n
395
(erlang-skel-separator-start 2)
397
"%% Starts the supervisor bridge" n
399
"%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
400
(erlang-skel-separator-end 2)
402
"supervisor_bridge:start_link({local, ?SERVER}, ?MODULE, [])." n
404
(erlang-skel-double-separator-start 3)
405
"%%% supervisor_bridge callbacks" n
406
(erlang-skel-double-separator-end 3) n
407
(erlang-skel-separator-start 2)
410
"%% Creates a supervisor_bridge process, linked to the calling process," n
411
"%% which calls Module:init/1 to start the subsystem. To ensure a" n
412
"%% synchronized start-up procedure, this function does not return" n
413
"%% until Module:init/1 has returned." n
415
"%% @spec init(Args) -> {ok, Pid, State} |" n
417
"%% {error, Reason}" n
418
(erlang-skel-separator-end 2)
420
"case 'AModule':start_link() of" n>
422
"{ok, Pid, #state{}};" n>
427
(erlang-skel-separator-start 2)
430
"%% This function is called by the supervisor_bridge when it is about" n
431
"%% to terminate. It should be the opposite of Module:init/1 and stop" n
432
"%% the subsystem and do any necessary cleaning up.The return value is" n
435
"%% @spec terminate(Reason, State) -> void()" n
436
(erlang-skel-separator-end 2)
437
"terminate(Reason, State) ->" n>
438
"'AModule':stop()," n>
441
(erlang-skel-double-separator-start 3)
442
"%%% Internal functions" n
443
(erlang-skel-double-separator-end 3)
445
"*The template of an supervisor_bridge behaviour.
446
Please see the function `tempo-define-template'.")
448
(defvar erlang-skel-generic-server
449
'((erlang-skel-include erlang-skel-large-header)
450
"-behaviour(gen_server)." n n
453
"-export([start_link/0])." n n
455
"%% gen_server callbacks" n
456
"-export([init/1, handle_call/3, handle_cast/2, "
458
"terminate/2, code_change/3])." n n
460
"-define(SERVER, ?MODULE). " n n
462
"-record(state, {})." n n
464
(erlang-skel-double-separator-start 3)
466
(erlang-skel-double-separator-end 3) n
467
(erlang-skel-separator-start 2)
469
"%% Starts the server" n
471
"%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
472
(erlang-skel-separator-end 2)
474
"gen_server:start_link({local, ?SERVER}, ?MODULE, [], [])." n
476
(erlang-skel-double-separator-start 3)
477
"%%% gen_server callbacks" n
478
(erlang-skel-double-separator-end 3)
480
(erlang-skel-separator-start 2)
483
"%% Initializes the server" n
485
"%% @spec init(Args) -> {ok, State} |" n
486
"%% {ok, State, Timeout} |" n
488
"%% {stop, Reason}" n
489
(erlang-skel-separator-end 2)
493
(erlang-skel-separator-start 2)
496
"%% Handling call messages" n
498
"%% @spec handle_call(Request, From, State) ->" n
499
"%% {reply, Reply, State} |" n
500
"%% {reply, Reply, State, Timeout} |" n
501
"%% {noreply, State} |" n
502
"%% {noreply, State, Timeout} |" n
503
"%% {stop, Reason, Reply, State} |" n
504
"%% {stop, Reason, State}" n
505
(erlang-skel-separator-end 2)
506
"handle_call(_Request, _From, State) ->" n>
508
"{reply, Reply, State}." n
510
(erlang-skel-separator-start 2)
513
"%% Handling cast messages" n
515
"%% @spec handle_cast(Msg, State) -> {noreply, State} |" n
516
"%% {noreply, State, Timeout} |" n
517
"%% {stop, Reason, State}" n
518
(erlang-skel-separator-end 2)
519
"handle_cast(_Msg, State) ->" n>
520
"{noreply, State}." n
522
(erlang-skel-separator-start 2)
525
"%% Handling all non call/cast messages" n
527
"%% @spec handle_info(Info, State) -> {noreply, State} |" n
528
"%% {noreply, State, Timeout} |" n
529
"%% {stop, Reason, State}" n
530
(erlang-skel-separator-end 2)
531
"handle_info(_Info, State) ->" n>
532
"{noreply, State}." n
534
(erlang-skel-separator-start 2)
537
"%% This function is called by a gen_server when it is about to" n
538
"%% terminate. It should be the opposite of Module:init/1 and do any" n
539
"%% necessary cleaning up. When it returns, the gen_server terminates" n
540
"%% with Reason. The return value is ignored." n
542
"%% @spec terminate(Reason, State) -> void()" n
543
(erlang-skel-separator-end 2)
544
"terminate(_Reason, _State) ->" n>
547
(erlang-skel-separator-start 2)
550
"%% Convert process state when code is changed" n
552
"%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
553
(erlang-skel-separator-end 2)
554
"code_change(_OldVsn, State, _Extra) ->" n>
557
(erlang-skel-double-separator-start 3)
558
"%%% Internal functions" n
559
(erlang-skel-double-separator-end 3)
561
"*The template of a generic server.
562
Please see the function `tempo-define-template'.")
564
(defvar erlang-skel-gen-event
565
'((erlang-skel-include erlang-skel-large-header)
566
"-behaviour(gen_event)." n n
569
"-export([start_link/0, add_handler/0])." n n
571
"%% gen_event callbacks" n
572
"-export([init/1, handle_event/2, handle_call/2, " n>
573
"handle_info/2, terminate/2, code_change/3])." n n
575
"-define(SERVER, ?MODULE). " n n
577
"-record(state, {})." n n
579
(erlang-skel-double-separator-start 3)
580
"%%% gen_event callbacks" n
581
(erlang-skel-double-separator-end 3) n
582
(erlang-skel-separator-start 2)
584
"%% Creates an event manager" n
586
"%% @spec start_link() -> {ok, Pid} | {error, Error}" n
587
(erlang-skel-separator-end 2)
589
"gen_event:start_link({local, ?SERVER})." n
591
(erlang-skel-separator-start 2)
593
"%% Adds an event handler" n
595
"%% @spec add_handler() -> ok | {'EXIT', Reason} | term()" n
596
(erlang-skel-separator-end 2)
597
"add_handler() ->" n>
598
"gen_event:add_handler(?SERVER, ?MODULE, [])." n
600
(erlang-skel-double-separator-start 3)
601
"%%% gen_event callbacks" n
602
(erlang-skel-double-separator-end 3) n
603
(erlang-skel-separator-start 2)
606
"%% Whenever a new event handler is added to an event manager," n
607
"%% this function is called to initialize the event handler." n
609
"%% @spec init(Args) -> {ok, State}" n
610
(erlang-skel-separator-end 2)
614
(erlang-skel-separator-start 2)
617
"%% Whenever an event manager receives an event sent using" n
618
"%% gen_event:notify/2 or gen_event:sync_notify/2, this function is" n
619
"%% called for each installed event handler to handle the event." n
621
"%% @spec handle_event(Event, State) ->" n
623
"%% {swap_handler, Args1, State1, Mod2, Args2} |"n
624
"%% remove_handler" n
625
(erlang-skel-separator-end 2)
626
"handle_event(_Event, State) ->" n>
629
(erlang-skel-separator-start 2)
632
"%% Whenever an event manager receives a request sent using" n
633
"%% gen_event:call/3,4, this function is called for the specified" n
634
"%% event handler to handle the request." n
636
"%% @spec handle_call(Request, State) ->" n
637
"%% {ok, Reply, State} |" n
638
"%% {swap_handler, Reply, Args1, State1, Mod2, Args2} |" n
639
"%% {remove_handler, Reply}" n
640
(erlang-skel-separator-end 2)
641
"handle_call(_Request, State) ->" n>
643
"{ok, Reply, State}." n
645
(erlang-skel-separator-start 2)
648
"%% This function is called for each installed event handler when" n
649
"%% an event manager receives any other message than an event or a" n
650
"%% synchronous request (or a system message)." n
652
"%% @spec handle_info(Info, State) ->" n
654
"%% {swap_handler, Args1, State1, Mod2, Args2} |" n
655
"%% remove_handler" n
656
(erlang-skel-separator-end 2)
657
"handle_info(_Info, State) ->" n>
660
(erlang-skel-separator-start 2)
663
"%% Whenever an event handler is deleted from an event manager, this" n
664
"%% function is called. It should be the opposite of Module:init/1 and" n
665
"%% do any necessary cleaning up." n
667
"%% @spec terminate(Reason, State) -> void()" n
668
(erlang-skel-separator-end 2)
669
"terminate(_Reason, _State) ->" n>
672
(erlang-skel-separator-start 2)
675
"%% Convert process state when code is changed" n
677
"%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
678
(erlang-skel-separator-end 2)
679
"code_change(_OldVsn, State, _Extra) ->" n>
682
(erlang-skel-double-separator-start 3)
683
"%%% Internal functions" n
684
(erlang-skel-double-separator-end 3)
686
"*The template of a gen_event.
687
Please see the function `tempo-define-template'.")
689
(defvar erlang-skel-gen-fsm
690
'((erlang-skel-include erlang-skel-large-header)
691
"-behaviour(gen_fsm)." n n
694
"-export([start_link/0])." n n
696
"%% gen_fsm callbacks" n
697
"-export([init/1, state_name/2, state_name/3, handle_event/3," n>
698
"handle_sync_event/4, handle_info/3, terminate/3, code_change/4])." n n
700
"-define(SERVER, ?MODULE)." n n
702
"-record(state, {})." n n
704
(erlang-skel-double-separator-start 3)
706
(erlang-skel-double-separator-end 3) n
707
(erlang-skel-separator-start 2)
709
"%% Creates a gen_fsm process which calls Module:init/1 to" n
710
"%% initialize. To ensure a synchronized start-up procedure, this" n
711
"%% function does not return until Module:init/1 has returned." n
713
"%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
714
(erlang-skel-separator-end 2)
716
"gen_fsm:start_link({local, ?SERVER}, ?MODULE, [], [])." n
718
(erlang-skel-double-separator-start 3)
719
"%%% gen_fsm callbacks" n
720
(erlang-skel-double-separator-end 3) n
721
(erlang-skel-separator-start 2)
724
"%% Whenever a gen_fsm is started using gen_fsm:start/[3,4] or" n
725
"%% gen_fsm:start_link/[3,4], this function is called by the new" n
726
"%% process to initialize." n
728
"%% @spec init(Args) -> {ok, StateName, State} |" n
729
"%% {ok, StateName, State, Timeout} |" n
731
"%% {stop, StopReason}" n
732
(erlang-skel-separator-end 2)
734
"{ok, state_name, #state{}}." n
736
(erlang-skel-separator-start 2)
739
"%% There should be one instance of this function for each possible" n
740
"%% state name. Whenever a gen_fsm receives an event sent using" n
741
"%% gen_fsm:send_event/2, the instance of this function with the same" n
742
"%% name as the current state name StateName is called to handle" n
743
"%% the event. It is also called if a timeout occurs." n
745
"%% @spec state_name(Event, State) ->" n
746
"%% {next_state, NextStateName, NextState} |" n
747
"%% {next_state, NextStateName, NextState, Timeout} |" n
748
"%% {stop, Reason, NewState}" n
749
(erlang-skel-separator-end 2)
750
"state_name(_Event, State) ->" n>
751
"{next_state, state_name, State}." n
753
(erlang-skel-separator-start 2)
756
"%% There should be one instance of this function for each possible" n
757
"%% state name. Whenever a gen_fsm receives an event sent using" n
758
"%% gen_fsm:sync_send_event/[2,3], the instance of this function with" n
759
"%% the same name as the current state name StateName is called to" n
760
"%% handle the event." n
762
"%% @spec state_name(Event, From, State) ->" n
763
"%% {next_state, NextStateName, NextState} |"n
764
"%% {next_state, NextStateName, NextState, Timeout} |" n
765
"%% {reply, Reply, NextStateName, NextState} |" n
766
"%% {reply, Reply, NextStateName, NextState, Timeout} |" n
767
"%% {stop, Reason, NewState} |" n
768
"%% {stop, Reason, Reply, NewState}" n
769
(erlang-skel-separator-end 2)
770
"state_name(_Event, _From, State) ->" n>
772
"{reply, Reply, state_name, State}." n
774
(erlang-skel-separator-start 2)
777
"%% Whenever a gen_fsm receives an event sent using" n
778
"%% gen_fsm:send_all_state_event/2, this function is called to handle" n
781
"%% @spec handle_event(Event, StateName, State) ->" n
782
"%% {next_state, NextStateName, NextState} |" n
783
"%% {next_state, NextStateName, NextState, Timeout} |" n
784
"%% {stop, Reason, NewState}" n
785
(erlang-skel-separator-end 2)
786
"handle_event(_Event, StateName, State) ->" n>
787
"{next_state, StateName, State}." n
789
(erlang-skel-separator-start 2)
792
"%% Whenever a gen_fsm receives an event sent using" n
793
"%% gen_fsm:sync_send_all_state_event/[2,3], this function is called" n
794
"%% to handle the event." n
796
"%% @spec handle_sync_event(Event, From, StateName, State) ->" n
797
"%% {next_state, NextStateName, NextState} |" n
798
"%% {next_state, NextStateName, NextState, Timeout} |" n
799
"%% {reply, Reply, NextStateName, NextState} |" n
800
"%% {reply, Reply, NextStateName, NextState, Timeout} |" n
801
"%% {stop, Reason, NewState} |" n
802
"%% {stop, Reason, Reply, NewState}" n
803
(erlang-skel-separator-end 2)
804
"handle_sync_event(_Event, _From, StateName, State) ->" n>
806
"{reply, Reply, StateName, State}." n
808
(erlang-skel-separator-start 2)
811
"%% This function is called by a gen_fsm when it receives any" n
812
"%% message other than a synchronous or asynchronous event" n
813
"%% (or a system message)." n
815
"%% @spec handle_info(Info,StateName,State)->" n
816
"%% {next_state, NextStateName, NextState} |" n
817
"%% {next_state, NextStateName, NextState, Timeout} |" n
818
"%% {stop, Reason, NewState}" n
819
(erlang-skel-separator-end 2)
820
"handle_info(_Info, StateName, State) ->" n>
821
"{next_state, StateName, State}." n
823
(erlang-skel-separator-start 2)
826
"%% This function is called by a gen_fsm when it is about to" n
827
"%% terminate. It should be the opposite of Module:init/1 and do any" n
828
"%% necessary cleaning up. When it returns, the gen_fsm terminates with" n
829
"%% Reason. The return value is ignored." n
831
"%% @spec terminate(Reason, StateName, State) -> void()" n
832
(erlang-skel-separator-end 2)
833
"terminate(_Reason, _StateName, _State) ->" n>
836
(erlang-skel-separator-start 2)
839
"%% Convert process state when code is changed" n
841
"%% @spec code_change(OldVsn, StateName, State, Extra) ->" n
842
"%% {ok, StateName, NewState}" n
843
(erlang-skel-separator-end 2)
844
"code_change(_OldVsn, StateName, State, _Extra) ->" n>
845
"{ok, StateName, State}." n
847
(erlang-skel-double-separator-start 3)
848
"%%% Internal functions" n
849
(erlang-skel-double-separator-end 3)
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-start 3)
862
(erlang-skel-double-separator-end 3) n
863
(erlang-skel-separator-start 2)
866
(erlang-skel-separator-end 2)
868
(erlang-skel-double-separator-start 3)
869
"%%% Internal functions" n
870
(erlang-skel-double-separator-end 3)
872
"*The template of a library module.
873
Please see the function `tempo-define-template'.")
875
(defvar erlang-skel-corba-callback
876
'((erlang-skel-include erlang-skel-large-header)
877
"%% Include files" n n
882
"%% Corba callbacks" n
883
"-export([init/1, terminate/2, code_change/3])." n n
885
"-record(state, {})." n n
887
(erlang-skel-double-separator-start 3)
888
"%%% Corba callbacks" n
889
(erlang-skel-double-separator-end 3) n
890
(erlang-skel-separator-start 2)
893
"%% Initializes the server" n
895
"%% @spec init(Args) -> {ok, State} |" n
896
"%% {ok, State, Timeout} |" n
898
"%% {stop, Reason}" n
899
(erlang-skel-separator-end 2)
903
(erlang-skel-separator-start 2)
906
"%% Shutdown the server" n
908
"%% @spec terminate(Reason, State) -> void()" n
909
(erlang-skel-separator-end 2)
910
"terminate(_Reason, _State) ->" n>
913
(erlang-skel-separator-start 2)
916
"%% Convert process state when code is changed" n
918
"%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
919
(erlang-skel-separator-end 2)
920
"code_change(_OldVsn, State, _Extra) ->" n>
923
(erlang-skel-double-separator-start 3)
924
"%%% Internal functions" n
925
(erlang-skel-double-separator-end 3)
927
"*The template of a library module.
928
Please see the function `tempo-define-template'.")
930
(defvar erlang-skel-ts-test-suite
931
'((erlang-skel-include erlang-skel-large-header)
932
"%% Note: This directive should only be used in test suites." n
933
"-compile(export_all)." n n
935
"-include_lib(\"test_server/include/test_server.hrl\")." n n
937
(erlang-skel-separator-start 2)
938
"%% TEST SERVER CALLBACK FUNCTIONS" n
939
(erlang-skel-separator 2)
941
(erlang-skel-separator-start 2)
944
"%% Initialization before the suite." n
946
"%% Config0 = Config1 = [tuple()]" n
947
"%% A list of key/value pairs, holding the test case configuration." n
948
"%% Reason = term()" n
949
"%% The reason for skipping the suite." n
951
"%% Note: This function is free to add any key/value pairs to the Config" n
952
"%% variable, but should NOT alter/remove any existing entries." n
954
"%% @spec init_per_suite(Config) -> Config" n
955
(erlang-skel-separator-end 2)
956
"init_per_suite(Config) ->" n >
959
(erlang-skel-separator-start 2)
961
"%% Cleanup after the suite." n
962
"%% Config - [tuple()]" n
963
"%% A list of key/value pairs, holding the test case configuration." n
965
"%% @spec end_per_suite(Config) -> _" n
966
(erlang-skel-separator-end 2)
967
"end_per_suite(_Config) ->" n >
970
(erlang-skel-separator-start 2)
972
"%% Initialization before each test case" n
974
"%% TestCase - atom()" n
975
"%% Name of the test case that is about to be run." n
976
"%% Config - [tuple()]" n
977
"%% A list of key/value pairs, holding the test case configuration." n
978
"%% Reason = term()" n
979
"%% The reason for skipping the test case." n
981
"%% Note: This function is free to add any key/value pairs to the Config" n
982
"%% variable, but should NOT alter/remove any existing entries." n
984
"%% @spec init_per_testcase(TestCase, Config) -> Config" n
985
(erlang-skel-separator-end 2)
986
"init_per_testcase(_TestCase, Config) ->" n >
989
(erlang-skel-separator-start 2)
991
"%% Cleanup after each test case" n
993
"%% TestCase = atom()" n
994
"%% Name of the test case that is finished." n
995
"%% Config = [tuple()]" n
996
"%% A list of key/value pairs, holding the test case configuration." n
998
"%% @spec end_per_testcase(TestCase, Config) -> _" n
999
(erlang-skel-separator-end 2)
1000
"end_per_testcase(_TestCase, _Config) ->" n >
1003
(erlang-skel-separator-start 2)
1005
"%% Returns a description of the test suite when" n
1006
"%% Clause == doc, and a test specification (list" n
1007
"%% of the conf and test cases in the suite) when" n
1008
"%% Clause == suite." n
1009
"%% Returns a list of all test cases in this test suite" n
1011
"%% Clause = doc | suite" n
1012
"%% Indicates expected return value." n
1013
"%% Descr = [string()] | []" n
1014
"%% String that describes the test suite." n
1015
"%% Spec = [TestCase]" n
1016
"%% A test specification." n
1017
"%% TestCase = ConfCase | atom()" n
1018
"%% Configuration case, or the name of a test case function." n
1019
"%% ConfCase = {conf,Init,Spec,End} |" n
1020
"%% {conf,Properties,Init,Spec,End}" n
1021
"%% Init = End = {Mod,Func} | Func" n
1022
"%% Initialization and cleanup function." n
1023
"%% Mod = Func = atom()" n
1024
"%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]" n
1025
"%% Execution properties of the test cases (may be combined)." n
1026
"%% Shuffle = shuffle | {shuffle,Seed}" n
1027
"%% To get cases executed in random order." n
1028
"%% Seed = {integer(),integer(),integer()}" n
1029
"%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |" n
1030
"%% repeat_until_any_ok | repeat_until_any_fail" n
1031
"%% To get execution of cases repeated." n
1032
"%% N = integer() | forever" n
1033
"%% Reason = term()" n
1034
"%% The reason for skipping the test suite." n
1036
"%% @spec all(Clause) -> TestCases" n
1037
(erlang-skel-separator-end 2)
1039
"[\"Describe the main purpose of this suite\"];" n n
1040
"all(suite) -> " n >
1041
"[a_test_case]." n n
1043
(erlang-skel-separator-start 2)
1045
(erlang-skel-separator 2)
1047
(erlang-skel-separator-start 2)
1049
"%% Test case function. Returns a description of the test" n
1050
"%% case (doc), then returns a test specification (suite)," n
1051
"%% or performs the actual test (Config)." n
1053
"%% Arg = doc | suite | Config" n
1054
"%% Indicates expected behaviour and return value." n
1055
"%% Config = [tuple()]" n
1056
"%% A list of key/value pairs, holding the test case configuration." n
1057
"%% Descr = [string()] | []" n
1058
"%% String that describes the test case." n
1059
"%% Spec = [tuple()] | []" n
1060
"%% A test specification, see all/1." n
1061
"%% Reason = term()" n
1062
"%% The reason for skipping the test case." n
1064
"%% @spec TestCase(Arg) -> Descr | Spec | ok | exit() | {skip,Reason}" n
1066
(erlang-skel-separator-end 2)
1067
"a_test_case(doc) -> " n >
1068
"[\"Describe the main purpose of this test case\"];" n n
1069
"a_test_case(suite) -> " n >
1071
"a_test_case(Config) when is_list(Config) -> " n >
1074
"*The template of a library module.
1075
Please see the function `tempo-define-template'.")
1077
(defvar erlang-skel-ct-test-suite-s
1078
'((erlang-skel-include erlang-skel-large-header)
1079
"-compile(export_all)." n n
1081
"-include_lib(\"common_test/include/ct.hrl\")." n n
1083
(erlang-skel-separator-start 2)
1084
"%% @spec suite() -> Info" n
1085
"%% Info = [tuple()]" n
1086
(erlang-skel-separator-end 2)
1088
"[{timetrap,{seconds,30}}]." n n
1090
(erlang-skel-separator-start 2)
1091
"%% @spec init_per_suite(Config0) ->" n
1092
"%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1093
"%% Config0 = Config1 = [tuple()]" n
1094
"%% Reason = term()" n
1095
(erlang-skel-separator-end 2)
1096
"init_per_suite(Config) ->" n >
1099
(erlang-skel-separator-start 2)
1100
"%% @spec end_per_suite(Config0) -> void() | {save_config,Config1}" n
1101
"%% Config0 = Config1 = [tuple()]" n
1102
(erlang-skel-separator-end 2)
1103
"end_per_suite(_Config) ->" n >
1106
(erlang-skel-separator-start 2)
1107
"%% @spec init_per_group(GroupName, Config0) ->" n
1108
"%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1109
"%% GroupName = atom()" n
1110
"%% Config0 = Config1 = [tuple()]" n
1111
"%% Reason = term()" n
1112
(erlang-skel-separator-end 2)
1113
"init_per_group(_GroupName, Config) ->" n >
1116
(erlang-skel-separator-start 2)
1117
"%% @spec end_per_group(GroupName, Config0) ->" n
1118
"%% void() | {save_config,Config1}" n
1119
"%% GroupName = atom()" n
1120
"%% Config0 = Config1 = [tuple()]" n
1121
(erlang-skel-separator-end 2)
1122
"end_per_group(_GroupName, _Config) ->" n >
1125
(erlang-skel-separator-start 2)
1126
"%% @spec init_per_testcase(TestCase, Config0) ->" n
1127
"%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1128
"%% TestCase = atom()" n
1129
"%% Config0 = Config1 = [tuple()]" n
1130
"%% Reason = term()" n
1131
(erlang-skel-separator-end 2)
1132
"init_per_testcase(_TestCase, Config) ->" n >
1135
(erlang-skel-separator-start 2)
1136
"%% @spec end_per_testcase(TestCase, Config0) ->" n
1137
"%% void() | {save_config,Config1} | {fail,Reason}" n
1138
"%% TestCase = atom()" n
1139
"%% Config0 = Config1 = [tuple()]" n
1140
"%% Reason = term()" n
1141
(erlang-skel-separator-end 2)
1142
"end_per_testcase(_TestCase, _Config) ->" n >
1145
(erlang-skel-separator-start 2)
1146
"%% @spec groups() -> [Group]" n
1147
"%% Group = {GroupName,Properties,GroupsAndTestCases}" n
1148
"%% GroupName = atom()" n
1149
"%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]" n
1150
"%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]" n
1151
"%% TestCase = atom()" n
1152
"%% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}" n
1153
"%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |" n
1154
"%% repeat_until_any_ok | repeat_until_any_fail" n
1155
"%% N = integer() | forever" n
1156
(erlang-skel-separator-end 2)
1160
(erlang-skel-separator-start 2)
1161
"%% @spec all() -> GroupsAndTestCases | {skip,Reason}" n
1162
"%% GroupsAndTestCases = [{group,GroupName} | TestCase]" n
1163
"%% GroupName = atom()" n
1164
"%% TestCase = atom()" n
1165
"%% Reason = term()" n
1166
(erlang-skel-separator-end 2)
1168
"[my_test_case]." n n
1170
(erlang-skel-separator-start 2)
1171
"%% @spec TestCase() -> Info" n
1172
"%% Info = [tuple()]" n
1173
(erlang-skel-separator-end 2)
1174
"my_test_case() -> " n >
1177
(erlang-skel-separator-start 2)
1178
"%% @spec TestCase(Config0) ->" n
1179
"%% ok | exit() | {skip,Reason} | {comment,Comment} |" n
1180
"%% {save_config,Config1} | {skip_and_save,Reason,Config1}" n
1181
"%% Config0 = Config1 = [tuple()]" n
1182
"%% Reason = term()" n
1183
"%% Comment = term()" n
1184
(erlang-skel-separator-end 2)
1185
"my_test_case(_Config) -> " n >
1188
"*The template of a library module.
1189
Please see the function `tempo-define-template'.")
1192
(defvar erlang-skel-ct-test-suite-l
1193
'((erlang-skel-include erlang-skel-large-header)
1194
"%% Note: This directive should only be used in test suites." n
1195
"-compile(export_all)." n n
1197
"-include_lib(\"common_test/include/ct.hrl\")." n n
1199
(erlang-skel-separator-start 2)
1200
"%% COMMON TEST CALLBACK FUNCTIONS" n
1201
(erlang-skel-separator 2)
1203
(erlang-skel-separator-start 2)
1205
"%% Returns list of tuples to set default properties" n
1206
"%% for the suite." n
1208
"%% Function: suite() -> Info" n
1210
"%% Info = [tuple()]" n
1211
"%% List of key/value pairs." n
1213
"%% Note: The suite/0 function is only meant to be used to return" n
1214
"%% default data values, not perform any other operations." n
1216
"%% @spec suite() -> Info" n
1217
(erlang-skel-separator-end 2)
1219
"[{timetrap,{minutes,10}}]." n n
1221
(erlang-skel-separator-start 2)
1223
"%% Initialization before the whole suite" n
1225
"%% Config0 = Config1 = [tuple()]" n
1226
"%% A list of key/value pairs, holding the test case configuration." n
1227
"%% Reason = term()" n
1228
"%% The reason for skipping the suite." n
1230
"%% Note: This function is free to add any key/value pairs to the Config" n
1231
"%% variable, but should NOT alter/remove any existing entries." n
1233
"%% @spec init_per_suite(Config0) ->" n
1234
"%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1235
(erlang-skel-separator-end 2)
1236
"init_per_suite(Config) ->" n >
1239
(erlang-skel-separator-start 2)
1241
"%% Cleanup after the whole suite" n
1243
"%% Config - [tuple()]" n
1244
"%% A list of key/value pairs, holding the test case configuration." n
1246
"%% @spec end_per_suite(Config) -> _" n
1247
(erlang-skel-separator-end 2)
1248
"end_per_suite(_Config) ->" n >
1251
(erlang-skel-separator-start 2)
1253
"%% Initialization before each test case group." n
1255
"%% GroupName = atom()" n
1256
"%% Name of the test case group that is about to run." n
1257
"%% Config0 = Config1 = [tuple()]" n
1258
"%% A list of key/value pairs, holding configuration data for the group." n
1259
"%% Reason = term()" n
1260
"%% The reason for skipping all test cases and subgroups in the group." n
1262
"%% @spec init_per_group(GroupName, Config0) ->" n
1263
"%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1264
(erlang-skel-separator-end 2)
1265
"init_per_group(_GroupName, Config) ->" n >
1268
(erlang-skel-separator-start 2)
1270
"%% Cleanup after each test case group." n
1272
"%% GroupName = atom()" n
1273
"%% Name of the test case group that is finished." n
1274
"%% Config0 = Config1 = [tuple()]" n
1275
"%% A list of key/value pairs, holding configuration data for the group." n
1277
"%% @spec end_per_group(GroupName, Config0) ->" n
1278
"%% void() | {save_config,Config1}" n
1279
(erlang-skel-separator-end 2)
1280
"end_per_group(_GroupName, _Config) ->" n >
1282
(erlang-skel-separator-start 2)
1284
"%% Initialization before each test case" n
1286
"%% TestCase - atom()" n
1287
"%% Name of the test case that is about to be run." n
1288
"%% Config0 = Config1 = [tuple()]" n
1289
"%% A list of key/value pairs, holding the test case configuration." n
1290
"%% Reason = term()" n
1291
"%% The reason for skipping the test case." n
1293
"%% Note: This function is free to add any key/value pairs to the Config" n
1294
"%% variable, but should NOT alter/remove any existing entries." n
1296
"%% @spec init_per_testcase(TestCase, Config0) ->" n
1297
"%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1298
(erlang-skel-separator-end 2)
1299
"init_per_testcase(_TestCase, Config) ->" n >
1302
(erlang-skel-separator-start 2)
1304
"%% Cleanup after each test case" n
1306
"%% TestCase - atom()" n
1307
"%% Name of the test case that is finished." n
1308
"%% Config0 = Config1 = [tuple()]" n
1309
"%% A list of key/value pairs, holding the test case configuration." n
1311
"%% @spec end_per_testcase(TestCase, Config0) ->" n
1312
"%% void() | {save_config,Config1} | {fail,Reason}" n
1313
(erlang-skel-separator-end 2)
1314
"end_per_testcase(_TestCase, _Config) ->" n >
1317
(erlang-skel-separator-start 2)
1319
"%% Returns a list of test case group definitions." n
1321
"%% Group = {GroupName,Properties,GroupsAndTestCases}" n
1322
"%% GroupName = atom()" n
1323
"%% The name of the group." n
1324
"%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]" n
1325
"%% Group properties that may be combined." n
1326
"%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]" n
1327
"%% TestCase = atom()" n
1328
"%% The name of a test case." n
1329
"%% Shuffle = shuffle | {shuffle,Seed}" n
1330
"%% To get cases executed in random order." n
1331
"%% Seed = {integer(),integer(),integer()}" n
1332
"%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |" n
1333
"%% repeat_until_any_ok | repeat_until_any_fail" n
1334
"%% To get execution of cases repeated." n
1335
"%% N = integer() | forever" n
1337
"%% @spec: groups() -> [Group]" n
1338
(erlang-skel-separator-end 2)
1342
(erlang-skel-separator-start 2)
1344
"%% Returns the list of groups and test cases that" n
1345
"%% are to be executed." n
1347
"%% GroupsAndTestCases = [{group,GroupName} | TestCase]" n
1348
"%% GroupName = atom()" n
1349
"%% Name of a test case group." n
1350
"%% TestCase = atom()" n
1351
"%% Name of a test case." n
1352
"%% Reason = term()" n
1353
"%% The reason for skipping all groups and test cases." n
1355
"%% @spec all() -> GroupsAndTestCases | {skip,Reason}" n
1356
(erlang-skel-separator-end 2)
1358
"[my_test_case]." n n
1361
(erlang-skel-separator-start 2)
1363
(erlang-skel-separator 2)
1366
(erlang-skel-separator-start 2)
1368
"%% Test case info function - returns list of tuples to set" n
1369
"%% properties for the test case." n
1371
"%% Info = [tuple()]" n
1372
"%% List of key/value pairs." n
1374
"%% Note: This function is only meant to be used to return a list of" n
1375
"%% values, not perform any other operations." n
1377
"%% @spec TestCase() -> Info " n
1378
(erlang-skel-separator-end 2)
1379
"my_test_case() -> " n >
1382
(erlang-skel-separator 2)
1383
"%% @doc Test case function. (The name of it must be specified in" n
1384
"%% the all/0 list or in a test case group for the test case" n
1385
"%% to be executed)." n
1387
"%% Config0 = Config1 = [tuple()]" n
1388
"%% A list of key/value pairs, holding the test case configuration." n
1389
"%% Reason = term()" n
1390
"%% The reason for skipping the test case." n
1391
"%% Comment = term()" n
1392
"%% A comment about the test case that will be printed in the html log." n
1394
"%% @spec TestCase(Config0) ->" n
1395
"%% ok | exit() | {skip,Reason} | {comment,Comment} |" n
1396
"%% {save_config,Config1} | {skip_and_save,Reason,Config1}" n
1397
(erlang-skel-separator-end 2)
1398
"my_test_case(_Config) -> " n >
1402
"*The template of a library module.
1403
Please see the function `tempo-define-template'.")
1407
;; This code is based on the package `tempo' which is part of modern
1408
;; Emacsen. (GNU Emacs 19.25 (?) and XEmacs 19.14.)
1410
(defun erlang-skel-init ()
1411
"Generate the skeleton functions and menu items.
1412
The variable `erlang-skel' contains the name and descriptions of
1415
The skeleton routines are based on the `tempo' package. Should this
1416
package not be present, this function does nothing."
1421
(if (featurep 'tempo)
1422
(let ((skel erlang-skel)
1425
(cond ((null (car skel))
1426
(setq menu (cons nil menu)))
1428
(funcall (symbol-function 'tempo-define-template)
1429
(concat "erlang-" (nth 1 (car skel)))
1430
;; The tempo template used contains an `include'
1431
;; function call only, hence changes to the
1432
;; variables describing the templates take effect
1434
(list (list 'erlang-skel-include (nth 2 (car skel))))
1436
(setq menu (cons (erlang-skel-make-menu-item
1437
(car skel)) menu))))
1438
(setq skel (cdr skel)))
1439
(setq erlang-menu-skel-items
1440
(list nil (list "Skeletons" (nreverse menu))))
1441
(setq erlang-menu-items
1442
(erlang-menu-add-above 'erlang-menu-skel-items
1443
'erlang-menu-version-items
1445
(erlang-menu-init))))
1447
(defun erlang-skel-make-menu-item (skel)
1448
(let ((func (intern (concat "tempo-template-erlang-" (nth 1 skel)))))
1449
(cond ((null (nth 3 skel))
1450
(list (car skel) func))
1456
(list 'quote (nth 3 skel))
1457
(list 'quote func))))))))
1459
;; Functions designed to be added to the skeleton menu.
1460
;; (Not normally used)
1461
(defun erlang-skel-insert (func)
1462
"Insert skeleton generated by FUNC and goto first tempo mark."
1463
(save-excursion (funcall func))
1464
(funcall (symbol-function 'tempo-forward-mark)))
1466
(defun erlang-skel-header (func)
1467
"Insert the header generated by FUNC at the beginning of the buffer."
1468
(goto-char (point-min))
1469
(save-excursion (funcall func))
1470
(funcall (symbol-function 'tempo-forward-mark)))
1473
;; Functions used inside the skeleton descriptions.
1474
(defun erlang-skel-skip-blank ()
1475
(skip-chars-backward " \t")
1478
(defun erlang-skel-include (&rest args)
1479
"Include a template inside another template.
1481
Example of use, assuming that `erlang-skel-func' is defined:
1483
(defvar foo-skeleton '(\"%%% New function:\"
1484
(erlang-skel-include erlang-skel-func)))
1486
Technically, this function returns the `tempo' attribute`(l ...)' which
1487
can contain other `tempo' attributes. Please see the function
1488
`tempo-define-template' for a description of the `(l ...)' attribute."
1492
(setq entry (car args))
1494
(setq res (cons (car entry) res))
1495
(setq entry (cdr entry)))
1496
(setq args (cdr args)))
1497
(cons 'l (nreverse res))))
1499
(defun erlang-skel-separator (&optional percent)
1500
"Return a comment separator."
1501
(let ((percent (or percent 3)))
1502
(concat (make-string percent ?%)
1503
(make-string (- 70 percent) ?-)
1506
(defun erlang-skel-separator-start (&optional percent)
1507
"Return a comment separator or an empty string if separators
1508
are configured off."
1509
(if erlang-skel-use-separators
1510
(erlang-skel-separator percent)
1513
(defun erlang-skel-separator-end (&optional percent)
1514
"Return a comment separator to end a function comment block or an
1515
empty string if separators are configured off."
1516
(if erlang-skel-use-separators
1517
(concat "%% @end\n" (erlang-skel-separator percent))
1520
(defun erlang-skel-double-separator (&optional percent)
1521
"Return a double line (equals sign) comment separator."
1522
(let ((percent (or percent 3)))
1523
(concat (make-string percent ?%)
1524
(make-string (- 70 percent) ?=)
1527
(defun erlang-skel-double-separator-start (&optional percent)
1528
"Return a double separator or a newline if separators are configured off."
1529
(if erlang-skel-use-separators
1530
(erlang-skel-double-separator percent)
1533
(defun erlang-skel-double-separator-end (&optional percent)
1534
"Return a double separator or an empty string if separators are
1536
(if erlang-skel-use-separators
1537
(erlang-skel-double-separator percent)
1540
(defun erlang-skel-dd-mmm-yyyy ()
1541
"Return the current date as a string in \"DD Mon YYYY\" form.
1542
The first character of DD is space if the value is less than 10."
1543
(let ((date (current-time-string)))
1545
(string-to-int (substring date 8 10))
1546
(substring date 4 7)
1547
(substring date -4))))
1550
;; coding: iso-8859-1
1553
;;; erlang-skels.el ends here