index.html 2.1 KB

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