2
0

index.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CodeMirror: Erlang mode</title>
  6. <link rel="stylesheet" href="../../lib/codemirror.css">
  7. <script src="../../lib/codemirror.js"></script>
  8. <script src="../../addon/edit/matchbrackets.js"></script>
  9. <script src="erlang.js"></script>
  10. <link rel="stylesheet" href="../../theme/erlang-dark.css">
  11. <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  12. <link rel="stylesheet" href="../../doc/docs.css">
  13. </head>
  14. <body>
  15. <h1>CodeMirror: Erlang mode</h1>
  16. <form><textarea id="code" name="code">
  17. %% -*- mode: erlang; erlang-indent-level: 2 -*-
  18. %%% Created : 7 May 2012 by mats cronqvist <masse@klarna.com>
  19. %% @doc
  20. %% Demonstrates how to print a record.
  21. %% @end
  22. -module('ex').
  23. -author('mats cronqvist').
  24. -export([demo/0,
  25. rec_info/1]).
  26. -record(demo,{a="One",b="Two",c="Three",d="Four"}).
  27. rec_info(demo) -> record_info(fields,demo).
  28. demo() -> expand_recs(?MODULE,#demo{a="A",b="BB"}).
  29. expand_recs(M,List) when is_list(List) ->
  30. [expand_recs(M,L)||L<-List];
  31. expand_recs(M,Tup) when is_tuple(Tup) ->
  32. case tuple_size(Tup) of
  33. L when L < 1 -> Tup;
  34. L ->
  35. try Fields = M:rec_info(element(1,Tup)),
  36. L = length(Fields)+1,
  37. lists:zip(Fields,expand_recs(M,tl(tuple_to_list(Tup))))
  38. catch _:_ ->
  39. list_to_tuple(expand_recs(M,tuple_to_list(Tup)))
  40. end
  41. end;
  42. expand_recs(_,Term) ->
  43. Term.
  44. </textarea></form>
  45. <script>
  46. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  47. lineNumbers: true,
  48. matchBrackets: true,
  49. extraKeys: {"Tab": "indentAuto"},
  50. theme: "erlang-dark"
  51. });
  52. </script>
  53. <p><strong>MIME types defined:</strong> <code>text/x-erlang</code>.</p>
  54. </body>
  55. </html>