Open2
Elixirのスニペット/snippetのたたき台
- VSnipでの使用
- メモ
-
Enum.map()
以外も追加したいような、増えすぎるような、悩ましいところ -
def
とdefl
の違いである末尾のl
はワンラインのLineの l の意 - LiveViewを使っていると頻発する
socket.assigns
などを随時追加した方が良さそう - https://github.com/florinpatrascu/vscode-elixir-snippets あたりも参考
-
.vsnip/elixir.json
{
"chain": {
"prefix": "c",
"body": [
"|> "
]
},
"def": {
"prefix": "def",
"body": [
"def $1 do",
" $0",
"end"
]
},
"def short": {
"prefix": "defl",
"body": [
"def $1, do: $2"
]
},
"defp": {
"prefix": "defp",
"body": [
"defp $1 do",
" $0",
"end"
]
},
"defp short": {
"prefix": "defpl",
"body": [
"defp $1, do: $2"
]
},
"defdelegate": {
"prefix": "defd",
"body": [
"defdelegate $1, to: $2"
]
},
"defn": {
"prefix": "defn",
"body": [
"defn $1 do",
" $0",
"end"
]
},
"@moduledoc": {
"prefix": "@mod",
"body": [
"@moduledoc \"\"\"",
"$0",
"\"\"\""
]
},
"@doc": {
"prefix": "@doc",
"body": [
"@doc \"\"\"",
"$0",
"\"\"\""
]
},
"doc examples": {
"prefix": "doce",
"body": [
"## Examples",
"",
" iex> $1"
]
},
"io inspect": {
"prefix": "ioi",
"body": [
"IO.inspect($1, label: \"${2:\\n\\n}\")$0"
]
},
"here for io label": {
"prefix": "here",
"body": [
"\\n#{inspect __ENV__.context_modules}#{inspect __ENV__.function}\\n"
]
},
"function": {
"prefix": "f",
"body": [
"fn $1 ->",
" $0",
"end"
]
},
"function short": {
"prefix": "fl",
"body": [
"& &1"
]
},
"then function": {
"prefix": "ct",
"body": [
"|> then(fn $1 ->",
" $0",
"end)"
]
},
"then function short": {
"prefix": "ctl",
"body": [
"|> then(& $0)"
]
},
"then with io inspection": {
"prefix": ["ctioi", "cioi"],
"body": [
"|> then(fn item -> IO.inspect($1item, label: \"${2:\\n\\n}\"); item end)$0"
]
},
"Enum start": {
"prefix": "e",
"body": [
"Enum.$1($0)"
]
},
"Enum start with chain": {
"prefix": "ce",
"body": [
"|> Enum.$1($0)"
]
},
"Enum.map with chain": {
"prefix": "cem",
"body": [
"|> Enum.map(& &1$0)"
]
},
"Map start": {
"prefix": "m",
"body": [
"Map.$1($0)"
]
},
"Map start with chain": {
"prefix": "cm",
"body": [
"|> Map.$1($0)"
]
},
"List start": {
"prefix": "l",
"body": [
"List$1"
]
},
"List start with chain": {
"prefix": "cl",
"body": [
"|> List.$1($0)"
]
},
"Keyword start": {
"prefix": "k",
"body": [
"Keyword.$1($0)"
]
},
"Keyword start with chain": {
"prefix": "ck",
"body": [
"|> Keyword.$1($0)"
]
},
"Flow map chain": {
"prefix": "flow",
"body": [
"|> Flow.from_enumerable()",
"|> Flow.map($0)",
"|> Enum.to_list()"
]
},
"defmacro using": {
"prefix": "defmu",
"body": [
"defmacro __using__(which) when is_atom(which) do",
" apply(__MODULE__, which, [])",
"end"
]
},
"live view socket.assigns": {
"prefix": "sa",
"body": [
"socket.assigns."
]
},
"live view assign": {
"prefix": "as",
"body": [
"assign($0)"
]
},
"live view handle_event": {
"prefix": "defhe",
"body": [
"@impl true",
"def handle_event(\"$1\", ${2:params}, socket) do",
" $3",
"end"
]
},
"live view handle_info": {
"prefix": "defhi",
"body": [
"@impl true",
"def handle_info({:$1}, socket) do",
" $2",
"end"
]
}
}