| 📦 Turbo Golo d710c1b k33g 22h ago | 1 | # turbo-golo snippets. |
| 2 | # |
| 3 | # Each [[snippet]] becomes one line of the Snippets menu. Snippets sharing a |
| 4 | # group appear together in a submenu of that name; one with no group goes into |
| 5 | # General. A snippet is inserted at the cursor, and every line after the |
| 6 | # first is indented to match the line you inserted it on. |
| 7 | # |
| 8 | # languages restricts a snippet to files of those kinds, by the names the |
| 9 | # editor uses: bash, dockerfile, golo, html, javascript, markdown, toml, xml, |
| 10 | # yaml. Leave it out and the snippet is offered everywhere. |
| 11 | # |
| 12 | # Bodies are indented with two spaces, which is what every example in the |
| 13 | # GoloScript documentation and its own templates use. Golo has no formatter to |
| 14 | # disagree with, so the convention is the only authority there is. |
| 15 | # |
| 16 | # Every Golo body below is written in single quotes — '''…''' rather than |
| 17 | # """…""" — because a Golo string carries \n and \" the way a Go string does, |
| 18 | # and TOML would interpret those escapes in a basic string before the editor |
| 19 | # ever saw them. In a literal string a backslash is just a backslash, which is |
| 20 | # what a Golo snippet needs. |
| 21 | # |
| 22 | # Your own snippets, shared across every project, go in: |
| 23 | # /Users/k33g/Library/Application Support/turbo-golo/snippets.toml |
| 24 | |
| 25 | [[snippet]] |
| 26 | name = "module" |
| 27 | group = "Golo" |
| 28 | languages = ["golo"] |
| 29 | body = ''' |
| 30 | module hello.World |
| 31 | |
| 32 | function main = |args| { |
| 33 | println("Hello, Golo!") |
| 34 | }''' |
| 35 | |
| 36 | [[snippet]] |
| 37 | name = "main" |
| 38 | group = "Golo" |
| 39 | languages = ["golo"] |
| 40 | body = ''' |
| 41 | function main = |args| { |
| 42 | println("Hello, Golo!") |
| 43 | }''' |
| 44 | |
| 45 | [[snippet]] |
| 46 | name = "function" |
| 47 | group = "Golo" |
| 48 | languages = ["golo"] |
| 49 | body = ''' |
| 50 | function name = |a, b| { |
| 51 | return a + b |
| 52 | }''' |
| 53 | |
| 54 | [[snippet]] |
| 55 | name = "closure" |
| 56 | group = "Golo" |
| 57 | languages = ["golo"] |
| 58 | body = ''' |
| 59 | let f = |x| -> x * 2''' |
| 60 | |
| 61 | [[snippet]] |
| 62 | name = "struct" |
| 63 | group = "Golo" |
| 64 | languages = ["golo"] |
| 65 | body = ''' |
| 66 | struct Point = { x, y }''' |
| 67 | |
| 68 | [[snippet]] |
| 69 | name = "union" |
| 70 | group = "Golo" |
| 71 | languages = ["golo"] |
| 72 | body = ''' |
| 73 | union Shape = { |
| 74 | Circle = { radius } |
| 75 | Rect = { width, height } |
| 76 | }''' |
| 77 | |
| 78 | [[snippet]] |
| 79 | name = "augment" |
| 80 | group = "Golo" |
| 81 | languages = ["golo"] |
| 82 | body = ''' |
| 83 | augment Point { |
| 84 | function describe = |this| -> "(" + this: x() + ", " + this: y() + ")" |
| 85 | }''' |
| 86 | |
| 87 | [[snippet]] |
| 88 | name = "match" |
| 89 | group = "Golo" |
| 90 | languages = ["golo"] |
| 91 | body = ''' |
| 92 | let label = match { |
| 93 | when n < 0 then "negative" |
| 94 | when n == 0 then "zero" |
| 95 | otherwise "positive" |
| 96 | }''' |
| 97 | |
| 98 | [[snippet]] |
| 99 | name = "foreach" |
| 100 | group = "Golo" |
| 101 | languages = ["golo"] |
| 102 | body = ''' |
| 103 | foreach item in list[1, 2, 3] { |
| 104 | println(item) |
| 105 | }''' |
| 106 | |
| 107 | [[snippet]] |
| 108 | name = "for" |
| 109 | group = "Golo" |
| 110 | languages = ["golo"] |
| 111 | body = ''' |
| 112 | for (var i = 0, i < 10, i = i + 1) { |
| 113 | println(i) |
| 114 | }''' |
| 115 | |
| 116 | [[snippet]] |
| 117 | name = "try" |
| 118 | group = "Golo" |
| 119 | languages = ["golo"] |
| 120 | body = ''' |
| 121 | try { |
| 122 | throw "boom" |
| 123 | } catch (e) { |
| 124 | println("caught: \"" + e + "\"") |
| 125 | } finally { |
| 126 | println("done") |
| 127 | }''' |
| 128 | |
| 129 | [[snippet]] |
| 130 | name = "comprehension" |
| 131 | group = "Golo" |
| 132 | languages = ["golo"] |
| 133 | body = ''' |
| 134 | let squares = list[x * x foreach x in range(1, 6) when x > 2]''' |
| 135 | |
| 136 | [[snippet]] |
| 137 | group = "General" |
| 138 | name = "Hello" |
| 139 | body = "Hello!!!" |
| 140 | |
| 141 | [[snippet]] |
| 142 | group = "Markdown" |
| 143 | name = "Image" |
| 144 | languages = ["markdown"] |
| 145 | body = "" |