Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1553 lines
54 KiB

  1. ;;
  2. ;; %CopyrightBegin%
  3. ;;
  4. ;; Copyright Ericsson AB 2010. All Rights Reserved.
  5. ;;
  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/.
  11. ;;
  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
  15. ;; under the License.
  16. ;;
  17. ;; %CopyrightEnd%
  18. ;;;
  19. ;;; Purpose: Provide Erlang code skeletons.
  20. ;;; See 'erlang-skel-file' variable.
  21. (defvar erlang-tempo-tags nil
  22. "Tempo tags for erlang mode")
  23. (defvar erlang-skel
  24. '(("If" "if" erlang-skel-if)
  25. ("Case" "case" erlang-skel-case)
  26. ("Receive" "receive" erlang-skel-receive)
  27. ("Receive After" "after" erlang-skel-receive-after)
  28. ("Receive Loop" "loop" erlang-skel-receive-loop)
  29. ("Module" "module" erlang-skel-module)
  30. ("Author" "author" erlang-skel-author)
  31. ("Function" "function" erlang-skel-function)
  32. ()
  33. ("Small Header" "small-header"
  34. erlang-skel-small-header erlang-skel-header)
  35. ("Normal Header" "normal-header"
  36. erlang-skel-normal-header erlang-skel-header)
  37. ("Large Header" "large-header"
  38. erlang-skel-large-header erlang-skel-header)
  39. ()
  40. ("Small Server" "small-server"
  41. erlang-skel-small-server erlang-skel-header)
  42. ()
  43. ("Application" "application"
  44. erlang-skel-application erlang-skel-header)
  45. ("Supervisor" "supervisor"
  46. erlang-skel-supervisor erlang-skel-header)
  47. ("supervisor_bridge" "supervisor-bridge"
  48. erlang-skel-supervisor-bridge erlang-skel-header)
  49. ("gen_server" "generic-server"
  50. erlang-skel-generic-server erlang-skel-header)
  51. ("gen_event" "gen-event"
  52. erlang-skel-gen-event erlang-skel-header)
  53. ("gen_fsm" "gen-fsm"
  54. erlang-skel-gen-fsm erlang-skel-header)
  55. ("Library module" "gen-lib"
  56. erlang-skel-lib erlang-skel-header)
  57. ("Corba callback" "gen-corba-cb"
  58. erlang-skel-corba-callback erlang-skel-header)
  59. ("Small Common Test suite" "ct-test-suite-s"
  60. erlang-skel-ct-test-suite-s erlang-skel-header)
  61. ("Large Common Test suite" "ct-test-suite-l"
  62. erlang-skel-ct-test-suite-l erlang-skel-header)
  63. ("Erlang TS test suite" "ts-test-suite"
  64. erlang-skel-ts-test-suite erlang-skel-header)
  65. )
  66. "*Description of all skeleton templates.
  67. Both functions and menu entries will be created.
  68. Each entry in `erlang-skel' should be a list with three or four
  69. elements, or the empty list.
  70. The first element is the name which shows up in the menu. The second
  71. is the `tempo' identifier (The string \"erlang-\" will be added in
  72. front of it). The third is the skeleton descriptor, a variable
  73. containing `tempo' attributes as described in the function
  74. `tempo-define-template'. The optional fourth elements denotes a
  75. function which should be called when the menu is selected.
  76. Functions corresponding to every template will be created. The name
  77. of the function will be `tempo-template-erlang-X' where `X' is the
  78. tempo identifier as specified in the second argument of the elements
  79. in this list.
  80. A list with zero elements means that the a horizontal line should
  81. be placed in the menu.")
  82. (defvar erlang-skel-use-separators t
  83. "A boolean than determines whether the skeletons include horizontal
  84. separators.
  85. Should this variable be nil, the documentation for functions will not
  86. include separators of the form %%--...")
  87. ;; In XEmacs `user-mail-address' returns "x@y.z (Foo Bar)" ARGH!
  88. ;; What's wrong with that? RFC 822 says it's legal. [sverkerw]
  89. ;; This needs to use the customized value. If that's not sane, things like
  90. ;; add-log will lose anyhow. Avoid it if there _is_ a paren.
  91. (defvar erlang-skel-mail-address
  92. (if (or (not user-mail-address) (string-match "(" user-mail-address))
  93. (concat (user-login-name) "@"
  94. (or (and (boundp 'mail-host-address)
  95. mail-host-address)
  96. (system-name)))
  97. user-mail-address)
  98. "Mail address of the user.")
  99. ;; Expression templates:
  100. (defvar erlang-skel-case
  101. '((erlang-skel-skip-blank) o >
  102. "case " p " of" n> p "_ ->" n> p "ok" n> "end" p)
  103. "*The skeleton of a `case' expression.
  104. Please see the function `tempo-define-template'.")
  105. (defvar erlang-skel-if
  106. '((erlang-skel-skip-blank) o >
  107. "if" n> p " ->" n> p "ok" n> "end" p)
  108. "The skeleton of an `if' expression.
  109. Please see the function `tempo-define-template'.")
  110. (defvar erlang-skel-receive
  111. '((erlang-skel-skip-blank) o >
  112. "receive" n> p "_ ->" n> p "ok" n> "end" p)
  113. "*The skeleton of a `receive' expression.
  114. Please see the function `tempo-define-template'.")
  115. (defvar erlang-skel-receive-after
  116. '((erlang-skel-skip-blank) o >
  117. "receive" n> p "_ ->" n> p "ok" n> "after " p "T ->" n>
  118. p "ok" n> "end" p)
  119. "*The skeleton of a `receive' expression with an `after' clause.
  120. Please see the function `tempo-define-template'.")
  121. (defvar erlang-skel-receive-loop
  122. '(& o "loop(" p ") ->" n> "receive" n> p "_ ->" n>
  123. "loop(" p ")" n> "end.")
  124. "*The skeleton of a simple `receive' loop.
  125. Please see the function `tempo-define-template'.")
  126. (defvar erlang-skel-function
  127. '((erlang-skel-separator-start 2)
  128. "%% @doc" n
  129. "%% @spec" n
  130. (erlang-skel-separator-end 2))
  131. "*The template of a function skeleton.
  132. Please see the function `tempo-define-template'.")
  133. ;; Attribute templates
  134. (defvar erlang-skel-module
  135. '(& "-module("
  136. (erlang-add-quotes-if-needed (erlang-get-module-from-file-name))
  137. ")." n)
  138. "*The skeleton of a `module' attribute.
  139. Please see the function `tempo-define-template'.")
  140. (defvar erlang-skel-author
  141. '(& "-author('" erlang-skel-mail-address "')." n)
  142. "*The skeleton of a `author' attribute.
  143. Please see the function `tempo-define-template'.")
  144. (defvar erlang-skel-vc nil
  145. "*The skeleton template to generate a version control attribute.
  146. The default is to insert nothing. Example of usage:
  147. (setq erlang-skel-vc '(& \"-rcs(\\\"$\Id: $ \\\").\") n)
  148. Please see the function `tempo-define-template'.")
  149. (defvar erlang-skel-export
  150. '(& "-export([" n> "])." n)
  151. "*The skeleton of an `export' attribute.
  152. Please see the function `tempo-define-template'.")
  153. (defvar erlang-skel-import
  154. '(& "%%-import(Module, [Function/Arity, ...])." n)
  155. "*The skeleton of an `import' attribute.
  156. Please see the function `tempo-define-template'.")
  157. (defvar erlang-skel-compile nil
  158. ;; '(& "%%-compile(export_all)." n)
  159. "*The skeleton of a `compile' attribute.
  160. Please see the function `tempo-define-template'.")
  161. ;; Comment templates.
  162. (defvar erlang-skel-date-function 'erlang-skel-dd-mmm-yyyy
  163. "*Function which returns date string.
  164. Look in the module `time-stamp' for a battery of functions.")
  165. (defvar erlang-skel-copyright-comment
  166. (if (boundp '*copyright-organization*)
  167. '(& "%%% @copyright (C) " (format-time-string "%Y") ", "
  168. *copyright-organization* n)
  169. '(& "%%% @copyright (C) " (format-time-string "%Y") ", "
  170. (user-full-name) n))
  171. "*The template for a copyright line in the header, normally empty.
  172. This variable should be bound to a `tempo' template, for example:
  173. '(& \"%%% Copyright (C) 2000, Yoyodyne, Inc.\" n)
  174. Please see the function `tempo-define-template'.")
  175. (defvar erlang-skel-created-comment
  176. '(& "%%% Created : " (funcall erlang-skel-date-function) " by "
  177. (user-full-name) " <" erlang-skel-mail-address ">" n)
  178. "*The template for the \"Created:\" comment line.")
  179. (defvar erlang-skel-author-comment
  180. '(& "%%% @author " (user-full-name) " <" erlang-skel-mail-address ">" n)
  181. "*The template for creating the \"Author:\" line in the header.
  182. Please see the function `tempo-define-template'.")
  183. (defvar erlang-skel-small-header
  184. '(o (erlang-skel-include erlang-skel-module)
  185. n
  186. (erlang-skel-include erlang-skel-compile erlang-skel-vc))
  187. "*The template of a small header without any comments.
  188. Please see the function `tempo-define-template'.")
  189. (defvar erlang-skel-normal-header
  190. '(o (erlang-skel-include erlang-skel-author-comment)
  191. (erlang-skel-include erlang-skel-copyright-comment)
  192. "%%% @doc" n
  193. "%%%" p n
  194. "%%% @end" n
  195. (erlang-skel-include erlang-skel-created-comment) n
  196. (erlang-skel-include erlang-skel-small-header) n)
  197. "*The template of a normal header.
  198. Please see the function `tempo-define-template'.")
  199. (defvar erlang-skel-large-header
  200. '(o (erlang-skel-separator)
  201. (erlang-skel-include erlang-skel-author-comment)
  202. (erlang-skel-include erlang-skel-copyright-comment)
  203. "%%% @doc" n
  204. "%%%" p n
  205. "%%% @end" n
  206. (erlang-skel-include erlang-skel-created-comment)
  207. (erlang-skel-separator)
  208. (erlang-skel-include erlang-skel-small-header) )
  209. "*The template of a large header.
  210. Please see the function `tempo-define-template'.")
  211. ;; Server templates.
  212. (defvar erlang-skel-small-server
  213. '((erlang-skel-include erlang-skel-large-header)
  214. "-export([start/0, init/1])." n n n
  215. "start() ->" n> "spawn(" (erlang-get-module-from-file-name)
  216. ", init, [self()])." n n
  217. "init(From) ->" n>
  218. "loop(From)." n n
  219. "loop(From) ->" n>
  220. "receive" n>
  221. p "_ ->" n>
  222. "loop(From)" n>
  223. "end." n
  224. )
  225. "*Template of a small server.
  226. Please see the function `tempo-define-template'.")
  227. ;; Behaviour templates.
  228. (defvar erlang-skel-application
  229. '((erlang-skel-include erlang-skel-large-header)
  230. "-behaviour(application)." n n
  231. "%% Application callbacks" n
  232. "-export([start/2, stop/1])." n n
  233. (erlang-skel-double-separator-start 3)
  234. "%%% Application callbacks" n
  235. (erlang-skel-double-separator-end 3) n
  236. (erlang-skel-separator-start 2)
  237. "%% @private" n
  238. "%% @doc" n
  239. "%% This function is called whenever an application is started using" n
  240. "%% application:start/[1,2], and should start the processes of the" n
  241. "%% application. If the application is structured according to the OTP" n
  242. "%% design principles as a supervision tree, this means starting the" n
  243. "%% top supervisor of the tree." n
  244. "%%" n
  245. "%% @spec start(StartType, StartArgs) -> {ok, Pid} |" n
  246. "%% {ok, Pid, State} |" n
  247. "%% {error, Reason}" n
  248. "%% StartType = normal | {takeover, Node} | {failover, Node}" n
  249. "%% StartArgs = term()" n
  250. (erlang-skel-separator-end 2)
  251. "start(_StartType, _StartArgs) ->" n>
  252. "case 'TopSupervisor':start_link() of" n>
  253. "{ok, Pid} ->" n>
  254. "{ok, Pid};" n>
  255. "Error ->" n>
  256. "Error" n>
  257. "end." n
  258. n
  259. (erlang-skel-separator-start 2)
  260. "%% @private" n
  261. "%% @doc" n
  262. "%% This function is called whenever an application has stopped. It" n
  263. "%% is intended to be the opposite of Module:start/2 and should do" n
  264. "%% any necessary cleaning up. The return value is ignored." n
  265. "%%" n
  266. "%% @spec stop(State) -> void()" n
  267. (erlang-skel-separator-end 2)
  268. "stop(_State) ->" n>
  269. "ok." n
  270. n
  271. (erlang-skel-double-separator-start 3)
  272. "%%% Internal functions" n
  273. (erlang-skel-double-separator-end 3)
  274. )
  275. "*The template of an application behaviour.
  276. Please see the function `tempo-define-template'.")
  277. (defvar erlang-skel-supervisor
  278. '((erlang-skel-include erlang-skel-large-header)
  279. "-behaviour(supervisor)." n n
  280. "%% API" n
  281. "-export([start_link/0])." n n
  282. "%% Supervisor callbacks" n
  283. "-export([init/1])." n n
  284. "-define(SERVER, ?MODULE)." n n
  285. (erlang-skel-double-separator-start 3)
  286. "%%% API functions" n
  287. (erlang-skel-double-separator-end 3) n
  288. (erlang-skel-separator-start 2)
  289. "%% @doc" n
  290. "%% Starts the supervisor" n
  291. "%%" n
  292. "%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
  293. (erlang-skel-separator-end 2)
  294. "start_link() ->" n>
  295. "supervisor:start_link({local, ?SERVER}, ?MODULE, [])." n
  296. n
  297. (erlang-skel-double-separator-start 3)
  298. "%%% Supervisor callbacks" n
  299. (erlang-skel-double-separator-end 3) n
  300. (erlang-skel-separator-start 2)
  301. "%% @private" n
  302. "%% @doc" n
  303. "%% Whenever a supervisor is started using supervisor:start_link/[2,3]," n
  304. "%% this function is called by the new process to find out about" n
  305. "%% restart strategy, maximum restart frequency and child" n
  306. "%% specifications." n
  307. "%%" n
  308. "%% @spec init(Args) -> {ok, {SupFlags, [ChildSpec]}} |" n
  309. "%% ignore |" n
  310. "%% {error, Reason}" n
  311. (erlang-skel-separator-end 2)
  312. "init([]) ->" n>
  313. "RestartStrategy = one_for_one," n>
  314. "MaxRestarts = 1000," n>
  315. "MaxSecondsBetweenRestarts = 3600," n
  316. "" n>
  317. "SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}," n
  318. "" n>
  319. "Restart = permanent," n>
  320. "Shutdown = 2000," n>
  321. "Type = worker," n
  322. "" n>
  323. "AChild = {'AName', {'AModule', start_link, []}," n>
  324. "Restart, Shutdown, Type, ['AModule']}," n
  325. "" n>
  326. "{ok, {SupFlags, [AChild]}}." n
  327. n
  328. (erlang-skel-double-separator-start 3)
  329. "%%% Internal functions" n
  330. (erlang-skel-double-separator-end 3)
  331. )
  332. "*The template of an supervisor behaviour.
  333. Please see the function `tempo-define-template'.")
  334. (defvar erlang-skel-supervisor-bridge
  335. '((erlang-skel-include erlang-skel-large-header)
  336. "-behaviour(supervisor_bridge)." n n
  337. "%% API" n
  338. "-export([start_link/0])." n n
  339. "%% supervisor_bridge callbacks" n
  340. "-export([init/1, terminate/2])." n n
  341. "-define(SERVER, ?MODULE)." n n
  342. "-record(state, {})." n n
  343. (erlang-skel-double-separator-start 3)
  344. "%%% API" n
  345. (erlang-skel-double-separator-end 3) n
  346. (erlang-skel-separator-start 2)
  347. "%% @doc" n
  348. "%% Starts the supervisor bridge" n
  349. "%%" n
  350. "%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
  351. (erlang-skel-separator-end 2)
  352. "start_link() ->" n>
  353. "supervisor_bridge:start_link({local, ?SERVER}, ?MODULE, [])." n
  354. n
  355. (erlang-skel-double-separator-start 3)
  356. "%%% supervisor_bridge callbacks" n
  357. (erlang-skel-double-separator-end 3) n
  358. (erlang-skel-separator-start 2)
  359. "%% @private" n
  360. "%% @doc" n
  361. "%% Creates a supervisor_bridge process, linked to the calling process," n
  362. "%% which calls Module:init/1 to start the subsystem. To ensure a" n
  363. "%% synchronized start-up procedure, this function does not return" n
  364. "%% until Module:init/1 has returned." n
  365. "%%" n
  366. "%% @spec init(Args) -> {ok, Pid, State} |" n
  367. "%% ignore |" n
  368. "%% {error, Reason}" n
  369. (erlang-skel-separator-end 2)
  370. "init([]) ->" n>
  371. "case 'AModule':start_link() of" n>
  372. "{ok, Pid} ->" n>
  373. "{ok, Pid, #state{}};" n>
  374. "Error ->" n>
  375. "Error" n>
  376. "end." n
  377. n
  378. (erlang-skel-separator-start 2)
  379. "%% @private" n
  380. "%% @doc" n
  381. "%% This function is called by the supervisor_bridge when it is about" n
  382. "%% to terminate. It should be the opposite of Module:init/1 and stop" n
  383. "%% the subsystem and do any necessary cleaning up.The return value is" n
  384. "%% ignored." n
  385. "%%" n
  386. "%% @spec terminate(Reason, State) -> void()" n
  387. (erlang-skel-separator-end 2)
  388. "terminate(Reason, State) ->" n>
  389. "'AModule':stop()," n>
  390. "ok." n
  391. n
  392. (erlang-skel-double-separator-start 3)
  393. "%%% Internal functions" n
  394. (erlang-skel-double-separator-end 3)
  395. )
  396. "*The template of an supervisor_bridge behaviour.
  397. Please see the function `tempo-define-template'.")
  398. (defvar erlang-skel-generic-server
  399. '((erlang-skel-include erlang-skel-large-header)
  400. "-behaviour(gen_server)." n n
  401. "%% API" n
  402. "-export([start_link/0])." n n
  403. "%% gen_server callbacks" n
  404. "-export([init/1, handle_call/3, handle_cast/2, "
  405. "handle_info/2," n>
  406. "terminate/2, code_change/3])." n n
  407. "-define(SERVER, ?MODULE). " n n
  408. "-record(state, {})." n n
  409. (erlang-skel-double-separator-start 3)
  410. "%%% API" n
  411. (erlang-skel-double-separator-end 3) n
  412. (erlang-skel-separator-start 2)
  413. "%% @doc" n
  414. "%% Starts the server" n
  415. "%%" n
  416. "%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
  417. (erlang-skel-separator-end 2)
  418. "start_link() ->" n>
  419. "gen_server:start_link({local, ?SERVER}, ?MODULE, [], [])." n
  420. n
  421. (erlang-skel-double-separator-start 3)
  422. "%%% gen_server callbacks" n
  423. (erlang-skel-double-separator-end 3)
  424. n
  425. (erlang-skel-separator-start 2)
  426. "%% @private" n
  427. "%% @doc" n
  428. "%% Initializes the server" n
  429. "%%" n
  430. "%% @spec init(Args) -> {ok, State} |" n
  431. "%% {ok, State, Timeout} |" n
  432. "%% ignore |" n
  433. "%% {stop, Reason}" n
  434. (erlang-skel-separator-end 2)
  435. "init([]) ->" n>
  436. "{ok, #state{}}." n
  437. n
  438. (erlang-skel-separator-start 2)
  439. "%% @private" n
  440. "%% @doc" n
  441. "%% Handling call messages" n
  442. "%%" n
  443. "%% @spec handle_call(Request, From, State) ->" n
  444. "%% {reply, Reply, State} |" n
  445. "%% {reply, Reply, State, Timeout} |" n
  446. "%% {noreply, State} |" n
  447. "%% {noreply, State, Timeout} |" n
  448. "%% {stop, Reason, Reply, State} |" n
  449. "%% {stop, Reason, State}" n
  450. (erlang-skel-separator-end 2)
  451. "handle_call(_Request, _From, State) ->" n>
  452. "Reply = ok," n>
  453. "{reply, Reply, State}." n
  454. n
  455. (erlang-skel-separator-start 2)
  456. "%% @private" n
  457. "%% @doc" n
  458. "%% Handling cast messages" n
  459. "%%" n
  460. "%% @spec handle_cast(Msg, State) -> {noreply, State} |" n
  461. "%% {noreply, State, Timeout} |" n
  462. "%% {stop, Reason, State}" n
  463. (erlang-skel-separator-end 2)
  464. "handle_cast(_Msg, State) ->" n>
  465. "{noreply, State}." n
  466. n
  467. (erlang-skel-separator-start 2)
  468. "%% @private" n
  469. "%% @doc" n
  470. "%% Handling all non call/cast messages" n
  471. "%%" n
  472. "%% @spec handle_info(Info, State) -> {noreply, State} |" n
  473. "%% {noreply, State, Timeout} |" n
  474. "%% {stop, Reason, State}" n
  475. (erlang-skel-separator-end 2)
  476. "handle_info(_Info, State) ->" n>
  477. "{noreply, State}." n
  478. n
  479. (erlang-skel-separator-start 2)
  480. "%% @private" n
  481. "%% @doc" n
  482. "%% This function is called by a gen_server when it is about to" n
  483. "%% terminate. It should be the opposite of Module:init/1 and do any" n
  484. "%% necessary cleaning up. When it returns, the gen_server terminates" n
  485. "%% with Reason. The return value is ignored." n
  486. "%%" n
  487. "%% @spec terminate(Reason, State) -> void()" n
  488. (erlang-skel-separator-end 2)
  489. "terminate(_Reason, _State) ->" n>
  490. "ok." n
  491. n
  492. (erlang-skel-separator-start 2)
  493. "%% @private" n
  494. "%% @doc" n
  495. "%% Convert process state when code is changed" n
  496. "%%" n
  497. "%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
  498. (erlang-skel-separator-end 2)
  499. "code_change(_OldVsn, State, _Extra) ->" n>
  500. "{ok, State}." n
  501. n
  502. (erlang-skel-double-separator-start 3)
  503. "%%% Internal functions" n
  504. (erlang-skel-double-separator-end 3)
  505. )
  506. "*The template of a generic server.
  507. Please see the function `tempo-define-template'.")
  508. (defvar erlang-skel-gen-event
  509. '((erlang-skel-include erlang-skel-large-header)
  510. "-behaviour(gen_event)." n n
  511. "%% API" n
  512. "-export([start_link/0, add_handler/0])." n n
  513. "%% gen_event callbacks" n
  514. "-export([init/1, handle_event/2, handle_call/2, " n>
  515. "handle_info/2, terminate/2, code_change/3])." n n
  516. "-define(SERVER, ?MODULE). " n n
  517. "-record(state, {})." n n
  518. (erlang-skel-double-separator-start 3)
  519. "%%% gen_event callbacks" n
  520. (erlang-skel-double-separator-end 3) n
  521. (erlang-skel-separator-start 2)
  522. "%% @doc" n
  523. "%% Creates an event manager" n
  524. "%%" n
  525. "%% @spec start_link() -> {ok, Pid} | {error, Error}" n
  526. (erlang-skel-separator-end 2)
  527. "start_link() ->" n>
  528. "gen_event:start_link({local, ?SERVER})." n
  529. n
  530. (erlang-skel-separator-start 2)
  531. "%% @doc" n
  532. "%% Adds an event handler" n
  533. "%%" n
  534. "%% @spec add_handler() -> ok | {'EXIT', Reason} | term()" n
  535. (erlang-skel-separator-end 2)
  536. "add_handler() ->" n>
  537. "gen_event:add_handler(?SERVER, ?MODULE, [])." n
  538. n
  539. (erlang-skel-double-separator-start 3)
  540. "%%% gen_event callbacks" n
  541. (erlang-skel-double-separator-end 3) n
  542. (erlang-skel-separator-start 2)
  543. "%% @private" n
  544. "%% @doc" n
  545. "%% Whenever a new event handler is added to an event manager," n
  546. "%% this function is called to initialize the event handler." n
  547. "%%" n
  548. "%% @spec init(Args) -> {ok, State}" n
  549. (erlang-skel-separator-end 2)
  550. "init([]) ->" n>
  551. "{ok, #state{}}." n
  552. n
  553. (erlang-skel-separator-start 2)
  554. "%% @private" n
  555. "%% @doc" n
  556. "%% Whenever an event manager receives an event sent using" n
  557. "%% gen_event:notify/2 or gen_event:sync_notify/2, this function is" n
  558. "%% called for each installed event handler to handle the event." n
  559. "%%" n
  560. "%% @spec handle_event(Event, State) ->" n
  561. "%% {ok, State} |" n
  562. "%% {swap_handler, Args1, State1, Mod2, Args2} |"n
  563. "%% remove_handler" n
  564. (erlang-skel-separator-end 2)
  565. "handle_event(_Event, State) ->" n>
  566. "{ok, State}." n
  567. n
  568. (erlang-skel-separator-start 2)
  569. "%% @private" n
  570. "%% @doc" n
  571. "%% Whenever an event manager receives a request sent using" n
  572. "%% gen_event:call/3,4, this function is called for the specified" n
  573. "%% event handler to handle the request." n
  574. "%%" n
  575. "%% @spec handle_call(Request, State) ->" n
  576. "%% {ok, Reply, State} |" n
  577. "%% {swap_handler, Reply, Args1, State1, Mod2, Args2} |" n
  578. "%% {remove_handler, Reply}" n
  579. (erlang-skel-separator-end 2)
  580. "handle_call(_Request, State) ->" n>
  581. "Reply = ok," n>
  582. "{ok, Reply, State}." n
  583. n
  584. (erlang-skel-separator-start 2)
  585. "%% @private" n
  586. "%% @doc" n
  587. "%% This function is called for each installed event handler when" n
  588. "%% an event manager receives any other message than an event or a" n
  589. "%% synchronous request (or a system message)." n
  590. "%%" n
  591. "%% @spec handle_info(Info, State) ->" n
  592. "%% {ok, State} |" n
  593. "%% {swap_handler, Args1, State1, Mod2, Args2} |" n
  594. "%% remove_handler" n
  595. (erlang-skel-separator-end 2)
  596. "handle_info(_Info, State) ->" n>
  597. "{ok, State}." n
  598. n
  599. (erlang-skel-separator-start 2)
  600. "%% @private" n
  601. "%% @doc" n
  602. "%% Whenever an event handler is deleted from an event manager, this" n
  603. "%% function is called. It should be the opposite of Module:init/1 and" n
  604. "%% do any necessary cleaning up." n
  605. "%%" n
  606. "%% @spec terminate(Reason, State) -> void()" n
  607. (erlang-skel-separator-end 2)
  608. "terminate(_Reason, _State) ->" n>
  609. "ok." n
  610. n
  611. (erlang-skel-separator-start 2)
  612. "%% @private" n
  613. "%% @doc" n
  614. "%% Convert process state when code is changed" n
  615. "%%" n
  616. "%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
  617. (erlang-skel-separator-end 2)
  618. "code_change(_OldVsn, State, _Extra) ->" n>
  619. "{ok, State}." n
  620. n
  621. (erlang-skel-double-separator-start 3)
  622. "%%% Internal functions" n
  623. (erlang-skel-double-separator-end 3)
  624. )
  625. "*The template of a gen_event.
  626. Please see the function `tempo-define-template'.")
  627. (defvar erlang-skel-gen-fsm
  628. '((erlang-skel-include erlang-skel-large-header)
  629. "-behaviour(gen_fsm)." n n
  630. "%% API" n
  631. "-export([start_link/0])." n n
  632. "%% gen_fsm callbacks" n
  633. "-export([init/1, state_name/2, state_name/3, handle_event/3," n>
  634. "handle_sync_event/4, handle_info/3, terminate/3, code_change/4])." n n
  635. "-define(SERVER, ?MODULE)." n n
  636. "-record(state, {})." n n
  637. (erlang-skel-double-separator-start 3)
  638. "%%% API" n
  639. (erlang-skel-double-separator-end 3) n
  640. (erlang-skel-separator-start 2)
  641. "%% @doc" n
  642. "%% Creates a gen_fsm process which calls Module:init/1 to" n
  643. "%% initialize. To ensure a synchronized start-up procedure, this" n
  644. "%% function does not return until Module:init/1 has returned." n
  645. "%%" n
  646. "%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}" n
  647. (erlang-skel-separator-end 2)
  648. "start_link() ->" n>
  649. "gen_fsm:start_link({local, ?SERVER}, ?MODULE, [], [])." n
  650. n
  651. (erlang-skel-double-separator-start 3)
  652. "%%% gen_fsm callbacks" n
  653. (erlang-skel-double-separator-end 3) n
  654. (erlang-skel-separator-start 2)
  655. "%% @private" n
  656. "%% @doc" n
  657. "%% Whenever a gen_fsm is started using gen_fsm:start/[3,4] or" n
  658. "%% gen_fsm:start_link/[3,4], this function is called by the new" n
  659. "%% process to initialize." n
  660. "%%" n
  661. "%% @spec init(Args) -> {ok, StateName, State} |" n
  662. "%% {ok, StateName, State, Timeout} |" n
  663. "%% ignore |" n
  664. "%% {stop, StopReason}" n
  665. (erlang-skel-separator-end 2)
  666. "init([]) ->" n>
  667. "{ok, state_name, #state{}}." n
  668. n
  669. (erlang-skel-separator-start 2)
  670. "%% @private" n
  671. "%% @doc" n
  672. "%% There should be one instance of this function for each possible" n
  673. "%% state name. Whenever a gen_fsm receives an event sent using" n
  674. "%% gen_fsm:send_event/2, the instance of this function with the same" n
  675. "%% name as the current state name StateName is called to handle" n
  676. "%% the event. It is also called if a timeout occurs." n
  677. "%%" n
  678. "%% @spec state_name(Event, State) ->" n
  679. "%% {next_state, NextStateName, NextState} |" n
  680. "%% {next_state, NextStateName, NextState, Timeout} |" n
  681. "%% {stop, Reason, NewState}" n
  682. (erlang-skel-separator-end 2)
  683. "state_name(_Event, State) ->" n>
  684. "{next_state, state_name, State}." n
  685. n
  686. (erlang-skel-separator-start 2)
  687. "%% @private" n
  688. "%% @doc" n
  689. "%% There should be one instance of this function for each possible" n
  690. "%% state name. Whenever a gen_fsm receives an event sent using" n
  691. "%% gen_fsm:sync_send_event/[2,3], the instance of this function with" n
  692. "%% the same name as the current state name StateName is called to" n
  693. "%% handle the event." n
  694. "%%" n
  695. "%% @spec state_name(Event, From, State) ->" n
  696. "%% {next_state, NextStateName, NextState} |"n
  697. "%% {next_state, NextStateName, NextState, Timeout} |" n
  698. "%% {reply, Reply, NextStateName, NextState} |" n
  699. "%% {reply, Reply, NextStateName, NextState, Timeout} |" n
  700. "%% {stop, Reason, NewState} |" n
  701. "%% {stop, Reason, Reply, NewState}" n
  702. (erlang-skel-separator-end 2)
  703. "state_name(_Event, _From, State) ->" n>
  704. "Reply = ok," n>
  705. "{reply, Reply, state_name, State}." n
  706. n
  707. (erlang-skel-separator-start 2)
  708. "%% @private" n
  709. "%% @doc" n
  710. "%% Whenever a gen_fsm receives an event sent using" n
  711. "%% gen_fsm:send_all_state_event/2, this function is called to handle" n
  712. "%% the event." n
  713. "%%" n
  714. "%% @spec handle_event(Event, StateName, State) ->" n
  715. "%% {next_state, NextStateName, NextState} |" n
  716. "%% {next_state, NextStateName, NextState, Timeout} |" n
  717. "%% {stop, Reason, NewState}" n
  718. (erlang-skel-separator-end 2)
  719. "handle_event(_Event, StateName, State) ->" n>
  720. "{next_state, StateName, State}." n
  721. n
  722. (erlang-skel-separator-start 2)
  723. "%% @private" n
  724. "%% @doc" n
  725. "%% Whenever a gen_fsm receives an event sent using" n
  726. "%% gen_fsm:sync_send_all_state_event/[2,3], this function is called" n
  727. "%% to handle the event." n
  728. "%%" n
  729. "%% @spec handle_sync_event(Event, From, StateName, State) ->" n
  730. "%% {next_state, NextStateName, NextState} |" n
  731. "%% {next_state, NextStateName, NextState, Timeout} |" n
  732. "%% {reply, Reply, NextStateName, NextState} |" n
  733. "%% {reply, Reply, NextStateName, NextState, Timeout} |" n
  734. "%% {stop, Reason, NewState} |" n
  735. "%% {stop, Reason, Reply, NewState}" n
  736. (erlang-skel-separator-end 2)
  737. "handle_sync_event(_Event, _From, StateName, State) ->" n>
  738. "Reply = ok," n>
  739. "{reply, Reply, StateName, State}." n
  740. n
  741. (erlang-skel-separator-start 2)
  742. "%% @private" n
  743. "%% @doc" n
  744. "%% This function is called by a gen_fsm when it receives any" n
  745. "%% message other than a synchronous or asynchronous event" n
  746. "%% (or a system message)." n
  747. "%%" n
  748. "%% @spec handle_info(Info,StateName,State)->" n
  749. "%% {next_state, NextStateName, NextState} |" n
  750. "%% {next_state, NextStateName, NextState, Timeout} |" n
  751. "%% {stop, Reason, NewState}" n
  752. (erlang-skel-separator-end 2)
  753. "handle_info(_Info, StateName, State) ->" n>
  754. "{next_state, StateName, State}." n
  755. n
  756. (erlang-skel-separator-start 2)
  757. "%% @private" n
  758. "%% @doc" n
  759. "%% This function is called by a gen_fsm when it is about to" n
  760. "%% terminate. It should be the opposite of Module:init/1 and do any" n
  761. "%% necessary cleaning up. When it returns, the gen_fsm terminates with" n
  762. "%% Reason. The return value is ignored." n
  763. "%%" n
  764. "%% @spec terminate(Reason, StateName, State) -> void()" n
  765. (erlang-skel-separator-end 2)
  766. "terminate(_Reason, _StateName, _State) ->" n>
  767. "ok." n
  768. n
  769. (erlang-skel-separator-start 2)
  770. "%% @private" n
  771. "%% @doc" n
  772. "%% Convert process state when code is changed" n
  773. "%%" n
  774. "%% @spec code_change(OldVsn, StateName, State, Extra) ->" n
  775. "%% {ok, StateName, NewState}" n
  776. (erlang-skel-separator-end 2)
  777. "code_change(_OldVsn, StateName, State, _Extra) ->" n>
  778. "{ok, StateName, State}." n
  779. n
  780. (erlang-skel-double-separator-start 3)
  781. "%%% Internal functions" n
  782. (erlang-skel-double-separator-end 3)
  783. )
  784. "*The template of a gen_fsm.
  785. Please see the function `tempo-define-template'.")
  786. (defvar erlang-skel-lib
  787. '((erlang-skel-include erlang-skel-large-header)
  788. "%% API" n
  789. "-export([])." n n
  790. (erlang-skel-double-separator-start 3)
  791. "%%% API" n
  792. (erlang-skel-double-separator-end 3) n
  793. (erlang-skel-separator-start 2)
  794. "%% @doc" n
  795. "%% @spec" n
  796. (erlang-skel-separator-end 2)
  797. n
  798. (erlang-skel-double-separator-start 3)
  799. "%%% Internal functions" n
  800. (erlang-skel-double-separator-end 3)
  801. )
  802. "*The template of a library module.
  803. Please see the function `tempo-define-template'.")
  804. (defvar erlang-skel-corba-callback
  805. '((erlang-skel-include erlang-skel-large-header)
  806. "%% Include files" n n
  807. "%% API" n
  808. "-export([])." n n
  809. "%% Corba callbacks" n
  810. "-export([init/1, terminate/2, code_change/3])." n n
  811. "-record(state, {})." n n
  812. (erlang-skel-double-separator-start 3)
  813. "%%% Corba callbacks" n
  814. (erlang-skel-double-separator-end 3) n
  815. (erlang-skel-separator-start 2)
  816. "%% @private" n
  817. "%% @doc" n
  818. "%% Initializes the server" n
  819. "%%" n
  820. "%% @spec init(Args) -> {ok, State} |" n
  821. "%% {ok, State, Timeout} |" n
  822. "%% ignore |" n
  823. "%% {stop, Reason}" n
  824. (erlang-skel-separator-end 2)
  825. "init([]) ->" n>
  826. "{ok, #state{}}." n
  827. n
  828. (erlang-skel-separator-start 2)
  829. "%% @private" n
  830. "%% @doc" n
  831. "%% Shutdown the server" n
  832. "%%" n
  833. "%% @spec terminate(Reason, State) -> void()" n
  834. (erlang-skel-separator-end 2)
  835. "terminate(_Reason, _State) ->" n>
  836. "ok." n
  837. n
  838. (erlang-skel-separator-start 2)
  839. "%% @private" n
  840. "%% @doc" n
  841. "%% Convert process state when code is changed" n
  842. "%%" n
  843. "%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}" n
  844. (erlang-skel-separator-end 2)
  845. "code_change(_OldVsn, State, _Extra) ->" n>
  846. "{ok, State}." n
  847. n
  848. (erlang-skel-double-separator-start 3)
  849. "%%% Internal functions" n
  850. (erlang-skel-double-separator-end 3)
  851. )
  852. "*The template of a library module.
  853. Please see the function `tempo-define-template'.")
  854. (defvar erlang-skel-ts-test-suite
  855. '((erlang-skel-include erlang-skel-large-header)
  856. "%% Note: This directive should only be used in test suites." n
  857. "-compile(export_all)." n n
  858. "-include_lib(\"test_server/include/test_server.hrl\")." n n
  859. (erlang-skel-separator-start 2)
  860. "%% TEST SERVER CALLBACK FUNCTIONS" n
  861. (erlang-skel-separator 2)
  862. n
  863. (erlang-skel-separator-start 2)
  864. "%%" n
  865. "%% @doc" n
  866. "%% Initialization before the suite." n
  867. "%%" n
  868. "%% Config0 = Config1 = [tuple()]" n
  869. "%% A list of key/value pairs, holding the test case configuration." n
  870. "%% Reason = term()" n
  871. "%% The reason for skipping the suite." n
  872. "%%" n
  873. "%% Note: This function is free to add any key/value pairs to the Config" n
  874. "%% variable, but should NOT alter/remove any existing entries." n
  875. "%%" n
  876. "%% @spec init_per_suite(Config) -> Config" n
  877. (erlang-skel-separator-end 2)
  878. "init_per_suite(Config) ->" n >
  879. "Config." n n
  880. (erlang-skel-separator-start 2)
  881. "%% @doc" n
  882. "%% Cleanup after the suite." n
  883. "%% Config - [tuple()]" n
  884. "%% A list of key/value pairs, holding the test case configuration." n
  885. "%%" n
  886. "%% @spec end_per_suite(Config) -> _" n
  887. (erlang-skel-separator-end 2)
  888. "end_per_suite(_Config) ->" n >
  889. "ok." n n
  890. (erlang-skel-separator-start 2)
  891. "%% @doc" n
  892. "%% Initialization before each test case" n
  893. "%%" n
  894. "%% TestCase - atom()" n
  895. "%% Name of the test case that is about to be run." n
  896. "%% Config - [tuple()]" n
  897. "%% A list of key/value pairs, holding the test case configuration." n
  898. "%% Reason = term()" n
  899. "%% The reason for skipping the test case." n
  900. "%%" n
  901. "%% Note: This function is free to add any key/value pairs to the Config" n
  902. "%% variable, but should NOT alter/remove any existing entries." n
  903. "%%" n
  904. "%% @spec init_per_testcase(TestCase, Config) -> Config" n
  905. (erlang-skel-separator-end 2)
  906. "init_per_testcase(_TestCase, Config) ->" n >
  907. "Config." n n
  908. (erlang-skel-separator-start 2)
  909. "%% @doc" n
  910. "%% Cleanup after each test case" n
  911. "%%" n
  912. "%% TestCase = atom()" n
  913. "%% Name of the test case that is finished." n
  914. "%% Config = [tuple()]" n
  915. "%% A list of key/value pairs, holding the test case configuration." n
  916. "%%" n
  917. "%% @spec end_per_testcase(TestCase, Config) -> _" n
  918. (erlang-skel-separator-end 2)
  919. "end_per_testcase(_TestCase, _Config) ->" n >
  920. "ok."n n
  921. (erlang-skel-separator-start 2)
  922. "%% @doc" n
  923. "%% Returns a description of the test suite when" n
  924. "%% Clause == doc, and a test specification (list" n
  925. "%% of the conf and test cases in the suite) when" n
  926. "%% Clause == suite." n
  927. "%% Returns a list of all test cases in this test suite" n
  928. "%%" n
  929. "%% Clause = doc | suite" n
  930. "%% Indicates expected return value." n
  931. "%% Descr = [string()] | []" n
  932. "%% String that describes the test suite." n
  933. "%% Spec = [TestCase]" n
  934. "%% A test specification." n
  935. "%% TestCase = ConfCase | atom()" n
  936. "%% Configuration case, or the name of a test case function." n
  937. "%% ConfCase = {conf,Init,Spec,End} |" n
  938. "%% {conf,Properties,Init,Spec,End}" n
  939. "%% Init = End = {Mod,Func} | Func" n
  940. "%% Initialization and cleanup function." n
  941. "%% Mod = Func = atom()" n
  942. "%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]" n
  943. "%% Execution properties of the test cases (may be combined)." n
  944. "%% Shuffle = shuffle | {shuffle,Seed}" n
  945. "%% To get cases executed in random order." n
  946. "%% Seed = {integer(),integer(),integer()}" n
  947. "%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |" n
  948. "%% repeat_until_any_ok | repeat_until_any_fail" n
  949. "%% To get execution of cases repeated." n
  950. "%% N = integer() | forever" n
  951. "%% Reason = term()" n
  952. "%% The reason for skipping the test suite." n
  953. "%%" n
  954. "%% @spec all(Clause) -> TestCases" n
  955. (erlang-skel-separator-end 2)
  956. "all(doc) ->" n >
  957. "[\"Describe the main purpose of this suite\"];" n n
  958. "all(suite) -> " n >
  959. "[a_test_case]." n n
  960. n
  961. (erlang-skel-separator-start 2)
  962. "%% TEST CASES" n
  963. (erlang-skel-separator 2)
  964. n
  965. (erlang-skel-separator-start 2)
  966. "%% @doc" n
  967. "%% Test case function. Returns a description of the test" n
  968. "%% case (doc), then returns a test specification (suite)," n
  969. "%% or performs the actual test (Config)." n
  970. "%%" n
  971. "%% Arg = doc | suite | Config" n
  972. "%% Indicates expected behaviour and return value." n
  973. "%% Config = [tuple()]" n
  974. "%% A list of key/value pairs, holding the test case configuration." n
  975. "%% Descr = [string()] | []" n
  976. "%% String that describes the test case." n
  977. "%% Spec = [tuple()] | []" n
  978. "%% A test specification, see all/1." n
  979. "%% Reason = term()" n
  980. "%% The reason for skipping the test case." n
  981. "%%" n
  982. "%% @spec TestCase(Arg) -> Descr | Spec | ok | exit() | {skip,Reason}" n
  983. (erlang-skel-separator-end 2)
  984. "a_test_case(doc) -> " n >
  985. "[\"Describe the main purpose of this test case\"];" n n
  986. "a_test_case(suite) -> " n >
  987. "[];" n n
  988. "a_test_case(Config) when is_list(Config) -> " n >
  989. "ok." n
  990. )
  991. "*The template of a library module.
  992. Please see the function `tempo-define-template'.")
  993. (defvar erlang-skel-ct-test-suite-s
  994. '((erlang-skel-include erlang-skel-large-header)
  995. "-compile(export_all)." n n
  996. "-include_lib(\"common_test/include/ct.hrl\")." n n
  997. (erlang-skel-separator-start 2)
  998. "%% @spec suite() -> Info" n
  999. "%% Info = [tuple()]" n
  1000. (erlang-skel-separator-end 2)
  1001. "suite() ->" n >
  1002. "[{timetrap,{seconds,30}}]." n n
  1003. (erlang-skel-separator-start 2)
  1004. "%% @spec init_per_suite(Config0) ->" n
  1005. "%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
  1006. "%% Config0 = Config1 = [tuple()]" n
  1007. "%% Reason = term()" n
  1008. (erlang-skel-separator-end 2)
  1009. "init_per_suite(Config) ->" n >
  1010. "Config." n n
  1011. (erlang-skel-separator-start 2)
  1012. "%% @spec end_per_suite(Config0) -> void() | {save_config,Config1}" n
  1013. "%% Config0 = Config1 = [tuple()]" n
  1014. (erlang-skel-separator-end 2)
  1015. "end_per_suite(_Config) ->" n >
  1016. "ok." n n
  1017. (erlang-skel-separator-start 2)
  1018. "%% @spec init_per_group(GroupName, Config0) ->" n
  1019. "%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
  1020. "%% GroupName = atom()" n
  1021. "%% Config0 = Config1 = [tuple()]" n
  1022. "%% Reason = term()" n
  1023. (erlang-skel-separator-end 2)
  1024. "init_per_group(_GroupName, Config) ->" n >
  1025. "Config." n n
  1026. (erlang-skel-separator-start 2)
  1027. "%% @spec end_per_group(GroupName, Config0) ->" n
  1028. "%% void() | {save_config,Config1}" n
  1029. "%% GroupName = atom()" n
  1030. "%% Config0 = Config1 = [tuple()]" n
  1031. (erlang-skel-separator-end 2)
  1032. "end_per_group(_GroupName, _Config) ->" n >
  1033. "ok." n n
  1034. (erlang-skel-separator-start 2)
  1035. "%% @spec init_per_testcase(TestCase, Config0) ->" n
  1036. "%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
  1037. "%% TestCase = atom()" n
  1038. "%% Config0 = Config1 = [tuple()]" n
  1039. "%% Reason = term()" n
  1040. (erlang-skel-separator-end 2)
  1041. "init_per_testcase(_TestCase, Config) ->" n >
  1042. "Config." n n
  1043. (erlang-skel-separator-start 2)
  1044. "%% @spec end_per_testcase(TestCase, Config0) ->" n
  1045. "%% void() | {save_config,Config1} | {fail,Reason}" n
  1046. "%% TestCase = atom()" n
  1047. "%% Config0 = Config1 = [tuple()]" n
  1048. "%% Reason = term()" n
  1049. (erlang-skel-separator-end 2)
  1050. "end_per_testcase(_TestCase, _Config) ->" n >
  1051. "ok." n n
  1052. (erlang-skel-separator-start 2)
  1053. "%% @spec groups() -> [Group]" n
  1054. "%% Group = {GroupName,Properties,GroupsAndTestCases}" n
  1055. "%% GroupName = atom()" n
  1056. "%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]" n
  1057. "%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]" n
  1058. "%% TestCase = atom()" n
  1059. "%% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}}" n
  1060. "%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |" n
  1061. "%% repeat_until_any_ok | repeat_until_any_fail" n
  1062. "%% N = integer() | forever" n
  1063. (erlang-skel-separator-end 2)
  1064. "groups() ->" n >
  1065. "[]." n n
  1066. (erlang-skel-separator-start 2)
  1067. "%% @spec all() -> GroupsAndTestCases | {skip,Reason}" n
  1068. "%% GroupsAndTestCases = [{group,GroupName} | TestCase]" n
  1069. "%% GroupName = atom()" n
  1070. "%% TestCase = atom()" n
  1071. "%% Reason = term()" n
  1072. (erlang-skel-separator-end 2)
  1073. "all() -> " n >
  1074. "[my_test_case]." n n
  1075. (erlang-skel-separator-start 2)
  1076. "%% @spec TestCase() -> Info" n
  1077. "%% Info = [tuple()]" n
  1078. (erlang-skel-separator-end 2)
  1079. "my_test_case() -> " n >
  1080. "[]." n n
  1081. (erlang-skel-separator-start 2)
  1082. "%% @spec TestCase(Config0) ->" n
  1083. "%% ok | exit() | {skip,Reason} | {comment,Comment} |" n
  1084. "%% {save_config,Config1} | {skip_and_save,Reason,Config1}" n
  1085. "%% Config0 = Config1 = [tuple()]" n
  1086. "%% Reason = term()" n
  1087. "%% Comment = term()" n
  1088. (erlang-skel-separator-end 2)
  1089. "my_test_case(_Config) -> " n >
  1090. "ok." n
  1091. )
  1092. "*The template of a library module.
  1093. Please see the function `tempo-define-template'.")
  1094. (defvar erlang-skel-ct-test-suite-l
  1095. '((erlang-skel-include erlang-skel-large-header)
  1096. "%% Note: This directive should only be used in test suites." n
  1097. "-compile(export_all)." n n
  1098. "-include_lib(\"common_test/include/ct.hrl\")." n n
  1099. (erlang-skel-separator-start 2)
  1100. "%% COMMON TEST CALLBACK FUNCTIONS" n
  1101. (erlang-skel-separator 2)
  1102. n
  1103. (erlang-skel-separator-start 2)
  1104. "%% @doc" n
  1105. "%% Returns list of tuples to set default properties" n
  1106. "%% for the suite." n
  1107. "%%" n
  1108. "%% Function: suite() -> Info" n
  1109. "%%" n
  1110. "%% Info = [tuple()]" n
  1111. "%% List of key/value pairs." n
  1112. "%%" n
  1113. "%% Note: The suite/0 function is only meant to be used to return" n
  1114. "%% default data values, not perform any other operations." n
  1115. "%%" n
  1116. "%% @spec suite() -> Info" n
  1117. (erlang-skel-separator-end 2)
  1118. "suite() ->" n >
  1119. "[{timetrap,{minutes,10}}]." n n
  1120. (erlang-skel-separator-start 2)
  1121. "%% @doc" n
  1122. "%% Initialization before the whole suite" n
  1123. "%%" n
  1124. "%% Config0 = Config1 = [tuple()]" n
  1125. "%% A list of key/value pairs, holding the test case configuration." n
  1126. "%% Reason = term()" n
  1127. "%% The reason for skipping the suite." n
  1128. "%%" n
  1129. "%% Note: This function is free to add any key/value pairs to the Config" n
  1130. "%% variable, but should NOT alter/remove any existing entries." n
  1131. "%%" n
  1132. "%% @spec init_per_suite(Config0) ->" n
  1133. "%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
  1134. (erlang-skel-separator-end 2)
  1135. "init_per_suite(Config) ->" n >
  1136. "Config." n n
  1137. (erlang-skel-separator-start 2)
  1138. "%% @doc" n
  1139. "%% Cleanup after the whole suite" n
  1140. "%%" n
  1141. "%% Config - [tuple()]" n
  1142. "%% A list of key/value pairs, holding the test case configuration." n
  1143. "%%" n
  1144. "%% @spec end_per_suite(Config) -> _" n
  1145. (erlang-skel-separator-end 2)
  1146. "end_per_suite(_Config) ->" n >
  1147. "ok." n n
  1148. (erlang-skel-separator-start 2)
  1149. "%% @doc" n
  1150. "%% Initialization before each test case group." n
  1151. "%%" n
  1152. "%% GroupName = atom()" n
  1153. "%% Name of the test case group that is about to run." n
  1154. "%% Config0 = Config1 = [tuple()]" n
  1155. "%% A list of key/value pairs, holding configuration data for the group." n
  1156. "%% Reason = term()" n
  1157. "%% The reason for skipping all test cases and subgroups in the group." n
  1158. "%%" n
  1159. "%% @spec init_per_group(GroupName, Config0) ->" n
  1160. "%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
  1161. (erlang-skel-separator-end 2)
  1162. "init_per_group(_GroupName, Config) ->" n >
  1163. "Config." n n
  1164. (erlang-skel-separator-start 2)
  1165. "%% @doc" n
  1166. "%% Cleanup after each test case group." n
  1167. "%%" n
  1168. "%% GroupName = atom()" n
  1169. "%% Name of the test case group that is finished." n
  1170. "%% Config0 = Config1 = [tuple()]" n
  1171. "%% A list of key/value pairs, holding configuration data for the group." n
  1172. "%%" n
  1173. "%% @spec end_per_group(GroupName, Config0) ->" n
  1174. "%% void() | {save_config,Config1}" n
  1175. (erlang-skel-separator-end 2)
  1176. "end_per_group(_GroupName, _Config) ->" n >
  1177. "ok." n n
  1178. (erlang-skel-separator-start 2)
  1179. "%% @doc" n
  1180. "%% Initialization before each test case" n
  1181. "%%" n
  1182. "%% TestCase - atom()" n
  1183. "%% Name of the test case that is about to be run." n
  1184. "%% Config0 = Config1 = [tuple()]" n
  1185. "%% A list of key/value pairs, holding the test case configuration." n
  1186. "%% Reason = term()" n
  1187. "%% The reason for skipping the test case." n
  1188. "%%" n
  1189. "%% Note: This function is free to add any key/value pairs to the Config" n
  1190. "%% variable, but should NOT alter/remove any existing entries." n
  1191. "%%" n
  1192. "%% @spec init_per_testcase(TestCase, Config0) ->" n
  1193. "%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}" n
  1194. (erlang-skel-separator-end 2)
  1195. "init_per_testcase(_TestCase, Config) ->" n >
  1196. "Config." n n
  1197. (erlang-skel-separator-start 2)
  1198. "%% @doc" n
  1199. "%% Cleanup after each test case" n
  1200. "%%" n
  1201. "%% TestCase - atom()" n
  1202. "%% Name of the test case that is finished." n
  1203. "%% Config0 = Config1 = [tuple()]" n
  1204. "%% A list of key/value pairs, holding the test case configuration." n
  1205. "%%" n
  1206. "%% @spec end_per_testcase(TestCase, Config0) ->" n
  1207. "%% void() | {save_config,Config1} | {fail,Reason}" n
  1208. (erlang-skel-separator-end 2)
  1209. "end_per_testcase(_TestCase, _Config) ->" n >
  1210. "ok." n n
  1211. (erlang-skel-separator-start 2)
  1212. "%% @doc" n
  1213. "%% Returns a list of test case group definitions." n
  1214. "%%" n
  1215. "%% Group = {GroupName,Properties,GroupsAndTestCases}" n
  1216. "%% GroupName = atom()" n
  1217. "%% The name of the group." n
  1218. "%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}]" n
  1219. "%% Group properties that may be combined." n
  1220. "%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase]" n
  1221. "%% TestCase = atom()" n
  1222. "%% The name of a test case." n
  1223. "%% Shuffle = shuffle | {shuffle,Seed}" n
  1224. "%% To get cases executed in random order." n
  1225. "%% Seed = {integer(),integer(),integer()}" n
  1226. "%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail |" n
  1227. "%% repeat_until_any_ok | repeat_until_any_fail" n
  1228. "%% To get execution of cases repeated." n
  1229. "%% N = integer() | forever" n
  1230. "%%" n
  1231. "%% @spec: groups() -> [Group]" n
  1232. (erlang-skel-separator-end 2)
  1233. "groups() ->" n >
  1234. "[]." n n
  1235. (erlang-skel-separator-start 2)
  1236. "%% @doc" n
  1237. "%% Returns the list of groups and test cases that" n
  1238. "%% are to be executed." n
  1239. "%%" n
  1240. "%% GroupsAndTestCases = [{group,GroupName} | TestCase]" n
  1241. "%% GroupName = atom()" n
  1242. "%% Name of a test case group." n
  1243. "%% TestCase = atom()" n
  1244. "%% Name of a test case." n
  1245. "%% Reason = term()" n
  1246. "%% The reason for skipping all groups and test cases." n
  1247. "%%" n
  1248. "%% @spec all() -> GroupsAndTestCases | {skip,Reason}" n
  1249. (erlang-skel-separator-end 2)
  1250. "all() -> " n >
  1251. "[my_test_case]." n n
  1252. n
  1253. (erlang-skel-separator-start 2)
  1254. "%% TEST CASES" n
  1255. (erlang-skel-separator 2)
  1256. n
  1257. (erlang-skel-separator-start 2)
  1258. "%% @doc " n
  1259. "%% Test case info function - returns list of tuples to set" n
  1260. "%% properties for the test case." n
  1261. "%%" n
  1262. "%% Info = [tuple()]" n
  1263. "%% List of key/value pairs." n
  1264. "%%" n
  1265. "%% Note: This function is only meant to be used to return a list of" n
  1266. "%% values, not perform any other operations." n
  1267. "%%" n
  1268. "%% @spec TestCase() -> Info " n
  1269. (erlang-skel-separator-end 2)
  1270. "my_test_case() -> " n >
  1271. "[]." n n
  1272. (erlang-skel-separator 2)
  1273. "%% @doc Test case function. (The name of it must be specified in" n
  1274. "%% the all/0 list or in a test case group for the test case" n
  1275. "%% to be executed)." n
  1276. "%%" n
  1277. "%% Config0 = Config1 = [tuple()]" n
  1278. "%% A list of key/value pairs, holding the test case configuration." n
  1279. "%% Reason = term()" n
  1280. "%% The reason for skipping the test case." n
  1281. "%% Comment = term()" n
  1282. "%% A comment about the test case that will be printed in the html log." n
  1283. "%%" n
  1284. "%% @spec TestCase(Config0) ->" n
  1285. "%% ok | exit() | {skip,Reason} | {comment,Comment} |" n
  1286. "%% {save_config,Config1} | {skip_and_save,Reason,Config1}" n
  1287. (erlang-skel-separator-end 2)
  1288. "my_test_case(_Config) -> " n >
  1289. "ok." n
  1290. )
  1291. "*The template of a library module.
  1292. Please see the function `tempo-define-template'.")
  1293. ;; Skeleton code:
  1294. ;; This code is based on the package `tempo' which is part of modern
  1295. ;; Emacsen. (GNU Emacs 19.25 (?) and XEmacs 19.14.)
  1296. (defun erlang-skel-init ()
  1297. "Generate the skeleton functions and menu items.
  1298. The variable `erlang-skel' contains the name and descriptions of
  1299. all skeletons.
  1300. The skeleton routines are based on the `tempo' package. Should this
  1301. package not be present, this function does nothing."
  1302. (interactive)
  1303. (condition-case nil
  1304. (require 'tempo)
  1305. (error t))
  1306. (if (featurep 'tempo)
  1307. (let ((skel erlang-skel)
  1308. (menu '()))
  1309. (while skel
  1310. (cond ((null (car skel))
  1311. (setq menu (cons nil menu)))
  1312. (t
  1313. (funcall (symbol-function 'tempo-define-template)
  1314. (concat "erlang-" (nth 1 (car skel)))
  1315. ;; The tempo template used contains an `include'
  1316. ;; function call only, hence changes to the
  1317. ;; variables describing the templates take effect
  1318. ;; immdiately.
  1319. (list (list 'erlang-skel-include (nth 2 (car skel))))
  1320. (nth 1 (car skel)))
  1321. (setq menu (cons (erlang-skel-make-menu-item
  1322. (car skel)) menu))))
  1323. (setq skel (cdr skel)))
  1324. (setq erlang-menu-skel-items
  1325. (list nil (list "Skeletons" (nreverse menu))))
  1326. (setq erlang-menu-items
  1327. (erlang-menu-add-above 'erlang-menu-skel-items
  1328. 'erlang-menu-version-items
  1329. erlang-menu-items))
  1330. (erlang-menu-init))))
  1331. (defun erlang-skel-make-menu-item (skel)
  1332. (let ((func (intern (concat "tempo-template-erlang-" (nth 1 skel)))))
  1333. (cond ((null (nth 3 skel))
  1334. (list (car skel) func))
  1335. (t
  1336. (list (car skel)
  1337. (list 'lambda '()
  1338. '(interactive)
  1339. (list 'funcall
  1340. (list 'quote (nth 3 skel))
  1341. (list 'quote func))))))))
  1342. ;; Functions designed to be added to the skeleton menu.
  1343. ;; (Not normally used)
  1344. (defun erlang-skel-insert (func)
  1345. "Insert skeleton generated by FUNC and goto first tempo mark."
  1346. (save-excursion (funcall func))
  1347. (funcall (symbol-function 'tempo-forward-mark)))
  1348. (defun erlang-skel-header (func)
  1349. "Insert the header generated by FUNC at the beginning of the buffer."
  1350. (goto-char (point-min))
  1351. (save-excursion (funcall func))
  1352. (funcall (symbol-function 'tempo-forward-mark)))
  1353. ;; Functions used inside the skeleton descriptions.
  1354. (defun erlang-skel-skip-blank ()
  1355. (skip-chars-backward " \t")
  1356. nil)
  1357. (defun erlang-skel-include (&rest args)
  1358. "Include a template inside another template.
  1359. Example of use, assuming that `erlang-skel-func' is defined:
  1360. (defvar foo-skeleton '(\"%%% New function:\"
  1361. (erlang-skel-include erlang-skel-func)))
  1362. Technically, this function returns the `tempo' attribute`(l ...)' which
  1363. can contain other `tempo' attributes. Please see the function
  1364. `tempo-define-template' for a description of the `(l ...)' attribute."
  1365. (let ((res '())
  1366. entry)
  1367. (while args
  1368. (setq entry (car args))
  1369. (while entry
  1370. (setq res (cons (car entry) res))
  1371. (setq entry (cdr entry)))
  1372. (setq args (cdr args)))
  1373. (cons 'l (nreverse res))))
  1374. (defun erlang-skel-separator (&optional percent)
  1375. "Return a comment separator."
  1376. (let ((percent (or percent 3)))
  1377. (concat (make-string percent ?%)
  1378. (make-string (- 70 percent) ?-)
  1379. "\n")))
  1380. (defun erlang-skel-separator-start (&optional percent)
  1381. "Return a comment separator or an empty string if separators
  1382. are configured off."
  1383. (if erlang-skel-use-separators
  1384. (erlang-skel-separator percent)
  1385. ""))
  1386. (defun erlang-skel-separator-end (&optional percent)
  1387. "Return a comment separator to end a function comment block or an
  1388. empty string if separators are configured off."
  1389. (if erlang-skel-use-separators
  1390. (concat "%% @end\n" (erlang-skel-separator percent))
  1391. ""))
  1392. (defun erlang-skel-double-separator (&optional percent)
  1393. "Return a double line (equals sign) comment separator."
  1394. (let ((percent (or percent 3)))
  1395. (concat (make-string percent ?%)
  1396. (make-string (- 70 percent) ?=)
  1397. "\n")))
  1398. (defun erlang-skel-double-separator-start (&optional percent)
  1399. "Return a double separator or a newline if separators are configured off."
  1400. (if erlang-skel-use-separators
  1401. (erlang-skel-double-separator percent)
  1402. "\n"))
  1403. (defun erlang-skel-double-separator-end (&optional percent)
  1404. "Return a double separator or an empty string if separators are
  1405. configured off."
  1406. (if erlang-skel-use-separators
  1407. (erlang-skel-double-separator percent)
  1408. ""))
  1409. (defun erlang-skel-dd-mmm-yyyy ()
  1410. "Return the current date as a string in \"DD Mon YYYY\" form.
  1411. The first character of DD is space if the value is less than 10."
  1412. (let ((date (current-time-string)))
  1413. (format "%2d %s %s"
  1414. (string-to-int (substring date 8 10))
  1415. (substring date 4 7)
  1416. (substring date -4))))
  1417. ;; Local variables:
  1418. ;; coding: iso-8859-1
  1419. ;; End:
  1420. ;;; erlang-skels.el ends here