1;;
2;; %CopyrightBegin%
3;;
4;; Copyright Ericsson AB 2010-2020. All Rights Reserved.
5;;
6;; Licensed under the Apache License, Version 2.0 (the "License");
7;; you may not use this file except in compliance with the License.
8;; You may obtain a copy of the License at
9;;
10;;     http://www.apache.org/licenses/LICENSE-2.0
11;;
12;; Unless required by applicable law or agreed to in writing, software
13;; distributed under the License is distributed on an "AS IS" BASIS,
14;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15;; See the License for the specific language governing permissions and
16;; limitations under the License.
17;;
18;; %CopyrightEnd%
19;;;
20;;; Purpose: Provide Erlang code skeletons.
21;;; See 'erlang-skel-file' variable.
22
23(defvar erlang-tempo-tags nil
24  "Tempo tags for erlang mode")
25
26(defvar erlang-skel
27  '(("If"            "if"            erlang-skel-if)
28    ("Case"          "case"          erlang-skel-case)
29    ("Receive"       "receive"       erlang-skel-receive)
30    ("Receive After" "after"         erlang-skel-receive-after)
31    ("Receive Loop"  "loop"          erlang-skel-receive-loop)
32    ("Module"        "module"        erlang-skel-module)
33    ("Author"        "author"        erlang-skel-author)
34    ("Function"      "function"      erlang-skel-function)
35    ("Spec"          "spec"          erlang-skel-spec)
36    ()
37    ("Small Header"  "small-header"
38     erlang-skel-small-header erlang-skel-header)
39    ("Normal Header" "normal-header"
40     erlang-skel-normal-header erlang-skel-header)
41    ("Large Header"  "large-header"
42     erlang-skel-large-header erlang-skel-header)
43    ()
44    ("Small Server"   "small-server"
45     erlang-skel-small-server erlang-skel-header)
46    ()
47    ("Application" "application"
48     erlang-skel-application erlang-skel-header)
49    ("Supervisor" "supervisor"
50     erlang-skel-supervisor erlang-skel-header)
51    ("supervisor_bridge" "supervisor-bridge"
52     erlang-skel-supervisor-bridge erlang-skel-header)
53    ("gen_server" "generic-server"
54     erlang-skel-generic-server erlang-skel-header)
55    ("gen_event" "gen-event"
56     erlang-skel-gen-event erlang-skel-header)
57    ("gen_fsm" "gen-fsm"
58     erlang-skel-gen-fsm erlang-skel-header)
59    ("gen_statem (StateName/3)" "gen-statem-StateName"
60     erlang-skel-gen-statem-StateName erlang-skel-header)
61    ("gen_statem (handle_event/4)" "gen-statem-handle-event"
62     erlang-skel-gen-statem-handle-event erlang-skel-header)
63    ("wx_object" "wx-object"
64     erlang-skel-wx-object erlang-skel-header)
65    ("Library module" "gen-lib"
66     erlang-skel-lib erlang-skel-header)
67    ("Corba callback" "gen-corba-cb"
68     erlang-skel-corba-callback erlang-skel-header)
69    ("Small Common Test suite" "ct-test-suite-s"
70     erlang-skel-ct-test-suite-s erlang-skel-header)
71    ("Large Common Test suite" "ct-test-suite-l"
72     erlang-skel-ct-test-suite-l erlang-skel-header)
73    ("Erlang TS test suite" "ts-test-suite"
74     erlang-skel-ts-test-suite erlang-skel-header)
75  )
76  "*Description of all skeleton templates.
77Both functions and menu entries will be created.
78
79Each entry in `erlang-skel' should be a list with three or four
80elements, or the empty list.
81
82The first element is the name which shows up in the menu.  The second
83is the `tempo' identifier (The string \"erlang-\" will be added in
84front of it).  The third is the skeleton descriptor, a variable
85containing `tempo' attributes as described in the function
86`tempo-define-template'.  The optional fourth elements denotes a
87function which should be called when the menu is selected.
88
89Functions corresponding to every template will be created.  The name
90of the function will be `tempo-template-erlang-X' where `X' is the
91tempo identifier as specified in the second argument of the elements
92in this list.
93
94A list with zero elements means that the a horizontal line should
95be placed in the menu.")
96
97(defvar erlang-skel-use-separators t
98  "A boolean than determines whether the skeletons include horizontal
99separators.
100
101Should this variable be nil, the documentation for functions will not
102include separators of the form %%--...")
103
104;; In XEmacs `user-mail-address' returns "x@y.z (Foo Bar)" ARGH!
105;; What's wrong with that? RFC 822 says it's legal.   [sverkerw]
106;; This needs to use the customized value.  If that's not sane, things like
107;; add-log will lose anyhow.  Avoid it if there _is_ a paren.
108(defvar erlang-skel-mail-address
109  (if (or (not user-mail-address) (string-match "(" user-mail-address))
110      (concat (user-login-name) "@"
111              (or (and (boundp 'mail-host-address)
112                       mail-host-address)
113                  (system-name)))
114    user-mail-address)
115  "Mail address of the user.")
116
117;; Expression templates:
118(defvar erlang-skel-case
119  '((erlang-skel-skip-blank) o >
120    "case " p " of" n> p "_ ->" n> p "ok" n "end" > p)
121  "*The skeleton of a `case' expression.
122Please see the function `tempo-define-template'.")
123
124(defvar erlang-skel-if
125  '((erlang-skel-skip-blank) o >
126    "if"  n> p " ->" n> p "ok" n "end" > p)
127  "The skeleton of an `if' expression.
128Please see the function `tempo-define-template'.")
129
130(defvar erlang-skel-receive
131  '((erlang-skel-skip-blank) o >
132    "receive" n> p "_ ->" n> p "ok" n "end" > p)
133  "*The skeleton of a `receive' expression.
134Please see the function `tempo-define-template'.")
135
136(defvar erlang-skel-receive-after
137  '((erlang-skel-skip-blank) o >
138    "receive" n> p "_ ->" n> p "ok" n "after " > p "T ->" n>
139    p "ok" n "end" > p)
140  "*The skeleton of a `receive' expression with an `after' clause.
141Please see the function `tempo-define-template'.")
142
143(defvar erlang-skel-receive-loop
144  '(& o "loop(" p ") ->" n> "receive" n> p "_ ->" n>
145      "loop(" p ")" n "end." >)
146  "*The skeleton of a simple `receive' loop.
147Please see the function `tempo-define-template'.")
148
149
150(defvar erlang-skel-function
151  '((erlang-skel-separator-start 2)
152    "%% @doc" n
153    "%% @spec" n
154    (erlang-skel-separator-end 2))
155    "*The template of a function skeleton.
156Please see the function `tempo-define-template'.")
157
158(defvar erlang-skel-spec
159  '("-spec " (erlang-skel-get-function-name) "(" (erlang-skel-get-function-args) ") -> undefined.")
160    "*The template of a -spec for the function following point.
161Please see the function `tempo-define-template'.")
162
163;; Attribute templates
164
165(defvar erlang-skel-module
166  '(& "-module("
167      (erlang-add-quotes-if-needed (erlang-get-module-from-file-name))
168      ")." n)
169  "*The skeleton of a `module' attribute.
170Please see the function `tempo-define-template'.")
171
172(defvar erlang-skel-author
173  '(& "-author('" erlang-skel-mail-address "')." n)
174  "*The skeleton of a `author' attribute.
175Please see the function `tempo-define-template'.")
176
177(defvar erlang-skel-vc nil
178  "*The skeleton template to generate a version control attribute.
179The default is to insert nothing.  Example of usage:
180
181    (setq erlang-skel-vc '(& \"-rcs(\\\"$\Id: $ \\\").\") n)
182
183Please see the function `tempo-define-template'.")
184
185(defvar erlang-skel-export
186  '(& "-export([" n> "])." n)
187  "*The skeleton of an `export' attribute.
188Please see the function `tempo-define-template'.")
189
190(defvar erlang-skel-import
191  '(& "%%-import(Module, [Function/Arity, ...])." n)
192  "*The skeleton of an `import' attribute.
193Please see the function `tempo-define-template'.")
194
195(defvar erlang-skel-compile nil
196  ;;  '(& "%%-compile(export_all)." n)
197  "*The skeleton of a `compile' attribute.
198Please see the function `tempo-define-template'.")
199
200
201;; Comment templates.
202
203(defvar erlang-skel-date-function 'erlang-skel-dd-mmm-yyyy
204  "*Function which returns date string.
205Look in the module `time-stamp' for a battery of functions.")
206
207(defvar erlang-skel-copyright-comment
208  (if (boundp '*copyright-organization*)
209      '(& "%%% @copyright (C) " (format-time-string "%Y") ", "
210          *copyright-organization*  n)
211      '(& "%%% @copyright (C) " (format-time-string "%Y") ", "
212          (user-full-name)  n))
213  "*The template for a copyright line in the header, normally empty.
214This variable should be bound to a `tempo' template, for example:
215  '(& \"%%% Copyright (C) 2000, Yoyodyne, Inc.\" n)
216Please see the function `tempo-define-template'.")
217
218(defvar erlang-skel-created-comment
219  '(& "%%% Created : " (funcall erlang-skel-date-function) " by "
220      (user-full-name) " <" erlang-skel-mail-address ">" n)
221  "*The template for the \"Created:\" comment line.")
222
223(defvar erlang-skel-author-comment
224  '(& "%%% @author " (user-full-name) " <" erlang-skel-mail-address ">" n)
225  "*The template for creating the \"Author:\" line in the header.
226Please see the function `tempo-define-template'.")
227
228(defvar erlang-skel-small-header
229  '(o (erlang-skel-include erlang-skel-module)
230      n
231      (erlang-skel-include erlang-skel-compile erlang-skel-vc))
232  "*The template of a small header without any comments.
233Please see the function `tempo-define-template'.")
234
235(defvar erlang-skel-normal-header
236  '(o (erlang-skel-include  erlang-skel-author-comment)
237      (erlang-skel-include erlang-skel-copyright-comment)
238      "%%% @doc"  n
239      "%%%" p n
240      "%%% @end" n
241      (erlang-skel-include erlang-skel-created-comment) n
242      (erlang-skel-include erlang-skel-small-header) n)
243  "*The template of a normal header.
244Please see the function `tempo-define-template'.")
245
246(defvar erlang-skel-large-header
247  '(o (erlang-skel-separator)
248      (erlang-skel-include erlang-skel-author-comment)
249      (erlang-skel-include erlang-skel-copyright-comment)
250      "%%% @doc" n
251      "%%%" p n
252      "%%% @end" n
253      (erlang-skel-include erlang-skel-created-comment)
254      (erlang-skel-separator)
255      (erlang-skel-include erlang-skel-small-header) )
256  "*The template of a large header.
257Please see the function `tempo-define-template'.")
258
259
260 ;; Server templates.
261(defvar erlang-skel-small-server
262  '((erlang-skel-include erlang-skel-large-header)
263    "-export([start/0, init/1])." n n n
264    "start() ->" n> "spawn(" (erlang-get-module-from-file-name)
265    ", init, [self()])." n n
266    "init(From) ->" n>
267    "loop(From)." n n
268    "loop(From) ->" n>
269    "receive" n>
270    p "_ ->" n>
271    "loop(From)" n
272    "end." > n
273    )
274  "*Template of a small server.
275Please see the function `tempo-define-template'.")
276
277;; Behaviour templates.
278(defvar erlang-skel-application
279  '((erlang-skel-include erlang-skel-large-header)
280    "-behaviour(application)." n n
281    "%% Application callbacks" n
282    "-export([start/2, start_phase/3, stop/1, prep_stop/1," n>
283    "config_change/3])." n n
284    (erlang-skel-double-separator-start 3)
285    "%%% Application callbacks" n
286    (erlang-skel-double-separator-end 3) n
287    (erlang-skel-separator-start 2)
288    "%% @private" n
289    "%% @doc" n
290    "%% This function is called whenever an application is started using" n
291    "%% application:start/[1,2], and should start the processes of the" n
292    "%% application. If the application is structured according to the OTP" n
293    "%% design principles as a supervision tree, this means starting the" n
294    "%% top supervisor of the tree." n
295    (erlang-skel-separator-end 2)
296    "-spec start(StartType :: normal |" n>
297    "{takeover, Node :: node()} |" n>
298    "{failover, Node :: node()}," n>
299    "StartArgs :: term()) ->" n>
300    "{ok, Pid :: pid()} |" n>
301    "{ok, Pid :: pid(), State :: term()} |" n>
302    "{error, Reason :: term()}." n
303    "start(_StartType, _StartArgs) ->" n>
304    "case 'TopSupervisor':start_link() of" n>
305    "{ok, Pid} ->" n>
306    "{ok, Pid};" n>
307    "Error ->" n>
308    "Error" n
309    "end." > n
310    n
311    (erlang-skel-separator-start 2)
312    "%% @private" n
313    "%% @doc" n
314    "%% top supervisor of the tree." n
315    "%% Starts an application with included applications, when" n
316    "%% synchronization is needed between processes in the different" n
317    "%% applications during startup."
318    (erlang-skel-separator-end 2)
319    "-spec start_phase(Phase :: atom()," n>
320    "StartType :: normal |" n>
321    "{takeover, Node :: node()} |" n>
322    "{failover, Node :: node()}," n>
323    "PhaseArgs :: term()) -> ok | {error, Reason :: term()}." n
324    "start_phase(_Phase, _StartType, _PhaseArgs) ->" n>
325    "ok."n
326    n
327    (erlang-skel-separator-start 2)
328    "%% @private" n
329    "%% @doc" n
330    "%% This function is called whenever an application has stopped. It" n
331    "%% is intended to be the opposite of Module:start/2 and should do" n
332    "%% any necessary cleaning up. The return value is ignored." n
333    (erlang-skel-separator-end 2)
334    "-spec stop(State :: term()) -> any()." n
335    "stop(_State) ->" n>
336    "ok." n
337    n
338    (erlang-skel-separator-start 2)
339    "%% @private" n
340    "%% @doc" n
341    "%% This function is called when an application is about to be stopped," n
342    "%% before shutting down the processes of the application." n
343    (erlang-skel-separator-end 2)
344    "-spec prep_stop(State :: term()) -> NewState :: term()." n
345    "prep_stop(State) ->" n>
346    "State." n
347    n
348    (erlang-skel-separator-start 2)
349    "%% @private" n
350    "%% @doc" n
351    "%% This function is called by an application after a code replacement," n
352    "%% if the configuration parameters have changed." n
353    (erlang-skel-separator-end 2)
354    "-spec config_change(Changed :: [{Par :: atom(), Val :: term()}]," n>
355    "New :: [{Par :: atom(), Val :: term()}]," n>
356    "Removed :: [Par :: atom()]) -> ok." n
357    "config_change(_Changed, _New, _Removed) ->" n>
358    "ok." n
359    n
360    (erlang-skel-double-separator-start 3)
361    "%%% Internal functions" n
362    (erlang-skel-double-separator-end 3)
363    )
364  "*The template of an application behaviour.
365Please see the function `tempo-define-template'.")
366
367(defvar erlang-skel-supervisor
368  '((erlang-skel-include erlang-skel-large-header)
369    "-behaviour(supervisor)." n n
370
371    "%% API" n
372    "-export([start_link/0])." n n
373
374    "%% Supervisor callbacks" n
375    "-export([init/1])." n n
376
377    "-define(SERVER, ?MODULE)." n n
378
379    (erlang-skel-double-separator-start 3)
380    "%%% API functions" n
381    (erlang-skel-double-separator-end 3) n
382    (erlang-skel-separator-start 2)
383    "%% @doc" n
384    "%% Starts the supervisor" n
385    (erlang-skel-separator-end 2)
386    "-spec start_link() -> {ok, Pid :: pid()} |" n>
387    "{error, {already_started, Pid :: pid()}} |" n>
388    "{error, {shutdown, term()}} |" n>
389    "{error, term()} |" n>
390    "ignore." n
391    "start_link() ->" n>
392    "supervisor:start_link({local, ?SERVER}, ?MODULE, [])." n
393    n
394    (erlang-skel-double-separator-start 3)
395    "%%% Supervisor callbacks" n
396    (erlang-skel-double-separator-end 3) n
397    (erlang-skel-separator-start 2)
398    "%% @private" n
399    "%% @doc" n
400    "%% Whenever a supervisor is started using supervisor:start_link/[2,3]," n
401    "%% this function is called by the new process to find out about" n
402    "%% restart strategy, maximum restart intensity, and child" n
403    "%% specifications." n
404    (erlang-skel-separator-end 2)
405    "-spec init(Args :: term()) ->" n>
406    "{ok, {SupFlags :: supervisor:sup_flags()," n>
407    "[ChildSpec :: supervisor:child_spec()]}} |" n>
408    "ignore." n
409    "init([]) ->" n
410    "" n>
411    "SupFlags = #{strategy => one_for_one," n>
412    "intensity => 1," n>
413    "period => 5}," n
414    "" n>
415    "AChild = #{id => 'AName'," n>
416    "start => {'AModule', start_link, []}," n>
417    "restart => permanent," n>
418    "shutdown => 5000," n>
419    "type => worker," n>
420    "modules => ['AModule']}," n
421    "" n>
422    "{ok, {SupFlags, [AChild]}}." n
423    n
424    (erlang-skel-double-separator-start 3)
425    "%%% Internal functions" n
426    (erlang-skel-double-separator-end 3)
427    )
428  "*The template of a supervisor behaviour.
429Please see the function `tempo-define-template'.")
430
431(defvar erlang-skel-supervisor-bridge
432  '((erlang-skel-include erlang-skel-large-header)
433    "-behaviour(supervisor_bridge)." n n
434
435    "%% API" n
436    "-export([start_link/0])." n n
437
438    "%% supervisor_bridge callbacks" n
439    "-export([init/1, terminate/2])." n n
440
441    "-define(SERVER, ?MODULE)." n n
442
443    "-record(state, {})." n n
444
445    (erlang-skel-double-separator-start 3)
446    "%%% API" n
447    (erlang-skel-double-separator-end 3) n
448    (erlang-skel-separator-start 2)
449    "%% @doc" n
450    "%% Starts the supervisor bridge" n
451    (erlang-skel-separator-end 2)
452    "-spec start_link() -> {ok, Pid :: pid()} |" n>
453    "{error, {already_started, Pid :: pid()}} |" n>
454    "{error, term()} |" n>
455    "ignore." n
456    "start_link() ->" n>
457    "supervisor_bridge:start_link({local, ?SERVER}, ?MODULE, [])." n
458    n
459    (erlang-skel-double-separator-start 3)
460    "%%% supervisor_bridge callbacks" n
461    (erlang-skel-double-separator-end 3) n
462    (erlang-skel-separator-start 2)
463    "%% @private" n
464    "%% @doc" n
465    "%% Creates a supervisor_bridge process, linked to the calling process," n
466    "%% which calls Module:init/1 to start the subsystem. To ensure a" n
467    "%% synchronized start-up procedure, this function does not return" n
468    "%% until Module:init/1 has returned." n
469    (erlang-skel-separator-end 2)
470    "-spec init(Args :: term()) -> {ok, Pid :: pid(), State :: term()} |" n>
471    "{error, Error :: term()} |" n>
472    "ignore." n
473    "init([]) ->" n>
474    "case 'AModule':start_link() of" n>
475    "{ok, Pid} ->" n>
476    "{ok, Pid, #state{}};" n>
477    "Error ->" n>
478    "Error" n
479    "end." > n
480    n
481    (erlang-skel-separator-start 2)
482    "%% @private" n
483    "%% @doc" n
484    "%% This function is called by the supervisor_bridge when it is about" n
485    "%% to terminate. It should be the opposite of Module:init/1 and stop" n
486    "%% the subsystem and do any necessary cleaning up.The return value is" n
487    "%% ignored." n
488    (erlang-skel-separator-end 2)
489    "-spec terminate(Reason :: shutdown | term(), State :: term()) -> any()." n
490    "terminate(_Reason, _State) ->" n>
491    "'AModule':stop()," n>
492    "ok." n
493    n
494    (erlang-skel-double-separator-start 3)
495    "%%% Internal functions" n
496    (erlang-skel-double-separator-end 3)
497    )
498  "*The template of a supervisor_bridge behaviour.
499Please see the function `tempo-define-template'.")
500
501(defvar erlang-skel-generic-server
502  '((erlang-skel-include erlang-skel-large-header)
503    "-behaviour(gen_server)." n n
504
505    "%% API" n
506    "-export([start_link/0])." n n
507
508    "%% gen_server callbacks" n
509    "-export([init/1, handle_call/3, handle_cast/2, handle_info/2," n>
510    "terminate/2, code_change/3, format_status/2])." n n
511
512    "-define(SERVER, ?MODULE)." n n
513
514    "-record(state, {})." n n
515
516    (erlang-skel-double-separator-start 3)
517    "%%% API" n
518    (erlang-skel-double-separator-end 3) n
519    (erlang-skel-separator-start 2)
520    "%% @doc" n
521    "%% Starts the server" n
522    (erlang-skel-separator-end 2)
523    "-spec start_link() -> {ok, Pid :: pid()} |" n>
524    "{error, Error :: {already_started, pid()}} |" n>
525    "{error, Error :: term()} |" n>
526    "ignore." n
527    "start_link() ->" n>
528    "gen_server:start_link({local, ?SERVER}, ?MODULE, [], [])." n
529    n
530    (erlang-skel-double-separator-start 3)
531    "%%% gen_server callbacks" n
532    (erlang-skel-double-separator-end 3)
533    n
534    (erlang-skel-separator-start 2)
535    "%% @private" n
536    "%% @doc" n
537    "%% Initializes the server" n
538    (erlang-skel-separator-end 2)
539    "-spec init(Args :: term()) -> {ok, State :: term()} |" n>
540    "{ok, State :: term(), Timeout :: timeout()} |" n>
541    "{ok, State :: term(), hibernate} |" n>
542    "{stop, Reason :: term()} |" n>
543    "ignore." n
544    "init([]) ->" n>
545    "process_flag(trap_exit, true)," n>
546    "{ok, #state{}}." n
547    n
548    (erlang-skel-separator-start 2)
549    "%% @private" n
550    "%% @doc" n
551    "%% Handling call messages" n
552    (erlang-skel-separator-end 2)
553    "-spec handle_call(Request :: term(), From :: {pid(), term()}, State :: term()) ->" n>
554    "{reply, Reply :: term(), NewState :: term()} |" n>
555    "{reply, Reply :: term(), NewState :: term(), Timeout :: timeout()} |" n>
556    "{reply, Reply :: term(), NewState :: term(), hibernate} |" n>
557    "{noreply, NewState :: term()} |" n>
558    "{noreply, NewState :: term(), Timeout :: timeout()} |" n>
559    "{noreply, NewState :: term(), hibernate} |" n>
560    "{stop, Reason :: term(), Reply :: term(), NewState :: term()} |" n>
561    "{stop, Reason :: term(), NewState :: term()}." n
562    "handle_call(_Request, _From, State) ->" n>
563    "Reply = ok," n>
564    "{reply, Reply, State}." n
565    n
566    (erlang-skel-separator-start 2)
567    "%% @private" n
568    "%% @doc" n
569    "%% Handling cast messages" n
570    (erlang-skel-separator-end 2)
571    "-spec handle_cast(Request :: term(), State :: term()) ->" n>
572    "{noreply, NewState :: term()} |" n>
573    "{noreply, NewState :: term(), Timeout :: timeout()} |" n>
574    "{noreply, NewState :: term(), hibernate} |" n>
575    "{stop, Reason :: term(), NewState :: term()}." n
576    "handle_cast(_Request, State) ->" n>
577    "{noreply, State}." n
578    n
579    (erlang-skel-separator-start 2)
580    "%% @private" n
581    "%% @doc" n
582    "%% Handling all non call/cast messages" n
583    (erlang-skel-separator-end 2)
584    "-spec handle_info(Info :: timeout() | term(), State :: term()) ->" n>
585    "{noreply, NewState :: term()} |" n>
586    "{noreply, NewState :: term(), Timeout :: timeout()} |" n>
587    "{noreply, NewState :: term(), hibernate} |" n>
588    "{stop, Reason :: normal | term(), NewState :: term()}." n
589    "handle_info(_Info, State) ->" n>
590    "{noreply, State}." n
591    n
592    (erlang-skel-separator-start 2)
593    "%% @private" n
594    "%% @doc" n
595    "%% This function is called by a gen_server when it is about to" n
596    "%% terminate. It should be the opposite of Module:init/1 and do any" n
597    "%% necessary cleaning up. When it returns, the gen_server terminates" n
598    "%% with Reason. The return value is ignored." n
599    (erlang-skel-separator-end 2)
600    "-spec terminate(Reason :: normal | shutdown | {shutdown, term()} | term()," n>
601    "State :: term()) -> any()." n
602    "terminate(_Reason, _State) ->" n>
603    "ok." n
604    n
605    (erlang-skel-separator-start 2)
606    "%% @private" n
607    "%% @doc" n
608    "%% Convert process state when code is changed" n
609    (erlang-skel-separator-end 2)
610    "-spec code_change(OldVsn :: term() | {down, term()}," n>
611    "State :: term()," n>
612    "Extra :: term()) -> {ok, NewState :: term()} |" n>
613    "{error, Reason :: term()}." n
614    "code_change(_OldVsn, State, _Extra) ->" n>
615    "{ok, State}." n
616    n
617    (erlang-skel-separator-start 2)
618    "%% @private" n
619    "%% @doc" n
620    "%% This function is called for changing the form and appearance" n
621    "%% of gen_server status when it is returned from sys:get_status/1,2" n
622    "%% or when it appears in termination error logs." n
623    (erlang-skel-separator-end 2)
624    "-spec format_status(Opt :: normal | terminate," n>
625    "Status :: list()) -> Status :: term()." n
626    "format_status(_Opt, Status) ->" n>
627    "Status." n
628    n
629    (erlang-skel-double-separator-start 3)
630    "%%% Internal functions" n
631    (erlang-skel-double-separator-end 3)
632    )
633  "*The template of a generic server.
634Please see the function `tempo-define-template'.")
635
636(defvar erlang-skel-gen-event
637  '((erlang-skel-include erlang-skel-large-header)
638    "-behaviour(gen_event)." n n
639
640    "%% API" n
641    "-export([start_link/0, add_handler/0])." n n
642
643    "%% gen_event callbacks" n
644    "-export([init/1, handle_event/2, handle_call/2, handle_info/2," n>
645    "terminate/2, code_change/3, format_status/2])." n n
646
647    "-define(SERVER, ?MODULE)." n n
648
649    "-record(state, {})." n n
650
651    (erlang-skel-double-separator-start 3)
652    "%%% API" n
653    (erlang-skel-double-separator-end 3) n
654    (erlang-skel-separator-start 2)
655    "%% @doc" n
656    "%% Creates an event manager" n
657    (erlang-skel-separator-end 2)
658    "-spec start_link() -> {ok, Pid :: pid()} |" n>
659    "{error, Error :: {already_started, pid()} | term()}." n
660    "start_link() ->" n>
661    "gen_event:start_link({local, ?SERVER})." n
662    n
663    (erlang-skel-separator-start 2)
664    "%% @doc" n
665    "%% Adds an event handler" n
666    (erlang-skel-separator-end 2)
667    "-spec add_handler() -> ok | {'EXIT', Reason :: term()} | term()." n
668    "add_handler() ->" n>
669    "gen_event:add_handler(?SERVER, ?MODULE, [])." n
670    n
671    (erlang-skel-double-separator-start 3)
672    "%%% gen_event callbacks" n
673    (erlang-skel-double-separator-end 3) n
674    (erlang-skel-separator-start 2)
675    "%% @private" n
676    "%% @doc" n
677    "%% Whenever a new event handler is added to an event manager," n
678    "%% this function is called to initialize the event handler." n
679    (erlang-skel-separator-end 2)
680    "-spec init(Args :: term() | {Args :: term(), Term :: term()}) ->" n>
681    "{ok, State :: term()} |" n>
682    "{ok, State :: term(), hibernate} |" n>
683    "{error, Reason :: term()}." n
684    "init([]) ->" n>
685    "{ok, #state{}}." n
686    n
687    (erlang-skel-separator-start 2)
688    "%% @private" n
689    "%% @doc" n
690    "%% Whenever an event manager receives an event sent using" n
691    "%% gen_event:notify/2 or gen_event:sync_notify/2, this function is" n
692    "%% called for each installed event handler to handle the event." n
693    (erlang-skel-separator-end 2)
694    "-spec handle_event(Event :: term(), State :: term()) ->" n>
695    "{ok, NewState :: term()} |" n>
696    "{ok, NewState :: term(), hibernate} |" n>
697    "remove_handler |" n>
698    "{swap_handler, Args1 :: term(), NewState :: term()," n>
699    "Handler2 :: atom() | {atom(), term()} , Args2 :: term()}." n>
700    "handle_event(_Event, State) ->" n>
701    "{ok, State}." n
702    n
703    (erlang-skel-separator-start 2)
704    "%% @private" n
705    "%% @doc" n
706    "%% Whenever an event manager receives a request sent using" n
707    "%% gen_event:call/3,4, this function is called for the specified" n
708    "%% event handler to handle the request." n
709    (erlang-skel-separator-end 2)
710    "-spec handle_call(Request :: term(), State :: term()) ->" n>
711    "{ok, Reply :: term(), NewState :: term()} |" n>
712    "{ok, Reply :: term(), NewState :: term(), hibernate} |" n>
713    "{remove_handler, Reply :: term()} |" n>
714    "{swap_handler, Reply :: term(), Args1 :: term(), NewState :: term()," n>
715    "Handler2 :: atom() | {atom(), term()}, Args2 :: term()}." n
716    "handle_call(_Request, State) ->" n>
717    "Reply = ok," n>
718    "{ok, Reply, State}." n
719    n
720    (erlang-skel-separator-start 2)
721    "%% @private" n
722    "%% @doc" n
723    "%% This function is called for each installed event handler when" n
724    "%% an event manager receives any other message than an event or a" n
725    "%% synchronous request (or a system message)." n
726    (erlang-skel-separator-end 2)
727    "-spec handle_info(Info :: term(), State :: term()) ->" n>
728    "{ok, NewState :: term()} |" n>
729    "{ok, NewState :: term(), hibernate} |" n>
730    "remove_handler |" n>
731    "{swap_handler, Args1 :: term(), NewState :: term()," n>
732    "Handler2 :: atom() | {atom(), term()}, Args2 :: term()}." n
733    "handle_info(_Info, State) ->" n>
734    "{ok, State}." n
735    n
736    (erlang-skel-separator-start 2)
737    "%% @private" n
738    "%% @doc" n
739    "%% Whenever an event handler is deleted from an event manager, this" n
740    "%% function is called. It should be the opposite of Module:init/1 and" n
741    "%% do any necessary cleaning up." n
742    (erlang-skel-separator-end 2)
743    "-spec terminate(Arg :: {stop, Reason :: term()} |" n>
744    "stop |" n>
745    "remove_handler |" n>
746    "{error, {'EXIT', Reason :: term()}} |" n>
747    "{error, Term :: term()} |" n>
748    "term()," n>
749    "State :: term()) -> any()." n
750    "terminate(_Arg, _State) ->" n>
751    "ok." n
752    n
753    (erlang-skel-separator-start 2)
754    "%% @private" n
755    "%% @doc" n
756    "%% Convert process state when code is changed" n
757    (erlang-skel-separator-end 2)
758    "-spec code_change(OldVsn :: term() | {down, term()}," n>
759    "State :: term()," n>
760    "Extra :: term()) -> {ok, NewState :: term()}." n
761    "code_change(_OldVsn, State, _Extra) ->" n>
762    "{ok, State}." n
763    n
764    (erlang-skel-separator-start 2)
765    "%% @private" n
766    "%% @doc" n
767    "%% This function is called for changing the form and appearance" n
768    "%% of gen_event status when it is returned from sys:get_status/1,2" n
769    "%% or when it appears in termination error logs." n
770    (erlang-skel-separator-end 2)
771    "-spec format_status(Opt :: normal | terminate," n>
772    "Status :: list()) -> Status :: term()." n
773    "format_status(_Opt, Status) ->" n>
774    "Status." n
775    n
776    (erlang-skel-double-separator-start 3)
777    "%%% Internal functions" n
778    (erlang-skel-double-separator-end 3)
779    )
780  "*The template of a gen_event.
781Please see the function `tempo-define-template'.")
782
783(defvar erlang-skel-gen-fsm
784  '((erlang-skel-include erlang-skel-large-header)
785    "-behaviour(gen_fsm)." n n
786
787    "%% API" n
788    "-export([start_link/0])." n n
789
790    "%% gen_fsm callbacks" n
791    "-export([init/1, state_name/2, state_name/3, handle_event/3," n>
792    "handle_sync_event/4, handle_info/3, terminate/3, code_change/4])." n n
793
794    "-define(SERVER, ?MODULE)." n n
795
796    "-record(state, {})." n n
797
798    (erlang-skel-double-separator-start 3)
799    "%%% API" n
800    (erlang-skel-double-separator-end 3) n
801    (erlang-skel-separator-start 2)
802    "%% @doc" n
803    "%% Creates a gen_fsm process which calls Module:init/1 to" n
804    "%% initialize. To ensure a synchronized start-up procedure, this" n
805    "%% function does not return until Module:init/1 has returned." n
806    "%%" n
807    "%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
808    (erlang-skel-separator-end 2)
809    "start_link() ->" n>
810    "gen_fsm:start_link({local, ?SERVER}, ?MODULE, [], [])." n
811    n
812    (erlang-skel-double-separator-start 3)
813    "%%% gen_fsm callbacks" n
814    (erlang-skel-double-separator-end 3) n
815    (erlang-skel-separator-start 2)
816    "%% @private" n
817    "%% @doc" n
818    "%% Whenever a gen_fsm is started using gen_fsm:start/[3,4] or" n
819    "%% gen_fsm:start_link/[3,4], this function is called by the new" n
820    "%% process to initialize." n
821    "%%" n
822    "%% @spec init(Args) -> {ok, StateName, State} |" n
823    "%%                     {ok, StateName, State, Timeout} |" n
824    "%%                     ignore |" n
825    "%%                     {stop, StopReason}" n
826    (erlang-skel-separator-end 2)
827    "init([]) ->" n>
828    "process_flag(trap_exit, true)," n>
829    "{ok, state_name, #state{}}." n
830    n
831    (erlang-skel-separator-start 2)
832    "%% @private" n
833    "%% @doc" n
834    "%% There should be one instance of this function for each possible" n
835    "%% state name. Whenever a gen_fsm receives an event sent using" n
836    "%% gen_fsm:send_event/2, the instance of this function with the same" n
837    "%% name as the current state name StateName is called to handle" n
838    "%% the event. It is also called if a timeout occurs." n
839    "%%" n
840    "%% @spec state_name(Event, State) ->" n
841    "%%                   {next_state, NextStateName, NextState} |" n
842    "%%                   {next_state, NextStateName, NextState, Timeout} |" n
843    "%%                   {stop, Reason, NewState}" n
844    (erlang-skel-separator-end 2)
845    "state_name(_Event, State) ->" n>
846    "{next_state, state_name, State}." n
847    n
848    (erlang-skel-separator-start 2)
849    "%% @private" n
850    "%% @doc" n
851    "%% There should be one instance of this function for each possible" n
852    "%% state name. Whenever a gen_fsm receives an event sent using" n
853    "%% gen_fsm:sync_send_event/[2,3], the instance of this function with" n
854    "%% the same name as the current state name StateName is called to" n
855    "%% handle the event." n
856    "%%" n
857    "%% @spec state_name(Event, From, State) ->" n
858    "%%                   {next_state, NextStateName, NextState} |"n
859    "%%                   {next_state, NextStateName, NextState, Timeout} |" n
860    "%%                   {reply, Reply, NextStateName, NextState} |" n
861    "%%                   {reply, Reply, NextStateName, NextState, Timeout} |" n
862    "%%                   {stop, Reason, NewState} |" n
863    "%%                   {stop, Reason, Reply, NewState}" n
864    (erlang-skel-separator-end 2)
865    "state_name(_Event, _From, State) ->" n>
866    "Reply = ok," n>
867    "{reply, Reply, state_name, State}." n
868    n
869    (erlang-skel-separator-start 2)
870    "%% @private" n
871    "%% @doc" n
872    "%% Whenever a gen_fsm receives an event sent using" n
873    "%% gen_fsm:send_all_state_event/2, this function is called to handle" n
874    "%% the event." n
875    "%%" n
876    "%% @spec handle_event(Event, StateName, State) ->" n
877    "%%                   {next_state, NextStateName, NextState} |" n
878    "%%                   {next_state, NextStateName, NextState, Timeout} |" n
879    "%%                   {stop, Reason, NewState}" n
880    (erlang-skel-separator-end 2)
881    "handle_event(_Event, StateName, State) ->" n>
882    "{next_state, StateName, State}." n
883    n
884    (erlang-skel-separator-start 2)
885    "%% @private" n
886    "%% @doc" n
887    "%% Whenever a gen_fsm receives an event sent using" n
888    "%% gen_fsm:sync_send_all_state_event/[2,3], this function is called" n
889    "%% to handle the event." n
890    "%%" n
891    "%% @spec handle_sync_event(Event, From, StateName, State) ->" n
892    "%%                   {next_state, NextStateName, NextState} |" n
893    "%%                   {next_state, NextStateName, NextState, Timeout} |" n
894    "%%                   {reply, Reply, NextStateName, NextState} |" n
895    "%%                   {reply, Reply, NextStateName, NextState, Timeout} |" n
896    "%%                   {stop, Reason, NewState} |" n
897    "%%                   {stop, Reason, Reply, NewState}" n
898    (erlang-skel-separator-end 2)
899    "handle_sync_event(_Event, _From, StateName, State) ->" n>
900    "Reply = ok," n>
901    "{reply, Reply, StateName, State}." n
902    n
903    (erlang-skel-separator-start 2)
904    "%% @private" n
905    "%% @doc" n
906    "%% This function is called by a gen_fsm when it receives any" n
907    "%% message other than a synchronous or asynchronous event" n
908    "%% (or a system message)." n
909    "%%" n
910    "%% @spec handle_info(Info,StateName,State)->" n
911    "%%                   {next_state, NextStateName, NextState} |" n
912    "%%                   {next_state, NextStateName, NextState, Timeout} |" n
913    "%%                   {stop, Reason, NewState}" n
914    (erlang-skel-separator-end 2)
915    "handle_info(_Info, StateName, State) ->" n>
916    "{next_state, StateName, State}." n
917    n
918    (erlang-skel-separator-start 2)
919    "%% @private" n
920    "%% @doc" n
921    "%% This function is called by a gen_fsm when it is about to" n
922    "%% terminate. It should be the opposite of Module:init/1 and do any" n
923    "%% necessary cleaning up. When it returns, the gen_fsm terminates with" n
924    "%% Reason. The return value is ignored." n
925    "%%" n
926    "%% @spec terminate(Reason, StateName, State) -> void()" n
927    (erlang-skel-separator-end 2)
928    "terminate(_Reason, _StateName, _State) ->" n>
929    "ok." n
930    n
931    (erlang-skel-separator-start 2)
932    "%% @private" n
933    "%% @doc" n
934    "%% Convert process state when code is changed" n
935    "%%" n
936    "%% @spec code_change(OldVsn, StateName, State, Extra) ->" n
937    "%%                   {ok, StateName, NewState}" n
938    (erlang-skel-separator-end 2)
939    "code_change(_OldVsn, StateName, State, _Extra) ->" n>
940    "{ok, StateName, State}." n
941    n
942    (erlang-skel-double-separator-start 3)
943    "%%% Internal functions" n
944    (erlang-skel-double-separator-end 3)
945    )
946  "*The template of a gen_fsm.
947Please see the function `tempo-define-template'.")
948
949(defvar erlang-skel-gen-statem-StateName
950  '((erlang-skel-include erlang-skel-large-header)
951    "-behaviour(gen_statem)." n n
952
953    "%% API" n
954    "-export([start_link/0])." n
955    n
956    "%% gen_statem callbacks" n
957    "-export([callback_mode/0, init/1, terminate/3, code_change/4])." n
958    "-export([state_name/3])." n
959    n
960    "-define(SERVER, ?MODULE)." n
961    n
962    "-record(data, {})." n
963    n
964    (erlang-skel-double-separator-start 3)
965    "%%% API" n
966    (erlang-skel-double-separator-end 3) n
967    (erlang-skel-separator-start 2)
968    "%% @doc" n
969    "%% Creates a gen_statem process which calls Module:init/1 to" n
970    "%% initialize. To ensure a synchronized start-up procedure, this" n
971    "%% function does not return until Module:init/1 has returned." n
972    "%%" n
973    (erlang-skel-separator-end 2)
974    "-spec start_link() ->" n>
975    "{ok, Pid :: pid()} |" n>
976    "ignore |" n>
977    "{error, Error :: term()}." n
978    "start_link() ->" n>
979    "gen_statem:start_link({local, ?SERVER}, ?MODULE, [], [])." n
980    n
981    (erlang-skel-double-separator-start 3)
982    "%%% gen_statem callbacks" n
983    (erlang-skel-double-separator-end 3) n
984    (erlang-skel-separator-start 2)
985    "%% @private" n
986    "%% @doc" n
987    "%% Define the callback_mode() for this callback module." n
988    (erlang-skel-separator-end 2)
989    "-spec callback_mode() -> gen_statem:callback_mode_result()." n
990    "callback_mode() -> state_functions." n
991    n
992    (erlang-skel-separator-start 2)
993    "%% @private" n
994    "%% @doc" n
995    "%% Whenever a gen_statem is started using gen_statem:start/[3,4] or" n
996    "%% gen_statem:start_link/[3,4], this function is called by the new" n
997    "%% process to initialize." n
998    (erlang-skel-separator-end 2)
999    "-spec init(Args :: term()) ->" n>
1000    "gen_statem:init_result(atom())." n
1001    "init([]) ->" n>
1002    "process_flag(trap_exit, true)," n>
1003    "{ok, state_name, #data{}}." n
1004    n
1005    (erlang-skel-separator-start 2)
1006    "%% @private" n
1007    "%% @doc" n
1008    "%% There should be one function like this for each state name." n
1009    "%% Whenever a gen_statem receives an event, the function " n
1010    "%% with the name of the current state (StateName) " n
1011    "%% is called to handle the event." n
1012    (erlang-skel-separator-end 2)
1013    "-spec state_name('enter'," n>
1014    "OldState :: atom()," n>
1015    "Data :: term()) ->" n>
1016    "gen_statem:state_enter_result('state_name');" n>
1017    "(gen_statem:event_type()," n>
1018    "Msg :: term()," n>
1019    "Data :: term()) ->" n>
1020    "gen_statem:event_handler_result(atom())." n
1021    ;;
1022    "state_name({call,Caller}, _Msg, Data) ->" n>
1023    "{next_state, state_name, Data, [{reply,Caller,ok}]}." n
1024    n
1025    (erlang-skel-separator-start 2)
1026    "%% @private" n
1027    "%% @doc" n
1028    "%% This function is called by a gen_statem when it is about to" n
1029    "%% terminate. It should be the opposite of Module:init/1 and do any" n
1030    "%% necessary cleaning up. When it returns, the gen_statem terminates with" n
1031    "%% Reason. The return value is ignored." n
1032    (erlang-skel-separator-end 2)
1033    "-spec terminate(Reason :: term(), State :: term(), Data :: term()) ->" n>
1034    "any()." n
1035    "terminate(_Reason, _State, _Data) ->" n>
1036    "void." n
1037    n
1038    (erlang-skel-separator-start 2)
1039    "%% @private" n
1040    "%% @doc" n
1041    "%% Convert process state when code is changed" n
1042    (erlang-skel-separator-end 2)
1043    "-spec code_change(" n>
1044    "OldVsn :: term() | {down,term()}," n>
1045    "State :: term(), Data :: term(), Extra :: term()) ->" n>
1046    "{ok, NewState :: term(), NewData :: term()} |" n>
1047    "(Reason :: term())." n
1048    "code_change(_OldVsn, State, Data, _Extra) ->" n>
1049    "{ok, State, Data}." n
1050    n
1051    (erlang-skel-double-separator-start 3)
1052    "%%% Internal functions" n
1053    (erlang-skel-double-separator-end 3)
1054    )
1055  "*The template of a gen_statem (StateName/3).
1056Please see the function `tempo-define-template'.")
1057
1058(defvar erlang-skel-gen-statem-handle-event
1059  '((erlang-skel-include erlang-skel-large-header)
1060    "-behaviour(gen_statem)." n n
1061
1062    "%% API" n
1063    "-export([start_link/0])." n
1064    n
1065    "%% gen_statem callbacks" n
1066    "-export([callback_mode/0, init/1, terminate/3, code_change/4])." n
1067    "-export([handle_event/4])." n
1068    n
1069    "-define(SERVER, ?MODULE)." n
1070    n
1071    "-record(data, {})." n
1072    n
1073    (erlang-skel-double-separator-start 3)
1074    "%%% API" n
1075    (erlang-skel-double-separator-end 3) n
1076    (erlang-skel-separator-start 2)
1077    "%% @doc" n
1078    "%% Creates a gen_statem process which calls Module:init/1 to" n
1079    "%% initialize. To ensure a synchronized start-up procedure, this" n
1080    "%% function does not return until Module:init/1 has returned." n
1081    "%%" n
1082    (erlang-skel-separator-end 2)
1083    "-spec start_link() ->" n>
1084    "{ok, Pid :: pid()} |" n>
1085    "ignore |" n>
1086    "{error, Error :: term()}." n
1087    "start_link() ->" n>
1088    "gen_statem:start_link({local, ?SERVER}, ?MODULE, [], [])." n
1089    n
1090    (erlang-skel-double-separator-start 3)
1091    "%%% gen_statem callbacks" n
1092    (erlang-skel-double-separator-end 3) n
1093    (erlang-skel-separator-start 2)
1094    "%% @private" n
1095    "%% @doc" n
1096    "%% Define the callback_mode() for this callback module." n
1097    (erlang-skel-separator-end 2)
1098    "-spec callback_mode() -> gen_statem:callback_mode_result()." n
1099    "callback_mode() -> handle_event_function." n
1100    n
1101    (erlang-skel-separator-start 2)
1102    "%% @private" n
1103    "%% @doc" n
1104    "%% Whenever a gen_statem is started using gen_statem:start/[3,4] or" n
1105    "%% gen_statem:start_link/[3,4], this function is called by the new" n
1106    "%% process to initialize." n
1107    (erlang-skel-separator-end 2)
1108    "-spec init(Args :: term()) ->" n>
1109    "gen_statem:init_result(term())." n
1110    "init([]) ->" n>
1111    "process_flag(trap_exit, true)," n>
1112    "{ok, state_name, #data{}}." n
1113    n
1114    (erlang-skel-separator-start 2)
1115    "%% @private" n
1116    "%% @doc" n
1117    "%% This function is called for every event a gen_statem receives." n
1118    (erlang-skel-separator-end 2)
1119    "-spec handle_event('enter'," n>
1120    "OldState :: term()," n>
1121    "State :: term()," n>
1122    "Data :: term()) ->" n>
1123    "gen_statem:state_enter_result(term());" n>
1124    "(gen_statem:event_type()," n>
1125    "Msg :: term()," n>
1126    "State :: term()," n>
1127    "Data :: term()) ->" n>
1128    "gen_statem:event_handler_result(term())." n
1129    ;;
1130    "handle_event({call,From}, _Msg, State, Data) ->" n>
1131    "{next_state, State, Data, [{reply,From,ok}]}." n
1132    n
1133    (erlang-skel-separator-start 2)
1134    "%% @private" n
1135    "%% @doc" n
1136    "%% This function is called by a gen_statem when it is about to" n
1137    "%% terminate. It should be the opposite of Module:init/1 and do any" n
1138    "%% necessary cleaning up. When it returns, the gen_statem terminates with" n
1139    "%% Reason. The return value is ignored." n
1140    (erlang-skel-separator-end 2)
1141    "-spec terminate(Reason :: term(), State :: term(), Data :: term()) ->" n>
1142    "any()." n
1143    "terminate(_Reason, _State, _Data) ->" n>
1144    "void." n
1145    n
1146    (erlang-skel-separator-start 2)
1147    "%% @private" n
1148    "%% @doc" n
1149    "%% Convert process state when code is changed" n
1150    (erlang-skel-separator-end 2)
1151    "-spec code_change(" n>
1152    "OldVsn :: term() | {down,term()}," n>
1153    "State :: term(), Data :: term(), Extra :: term()) ->" n>
1154    "{ok, NewState :: term(), NewData :: term()} |" n>
1155    "(Reason :: term())." n
1156    "code_change(_OldVsn, State, Data, _Extra) ->" n>
1157    "{ok, State, Data}." n
1158    n
1159    (erlang-skel-double-separator-start 3)
1160    "%%% Internal functions" n
1161    (erlang-skel-double-separator-end 3)
1162    )
1163  "*The template of a gen_statem (handle_event/4).
1164Please see the function `tempo-define-template'.")
1165
1166(defvar erlang-skel-wx-object
1167  '((erlang-skel-include erlang-skel-large-header)
1168    "-behaviour(wx_object)." n n
1169
1170    "-include_lib(\"wx/include/wx.hrl\")." n n
1171
1172    "%% API" n
1173    "-export([start_link/0])." n n
1174
1175    "%% wx_object callbacks" n
1176    "-export([init/1, handle_call/3, handle_cast/2, "
1177    "handle_info/2," n>
1178    "handle_event/2, terminate/2, code_change/3])." n n
1179
1180    "-record(state, {})." n n
1181
1182    (erlang-skel-double-separator-start 3)
1183    "%%% API" n
1184    (erlang-skel-double-separator-end 3) n
1185    (erlang-skel-separator-start 2)
1186    "%% @doc" n
1187    "%% Starts the server" n
1188    "%%" n
1189    "%% @spec start_link() -> wxWindow()" n
1190    (erlang-skel-separator-end 2)
1191    "start_link() ->" n>
1192    "wx_object:start_link(?MODULE, [], [])." n
1193    n
1194    (erlang-skel-double-separator-start 3)
1195    "%%% wx_object callbacks" n
1196    (erlang-skel-double-separator-end 3)
1197    n
1198    (erlang-skel-separator-start 2)
1199    "%% @private" n
1200    "%% @doc" n
1201    "%% Initializes the server" n
1202    "%%" n
1203    "%% @spec init(Args) -> {wxWindow(), State} |" n
1204    "%%                     {wxWindow(), State, Timeout} |" n
1205    "%%                     ignore |" n
1206    "%%                     {stop, Reason}" n
1207    (erlang-skel-separator-end 2)
1208    "init([]) ->" n>
1209    "wx:new()," n>
1210    "Frame = wxFrame:new()," n>
1211    "{Frame, #state{}}." n
1212    n
1213    (erlang-skel-separator-start 2)
1214    "%% @private" n
1215    "%% @doc" n
1216    "%% Handling events" n
1217    "%%" n
1218    "%% @spec handle_event(wx{}, State) ->" n
1219    "%%                                   {noreply, State} |" n
1220    "%%                                   {noreply, State, Timeout} |" n
1221    "%%                                   {stop, Reason, State}" n
1222    (erlang-skel-separator-end 2)
1223    "handle_event(#wx{}, State) ->" n>
1224    "{noreply, State}." n
1225    n
1226    (erlang-skel-separator-start 2)
1227    "%% @private" n
1228    "%% @doc" n
1229    "%% Handling call messages" n
1230    "%%" n
1231    "%% @spec handle_call(Request, From, State) ->" n
1232    "%%                                   {reply, Reply, State} |" n
1233    "%%                                   {reply, Reply, State, Timeout} |" n
1234    "%%                                   {noreply, State} |" n
1235    "%%                                   {noreply, State, Timeout} |" n
1236    "%%                                   {stop, Reason, Reply, State} |" n
1237    "%%                                   {stop, Reason, State}" n
1238    (erlang-skel-separator-end 2)
1239    "handle_call(_Request, _From, State) ->" n>
1240    "Reply = ok," n>
1241    "{reply, Reply, State}." n
1242    n
1243    (erlang-skel-separator-start 2)
1244    "%% @private" n
1245    "%% @doc" n
1246    "%% Handling cast messages" n
1247    "%%" n
1248    "%% @spec handle_cast(Msg, State) -> {noreply, State} |" n
1249    "%%                                  {noreply, State, Timeout} |" n
1250    "%%                                  {stop, Reason, State}" n
1251    (erlang-skel-separator-end 2)
1252    "handle_cast(_Msg, State) ->" n>
1253    "{noreply, State}." n
1254    n
1255    (erlang-skel-separator-start 2)
1256    "%% @private" n
1257    "%% @doc" n
1258    "%% Handling all non call/cast messages" n
1259    "%%" n
1260    "%% @spec handle_info(Info, State) -> {noreply, State} |" n
1261    "%%                                   {noreply, State, Timeout} |" n
1262    "%%                                   {stop, Reason, State}" n
1263    (erlang-skel-separator-end 2)
1264    "handle_info(_Info, State) ->" n>
1265    "{noreply, State}." n
1266    n
1267    (erlang-skel-separator-start 2)
1268    "%% @private" n
1269    "%% @doc" n
1270    "%% This function is called by a wx_object when it is about to" n
1271    "%% terminate. It should be the opposite of Module:init/1 and do any" n
1272    "%% necessary cleaning up. When it returns, the wx_object terminates" n
1273    "%% with Reason. The return value is ignored." n
1274    "%%" n
1275    "%% @spec terminate(Reason, State) -> void()" n
1276    (erlang-skel-separator-end 2)
1277    "terminate(_Reason, _State) ->" n>
1278    "ok." n
1279    n
1280    (erlang-skel-separator-start 2)
1281    "%% @private" n
1282    "%% @doc" n
1283    "%% Convert process state when code is changed" n
1284    "%%" n
1285    "%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
1286    (erlang-skel-separator-end 2)
1287    "code_change(_OldVsn, State, _Extra) ->" n>
1288    "{ok, State}." n
1289    n
1290    (erlang-skel-double-separator-start 3)
1291    "%%% Internal functions" n
1292    (erlang-skel-double-separator-end 3)
1293    )
1294  "*The template of a generic server.
1295Please see the function `tempo-define-template'.")
1296
1297(defvar erlang-skel-lib
1298  '((erlang-skel-include erlang-skel-large-header)
1299
1300    "%% API" n
1301    "-export([])." n n
1302
1303    (erlang-skel-double-separator-start 3)
1304    "%%% API" n
1305    (erlang-skel-double-separator-end 3) n
1306    (erlang-skel-separator-start 2)
1307    "%% @doc" n
1308    "%% @spec" n
1309    (erlang-skel-separator-end 2)
1310    n
1311    (erlang-skel-double-separator-start 3)
1312    "%%% Internal functions" n
1313    (erlang-skel-double-separator-end 3)
1314    )
1315  "*The template of a library module.
1316Please see the function `tempo-define-template'.")
1317
1318(defvar erlang-skel-corba-callback
1319  '((erlang-skel-include erlang-skel-large-header)
1320    "%% Include files" n n
1321
1322    "%% API" n
1323    "-export([])." n n
1324
1325    "%% Corba callbacks" n
1326    "-export([init/1, terminate/2, code_change/3])." n n
1327
1328    "-record(state, {})." n n
1329
1330    (erlang-skel-double-separator-start 3)
1331    "%%% Corba callbacks" n
1332    (erlang-skel-double-separator-end 3) n
1333    (erlang-skel-separator-start 2)
1334    "%% @private" n
1335    "%% @doc" n
1336    "%% Initializes the server" n
1337    "%%" n
1338    "%% @spec init(Args) -> {ok, State} |" n
1339    "%%                     {ok, State, Timeout} |" n
1340    "%%                     ignore |" n
1341    "%%                     {stop, Reason}" n
1342    (erlang-skel-separator-end 2)
1343    "init([]) ->" n>
1344    "{ok, #state{}}." n
1345    n
1346    (erlang-skel-separator-start 2)
1347    "%% @private" n
1348    "%% @doc" n
1349    "%% Shutdown the server" n
1350    "%%" n
1351    "%% @spec terminate(Reason, State) -> void()" n
1352    (erlang-skel-separator-end 2)
1353    "terminate(_Reason, _State) ->" n>
1354    "ok." n
1355    n
1356    (erlang-skel-separator-start 2)
1357    "%% @private" n
1358    "%% @doc" n
1359    "%% Convert process state when code is changed" n
1360    "%%" n
1361    "%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
1362    (erlang-skel-separator-end 2)
1363    "code_change(_OldVsn, State, _Extra) ->" n>
1364    "{ok, State}." n
1365    n
1366    (erlang-skel-double-separator-start 3)
1367    "%%% Internal functions" n
1368    (erlang-skel-double-separator-end 3)
1369    )
1370  "*The template of a library module.
1371Please see the function `tempo-define-template'.")
1372
1373(defvar erlang-skel-ts-test-suite
1374 '((erlang-skel-include erlang-skel-large-header)
1375   "%% Note: This directive should only be used in test suites." n
1376    "-compile(export_all)." n n
1377
1378    "-include_lib(\"common_test/include/ct.hrl\")." n n
1379
1380    (erlang-skel-separator-start 2)
1381    "%% TEST SERVER CALLBACK FUNCTIONS" n
1382    (erlang-skel-separator 2)
1383    n
1384    (erlang-skel-separator-start 2)
1385    "%%" n
1386    "%% @doc" n
1387    "%% Initialization before the suite." n
1388    "%%" n
1389    "%% Config0 = Config1 = [tuple()]" n
1390    "%%   A list of key/value pairs, holding the test case configuration." n
1391    "%% Reason = term()" n
1392    "%%   The reason for skipping the suite." n
1393    "%%" n
1394    "%% Note: This function is free to add any key/value pairs to the Config" n
1395    "%% variable, but should NOT alter/remove any existing entries." n
1396    "%%" n
1397    "%% @spec init_per_suite(Config) -> Config" n
1398    (erlang-skel-separator-end 2)
1399    "init_per_suite(Config) ->" n >
1400    "Config." n n
1401
1402    (erlang-skel-separator-start 2)
1403    "%% @doc" n
1404    "%% Cleanup after the suite." n
1405    "%% Config - [tuple()]" n
1406    "%%   A list of key/value pairs, holding the test case configuration." n
1407    "%%" n
1408    "%% @spec end_per_suite(Config) -> _" n
1409    (erlang-skel-separator-end 2)
1410    "end_per_suite(_Config) ->" n >
1411    "ok." n n
1412
1413    (erlang-skel-separator-start 2)
1414    "%% @doc" n
1415    "%% Initialization before each test case" n
1416    "%%" n
1417    "%% TestCase - atom()" n
1418    "%%   Name of the test case that is about to be run." n
1419    "%% Config - [tuple()]" n
1420    "%%   A list of key/value pairs, holding the test case configuration." n
1421    "%% Reason = term()" n
1422    "%%   The reason for skipping the test case." n
1423    "%%" n
1424    "%% Note: This function is free to add any key/value pairs to the Config" n
1425    "%% variable, but should NOT alter/remove any existing entries." n
1426    "%%" n
1427    "%% @spec init_per_testcase(TestCase, Config) -> Config" n
1428    (erlang-skel-separator-end 2)
1429    "init_per_testcase(_TestCase, Config) ->" n >
1430    "Config." n n
1431
1432    (erlang-skel-separator-start 2)
1433    "%% @doc" n
1434    "%% Cleanup after each test case" n
1435    "%%" n
1436    "%% TestCase = atom()" n
1437    "%%   Name of the test case that is finished." n
1438    "%% Config = [tuple()]" n
1439    "%%   A list of key/value pairs, holding the test case configuration." n
1440    "%%" n
1441    "%% @spec end_per_testcase(TestCase, Config) -> _" n
1442    (erlang-skel-separator-end 2)
1443    "end_per_testcase(_TestCase, _Config) ->" n >
1444    "ok."n n
1445
1446    (erlang-skel-separator-start 2)
1447    "%% @doc" n
1448    "%% Returns a description of the test suite when" n
1449    "%% Clause == doc, and a test specification (list" n
1450    "%% of the conf and test cases in the suite) when" n
1451    "%% Clause == suite." n
1452    "%% Returns a list of all test cases in this test suite" n
1453    "%%" n
1454    "%% Clause = doc | suite" n
1455    "%%   Indicates expected return value." n
1456    "%% Descr = [string()] | []" n
1457    "%%   String that describes the test suite." n
1458    "%% Spec = [TestCase]" n
1459    "%%   A test specification." n
1460    "%% TestCase = ConfCase | atom()" n
1461    "%%   Configuration case, or the name of a test case function." n
1462    "%% ConfCase = {conf,Init,Spec,End} |" n
1463    "%%            {conf,Properties,Init,Spec,End}" n
1464    "%% Init = End = {Mod,Func} | Func" n
1465    "%%   Initialization and cleanup function." n
1466    "%% Mod = Func = atom()" n
1467    "%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]" n
1468    "%%   Execution properties of the test cases (may be combined)." n
1469    "%% Shuffle = shuffle | {shuffle,Seed}" n
1470    "%%   To get cases executed in random order." n
1471    "%% Seed = {integer(),integer(),integer()}" n
1472    "%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |" n
1473    "%%              repeat_until_any_ok | repeat_until_any_fail" n
1474    "%%   To get execution of cases repeated." n
1475    "%% N = integer() | forever" n
1476    "%% Reason = term()" n
1477    "%%   The reason for skipping the test suite." n
1478    "%%" n
1479    "%% @spec all(Clause) -> TestCases" n
1480    (erlang-skel-separator-end 2)
1481    "all(doc) ->" n >
1482    "[\"Describe the main purpose of this suite\"];" n n
1483    "all(suite) -> " n >
1484    "[a_test_case]." n n
1485    n
1486    (erlang-skel-separator-start 2)
1487    "%% TEST CASES" n
1488    (erlang-skel-separator 2)
1489    n
1490    (erlang-skel-separator-start 2)
1491    "%% @doc" n
1492    "%%  Test case function. Returns a description of the test" n
1493    "%%  case (doc), then returns a test specification (suite)," n
1494    "%%  or performs the actual test (Config)." n
1495    "%%" n
1496    "%% Arg = doc | suite | Config" n
1497    "%%   Indicates expected behaviour and return value." n
1498    "%% Config = [tuple()]" n
1499    "%%   A list of key/value pairs, holding the test case configuration." n
1500    "%% Descr = [string()] | []" n
1501    "%%   String that describes the test case." n
1502    "%% Spec = [tuple()] | []" n
1503    "%%   A test specification, see all/1." n
1504    "%% Reason = term()" n
1505    "%%   The reason for skipping the test case." n
1506    "%%" n
1507    "%% @spec TestCase(Arg) -> Descr | Spec | ok | exit() | {skip,Reason}" n
1508
1509    (erlang-skel-separator-end 2)
1510    "a_test_case(doc) -> " n >
1511    "[\"Describe the main purpose of this test case\"];" n n
1512    "a_test_case(suite) -> " n >
1513    "[];" n n
1514    "a_test_case(Config) when is_list(Config) -> " n >
1515    "ok." n
1516   )
1517 "*The template of a library module.
1518Please see the function `tempo-define-template'.")
1519
1520(defvar erlang-skel-ct-test-suite-s
1521  '((erlang-skel-include erlang-skel-large-header)
1522    "-compile(export_all)." n n
1523
1524    "-include_lib(\"common_test/include/ct.hrl\")." n n
1525
1526    (erlang-skel-separator-start 2)
1527    "%% @spec suite() -> Info" n
1528    "%% Info = [tuple()]" n
1529    (erlang-skel-separator-end 2)
1530    "suite() ->" n >
1531    "[{timetrap,{seconds,30}}]." n n
1532
1533    (erlang-skel-separator-start 2)
1534    "%% @spec init_per_suite(Config0) ->" n
1535    "%%     Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1536    "%% Config0 = Config1 = [tuple()]" n
1537    "%% Reason = term()" n
1538    (erlang-skel-separator-end 2)
1539    "init_per_suite(Config) ->" n >
1540    "Config." n n
1541
1542    (erlang-skel-separator-start 2)
1543    "%% @spec end_per_suite(Config0) -> term() | {save_config,Config1}" n
1544    "%% Config0 = Config1 = [tuple()]" n
1545    (erlang-skel-separator-end 2)
1546    "end_per_suite(_Config) ->" n >
1547    "ok." n n
1548
1549    (erlang-skel-separator-start 2)
1550    "%% @spec init_per_group(GroupName, Config0) ->" n
1551    "%%               Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1552    "%% GroupName = atom()" n
1553    "%% Config0 = Config1 = [tuple()]" n
1554    "%% Reason = term()" n
1555    (erlang-skel-separator-end 2)
1556    "init_per_group(_GroupName, Config) ->" n >
1557    "Config." n n
1558
1559    (erlang-skel-separator-start 2)
1560    "%% @spec end_per_group(GroupName, Config0) ->" n
1561    "%%               term() | {save_config,Config1}" n
1562    "%% GroupName = atom()" n
1563    "%% Config0 = Config1 = [tuple()]" n
1564    (erlang-skel-separator-end 2)
1565    "end_per_group(_GroupName, _Config) ->" n >
1566    "ok." n n
1567
1568    (erlang-skel-separator-start 2)
1569    "%% @spec init_per_testcase(TestCase, Config0) ->" n
1570    "%%               Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1571    "%% TestCase = atom()" n
1572    "%% Config0 = Config1 = [tuple()]" n
1573    "%% Reason = term()" n
1574    (erlang-skel-separator-end 2)
1575    "init_per_testcase(_TestCase, Config) ->" n >
1576    "Config." n n
1577
1578    (erlang-skel-separator-start 2)
1579    "%% @spec end_per_testcase(TestCase, Config0) ->" n
1580    "%%               term() | {save_config,Config1} | {fail,Reason}" n
1581    "%% TestCase = atom()" n
1582    "%% Config0 = Config1 = [tuple()]" n
1583    "%% Reason = term()" n
1584    (erlang-skel-separator-end 2)
1585    "end_per_testcase(_TestCase, _Config) ->" n >
1586    "ok." n n
1587
1588    (erlang-skel-separator-start 2)
1589    "%% @spec groups() -> [Group]" n
1590    "%% Group = {GroupName,Properties,GroupsAndTestCases}" n
1591    "%% GroupName = atom()" n
1592    "%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]" n
1593    "%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]" n
1594    "%% TestCase = atom()" n
1595    "%% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}" n
1596    "%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |" n
1597    "%%              repeat_until_any_ok | repeat_until_any_fail" n
1598    "%% N = integer() | forever" n
1599    (erlang-skel-separator-end 2)
1600    "groups() ->" n >
1601    "[]." n n
1602
1603    (erlang-skel-separator-start 2)
1604    "%% @spec all() -> GroupsAndTestCases | {skip,Reason}" n
1605    "%% GroupsAndTestCases = [{group,GroupName} | TestCase]" n
1606    "%% GroupName = atom()" n
1607    "%% TestCase = atom()" n
1608    "%% Reason = term()" n
1609    (erlang-skel-separator-end 2)
1610    "all() -> " n >
1611    "[my_test_case]." n n
1612
1613    (erlang-skel-separator-start 2)
1614    "%% @spec TestCase() -> Info" n
1615    "%% Info = [tuple()]" n
1616    (erlang-skel-separator-end 2)
1617    "my_test_case() -> " n >
1618    "[]." n n
1619
1620    (erlang-skel-separator-start 2)
1621    "%% @spec TestCase(Config0) ->" n
1622    "%%               ok | exit() | {skip,Reason} | {comment,Comment} |" n
1623    "%%               {save_config,Config1} | {skip_and_save,Reason,Config1}" n
1624    "%% Config0 = Config1 = [tuple()]" n
1625    "%% Reason = term()" n
1626    "%% Comment = term()" n
1627    (erlang-skel-separator-end 2)
1628    "my_test_case(_Config) -> " n >
1629    "ok." n
1630    )
1631  "*The template of a library module.
1632Please see the function `tempo-define-template'.")
1633
1634
1635(defvar erlang-skel-ct-test-suite-l
1636  '((erlang-skel-include erlang-skel-large-header)
1637    "%% Note: This directive should only be used in test suites." n
1638    "-compile(export_all)." n n
1639
1640    "-include_lib(\"common_test/include/ct.hrl\")." n n
1641
1642    (erlang-skel-separator-start 2)
1643    "%% COMMON TEST CALLBACK FUNCTIONS" n
1644    (erlang-skel-separator 2)
1645    n
1646    (erlang-skel-separator-start 2)
1647    "%% @doc" n
1648    "%%  Returns list of tuples to set default properties" n
1649    "%%  for the suite." n
1650    "%%" n
1651    "%% Function: suite() -> Info" n
1652    "%%" n
1653    "%% Info = [tuple()]" n
1654    "%%   List of key/value pairs." n
1655    "%%" n
1656    "%% Note: The suite/0 function is only meant to be used to return" n
1657    "%% default data values, not perform any other operations." n
1658    "%%" n
1659    "%% @spec suite() -> Info" n
1660    (erlang-skel-separator-end 2)
1661    "suite() ->" n >
1662    "[{timetrap,{minutes,10}}]." n n
1663
1664    (erlang-skel-separator-start 2)
1665    "%% @doc" n
1666    "%% Initialization before the whole suite" n
1667    "%%" n
1668    "%% Config0 = Config1 = [tuple()]" n
1669    "%%   A list of key/value pairs, holding the test case configuration." n
1670    "%% Reason = term()" n
1671    "%%   The reason for skipping the suite." n
1672    "%%" n
1673    "%% Note: This function is free to add any key/value pairs to the Config" n
1674    "%% variable, but should NOT alter/remove any existing entries." n
1675    "%%" n
1676    "%% @spec init_per_suite(Config0) ->" n
1677    "%%               Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1678    (erlang-skel-separator-end 2)
1679    "init_per_suite(Config) ->" n >
1680    "Config." n n
1681
1682    (erlang-skel-separator-start 2)
1683    "%% @doc" n
1684    "%% Cleanup after the whole suite" n
1685    "%%" n
1686    "%% Config - [tuple()]" n
1687    "%%   A list of key/value pairs, holding the test case configuration." n
1688    "%%" n
1689    "%% @spec end_per_suite(Config) -> _" n
1690    (erlang-skel-separator-end 2)
1691    "end_per_suite(_Config) ->" n >
1692    "ok." n n
1693
1694    (erlang-skel-separator-start 2)
1695    "%% @doc" n
1696    "%% Initialization before each test case group." n
1697    "%%" n
1698    "%% GroupName = atom()" n
1699    "%%   Name of the test case group that is about to run." n
1700    "%% Config0 = Config1 = [tuple()]" n
1701    "%%   A list of key/value pairs, holding configuration data for the group." n
1702    "%% Reason = term()" n
1703    "%%   The reason for skipping all test cases and subgroups in the group." n
1704    "%%" n
1705    "%% @spec init_per_group(GroupName, Config0) ->" n
1706    "%%               Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1707    (erlang-skel-separator-end 2)
1708    "init_per_group(_GroupName, Config) ->" n >
1709    "Config." n n
1710
1711    (erlang-skel-separator-start 2)
1712    "%% @doc" n
1713    "%% Cleanup after each test case group." n
1714    "%%" n
1715    "%% GroupName = atom()" n
1716    "%%   Name of the test case group that is finished." n
1717    "%% Config0 = Config1 = [tuple()]" n
1718    "%%   A list of key/value pairs, holding configuration data for the group." n
1719    "%%" n
1720    "%% @spec end_per_group(GroupName, Config0) ->" n
1721    "%%               term() | {save_config,Config1}" n
1722    (erlang-skel-separator-end 2)
1723    "end_per_group(_GroupName, _Config) ->" n >
1724    "ok." n n
1725    (erlang-skel-separator-start 2)
1726    "%% @doc" n
1727    "%% Initialization before each test case" n
1728    "%%" n
1729    "%% TestCase - atom()" n
1730    "%%   Name of the test case that is about to be run." n
1731    "%% Config0 = Config1 = [tuple()]" n
1732    "%%   A list of key/value pairs, holding the test case configuration." n
1733    "%% Reason = term()" n
1734    "%%   The reason for skipping the test case." n
1735    "%%" n
1736    "%% Note: This function is free to add any key/value pairs to the Config" n
1737    "%% variable, but should NOT alter/remove any existing entries." n
1738    "%%" n
1739    "%% @spec init_per_testcase(TestCase, Config0) ->" n
1740    "%%               Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
1741    (erlang-skel-separator-end 2)
1742    "init_per_testcase(_TestCase, Config) ->" n >
1743    "Config." n n
1744
1745    (erlang-skel-separator-start 2)
1746    "%% @doc" n
1747    "%% Cleanup after each test case" n
1748    "%%" n
1749    "%% TestCase - atom()" n
1750    "%%   Name of the test case that is finished." n
1751    "%% Config0 = Config1 = [tuple()]" n
1752    "%%   A list of key/value pairs, holding the test case configuration." n
1753    "%%" n
1754    "%% @spec end_per_testcase(TestCase, Config0) ->" n
1755    "%%               term() | {save_config,Config1} | {fail,Reason}" n
1756    (erlang-skel-separator-end 2)
1757    "end_per_testcase(_TestCase, _Config) ->" n >
1758    "ok." n n
1759
1760    (erlang-skel-separator-start 2)
1761    "%% @doc" n
1762    "%% Returns a list of test case group definitions." n
1763    "%%" n
1764    "%% Group = {GroupName,Properties,GroupsAndTestCases}" n
1765    "%% GroupName = atom()" n
1766    "%%   The name of the group." n
1767    "%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]" n
1768    "%%   Group properties that may be combined." n
1769    "%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]" n
1770    "%% TestCase = atom()" n
1771    "%%   The name of a test case." n
1772    "%% Shuffle = shuffle | {shuffle,Seed}" n
1773    "%%   To get cases executed in random order." n
1774    "%% Seed = {integer(),integer(),integer()}" n
1775    "%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |" n
1776    "%%              repeat_until_any_ok | repeat_until_any_fail" n
1777    "%%   To get execution of cases repeated." n
1778    "%% N = integer() | forever" n
1779    "%%" n
1780    "%% @spec: groups() -> [Group]" n
1781    (erlang-skel-separator-end 2)
1782    "groups() ->" n >
1783    "[]." n n
1784
1785    (erlang-skel-separator-start 2)
1786    "%% @doc" n
1787    "%%  Returns the list of groups and test cases that" n
1788    "%%  are to be executed." n
1789    "%%" n
1790    "%% GroupsAndTestCases = [{group,GroupName} | TestCase]" n
1791    "%% GroupName = atom()" n
1792    "%%   Name of a test case group." n
1793    "%% TestCase = atom()" n
1794    "%%   Name of a test case." n
1795    "%% Reason = term()" n
1796    "%%   The reason for skipping all groups and test cases." n
1797    "%%" n
1798    "%% @spec all() -> GroupsAndTestCases | {skip,Reason}" n
1799    (erlang-skel-separator-end 2)
1800    "all() -> " n >
1801    "[my_test_case]." n n
1802
1803    n
1804    (erlang-skel-separator-start 2)
1805    "%% TEST CASES" n
1806    (erlang-skel-separator 2)
1807    n
1808
1809    (erlang-skel-separator-start 2)
1810    "%% @doc " n
1811    "%%  Test case info function - returns list of tuples to set" n
1812    "%%  properties for the test case." n
1813    "%%" n
1814    "%% Info = [tuple()]" n
1815    "%%   List of key/value pairs." n
1816    "%%" n
1817    "%% Note: This function is only meant to be used to return a list of" n
1818    "%% values, not perform any other operations." n
1819    "%%" n
1820    "%% @spec TestCase() -> Info " n
1821    (erlang-skel-separator-end 2)
1822    "my_test_case() -> " n >
1823    "[]." n n
1824
1825    (erlang-skel-separator 2)
1826    "%% @doc Test case function. (The name of it must be specified in" n
1827    "%%              the all/0 list or in a test case group for the test case" n
1828    "%%              to be executed)." n
1829    "%%" n
1830    "%% Config0 = Config1 = [tuple()]" n
1831    "%%   A list of key/value pairs, holding the test case configuration." n
1832    "%% Reason = term()" n
1833    "%%   The reason for skipping the test case." n
1834    "%% Comment = term()" n
1835    "%%   A comment about the test case that will be printed in the html log." n
1836    "%%" n
1837    "%% @spec TestCase(Config0) ->" n
1838    "%%           ok | exit() | {skip,Reason} | {comment,Comment} |" n
1839    "%%           {save_config,Config1} | {skip_and_save,Reason,Config1}" n
1840    (erlang-skel-separator-end 2)
1841    "my_test_case(_Config) -> " n >
1842    "ok." n
1843
1844    )
1845 "*The template of a library module.
1846 Please see the function `tempo-define-template'.")
1847
1848;; Skeleton code:
1849
1850;; This code is based on the package `tempo' which is part of modern
1851;; Emacsen.  (GNU Emacs 19.25 (?) and XEmacs 19.14.)
1852
1853(defun erlang-skel-init ()
1854  "Generate the skeleton functions and menu items.
1855The variable `erlang-skel' contains the name and descriptions of
1856all skeletons.
1857
1858The skeleton routines are based on the `tempo' package.  Should this
1859package not be present, this function does nothing."
1860  (interactive)
1861  (condition-case nil
1862      (require 'tempo)
1863    (error t))
1864  (if (featurep 'tempo)
1865      (let ((skel erlang-skel)
1866            (menu '()))
1867        (while skel
1868          (cond ((null (car skel))
1869                 (setq menu (cons nil menu)))
1870                (t
1871                 (funcall (symbol-function 'tempo-define-template)
1872                          (concat "erlang-" (nth 1 (car skel)))
1873                          ;; The tempo template used contains an `include'
1874                          ;; function call only, hence changes to the
1875                          ;; variables describing the templates take effect
1876                          ;; immdiately.
1877                          (list (list 'erlang-skel-include (nth 2 (car skel))))
1878                          (nth 1 (car skel)))
1879                 (setq menu (cons (erlang-skel-make-menu-item
1880                                   (car skel)) menu))))
1881          (setq skel (cdr skel)))
1882        (setq erlang-menu-skel-items
1883              (list nil (list "Skeletons" (nreverse menu))))
1884        (setq erlang-menu-items
1885              (erlang-menu-add-above 'erlang-menu-skel-items
1886                                     'erlang-menu-version-items
1887                                     erlang-menu-items))
1888        (erlang-menu-init))))
1889
1890(defun erlang-skel-make-menu-item (skel)
1891  (let ((func (intern (concat "tempo-template-erlang-" (nth 1 skel)))))
1892    (cond ((null (nth 3 skel))
1893           (list (car skel) func))
1894          (t
1895           (list (car skel)
1896                 (list 'lambda '()
1897                       '(interactive)
1898                       (list 'funcall
1899                             (list 'quote (nth 3 skel))
1900                             (list 'quote func))))))))
1901
1902;; Functions designed to be added to the skeleton menu.
1903;; (Not normally used)
1904(defun erlang-skel-insert (func)
1905  "Insert skeleton generated by FUNC and goto first tempo mark."
1906  (save-excursion (funcall func))
1907  (funcall (symbol-function 'tempo-forward-mark)))
1908
1909(defun erlang-skel-header (func)
1910  "Insert the header generated by FUNC at the beginning of the buffer."
1911  (goto-char (point-min))
1912  (save-excursion (funcall func))
1913  (funcall (symbol-function 'tempo-forward-mark)))
1914
1915
1916;; Functions used inside the skeleton descriptions.
1917(defun erlang-skel-skip-blank ()
1918  (skip-chars-backward " \t")
1919  nil)
1920
1921(defun erlang-skel-include (&rest args)
1922  "Include a template inside another template.
1923
1924Example of use, assuming that `erlang-skel-func' is defined:
1925
1926 (defvar foo-skeleton '(\"%%% New function:\"
1927                        (erlang-skel-include erlang-skel-func)))
1928
1929Technically, this function returns the `tempo' attribute`(l ...)' which
1930can contain other `tempo' attributes.  Please see the function
1931`tempo-define-template' for a description of the `(l ...)' attribute."
1932  (let ((res '())
1933        entry)
1934    (while args
1935      (setq entry (car args))
1936      (while entry
1937        (setq res (cons (car entry) res))
1938        (setq entry (cdr entry)))
1939      (setq args (cdr args)))
1940    (cons 'l (nreverse res))))
1941
1942(defun erlang-skel-separator (&optional percent)
1943  "Return a comment separator."
1944  (let ((percent (or percent 3)))
1945    (concat (make-string percent ?%)
1946            (make-string (- 70 percent) ?-)
1947            "\n")))
1948
1949(defun erlang-skel-separator-start (&optional percent)
1950  "Return a comment separator or an empty string if separators
1951are configured off."
1952  (if erlang-skel-use-separators
1953      (erlang-skel-separator percent)
1954    ""))
1955
1956(defun erlang-skel-separator-end (&optional percent)
1957  "Return a comment separator to end a function comment block or an
1958empty string if separators are configured off."
1959  (if erlang-skel-use-separators
1960      (concat "%% @end\n" (erlang-skel-separator percent))
1961    ""))
1962
1963(defun erlang-skel-double-separator (&optional percent)
1964  "Return a double line (equals sign) comment separator."
1965  (let ((percent (or percent 3)))
1966    (concat (make-string percent ?%)
1967            (make-string (- 70 percent) ?=)
1968            "\n")))
1969
1970(defun erlang-skel-double-separator-start (&optional percent)
1971  "Return a double separator or a newline if separators are configured off."
1972  (if erlang-skel-use-separators
1973      (erlang-skel-double-separator percent)
1974    "\n"))
1975
1976(defun erlang-skel-double-separator-end (&optional percent)
1977  "Return a double separator or an empty string if separators are
1978configured off."
1979  (if erlang-skel-use-separators
1980      (erlang-skel-double-separator percent)
1981    ""))
1982
1983(defun erlang-skel-dd-mmm-yyyy ()
1984  "Return the current date as a string in \"DD Mon YYYY\" form.
1985The first character of DD is space if the value is less than 10."
1986  (let ((date (current-time-string)))
1987    (format "%2d %s %s"
1988            (string-to-number (substring date 8 10))
1989            (substring date 4 7)
1990            (substring date -4))))
1991
1992(defun erlang-skel-get-function-name ()
1993  (save-excursion
1994    (erlang-beginning-of-function -1)
1995    (erlang-get-function-name)))
1996
1997(defun erlang-skel-get-function-args ()
1998  (save-excursion
1999    (erlang-beginning-of-function -1)
2000    (erlang-get-function-arguments)))
2001
2002;; Local variables:
2003;; coding: iso-8859-1
2004;; End:
2005
2006;;; erlang-skels.el ends here
2007