Elixir cleanup + 5 useful snippets (#245)

* removed trailing newline from elixir snippets

* 5 convenience snippets I often use
This commit is contained in:
Wahed Mangal 2018-01-06 22:17:06 +01:00 committed by Andrea Crotti
parent 7fc2b95e2f
commit 2bb3cc1b2e
28 changed files with 55 additions and 23 deletions

View file

@ -0,0 +1,6 @@
## -*- mode: snippet -*-
# name : after
# key: after
# --
after ${1:500} ->
$0

View file

@ -2,4 +2,4 @@
# name: call # name: call
# key: call # key: call
# -- # --
GenServer.call(${1:__MODULE__}, $0) GenServer.call(${1:__MODULE__}, $0)

View file

@ -4,4 +4,4 @@
# -- # --
case $1 do case $1 do
$0 $0
end end

View file

@ -2,4 +2,4 @@
# name: cast # name: cast
# key: cast # key: cast
# -- # --
GenServer.cast(${1:__MODULE__}, $0) GenServer.cast(${1:__MODULE__}, $0)

View file

@ -4,4 +4,4 @@
# -- # --
cond do cond do
$0 $0
end end

View file

@ -4,4 +4,4 @@
# -- # --
def ${1:function}${2:(${3:args})} do def ${1:function}${2:(${3:args})} do
$0 $0
end end

View file

@ -4,4 +4,4 @@
# -- # --
defmacro $1 do defmacro $1 do
$0 $0
end end

View file

@ -4,4 +4,4 @@
# -- # --
defmacrop $1 do defmacrop $1 do
$0 $0
end end

View file

@ -4,4 +4,4 @@
# -- # --
defmodule $1 do defmodule $1 do
$0 $0
end end

View file

@ -0,0 +1,7 @@
## -*- mode: snippet -*-
# name : defmodule XXX end
# key: dm
# --
defmodule ${1:`(concat (capitalize (file-name-nondirectory (directory-file-name (file-name-directory buffer-file-name)))) ".")`}${2:`(mapconcat 'capitalize (split-string (file-name-base) "_") "")`} do
$0
end

View file

@ -4,4 +4,4 @@
# -- # --
defp $1 do defp $1 do
$0 $0
end end

View file

@ -4,4 +4,4 @@
# -- # --
do do
$0 $0
end end

View file

@ -4,4 +4,4 @@
# -- # --
@doc """ @doc """
$0 $0
""" """

View file

@ -4,4 +4,4 @@
# -- # --
for ${2:x} <- ${1:enum} do for ${2:x} <- ${1:enum} do
$2$0 $2$0
end end

View file

@ -0,0 +1,7 @@
## -*- mode: snippet -*-
# name : function
# key: dfun
# --
def $1($2)${3:$$(when (and yas-moving-away-p yas-modified-p) (concat " when " yas-text))} do
$0
end

View file

@ -0,0 +1,5 @@
## -*- mode: snippet -*-
# name : function-one-line
# key: df
# --
def $1($2)${3:$$(when (and yas-moving-away-p yas-modified-p) (concat " when " yas-text))}, do: $0

View file

@ -5,4 +5,4 @@
def handle_call($1, _from, state) do def handle_call($1, _from, state) do
reply = $0 reply = $0
{:reply, reply, state} {:reply, reply, state}
end end

View file

@ -5,4 +5,4 @@
def handle_cast($1, state) do def handle_cast($1, state) do
$0 $0
{:noreply, state} {:noreply, state}
end end

View file

@ -5,4 +5,4 @@
def handle_info($1, state) do def handle_info($1, state) do
$0 $0
{:noreply, state} {:noreply, state}
end end

View file

@ -4,4 +4,4 @@
# -- # --
if ${1:condition} do if ${1:condition} do
$0 $0
end end

View file

@ -6,4 +6,4 @@ if ${1:condition} do
$2 $2
else else
$3 $3
end end

View file

@ -2,4 +2,4 @@
# name: io # name: io
# key: io # key: io
# -- # --
IO.puts("$1")$0 IO.puts("$1")$0

View file

@ -2,4 +2,4 @@
# name: iop # name: iop
# key: iop # key: iop
# -- # --
IO.puts("$1 #{inspect $1}")$0 IO.puts("$1 #{inspect $1}")$0

View file

@ -4,4 +4,4 @@
# -- # --
@moduledoc """ @moduledoc """
$0 $0
""" """

View file

@ -3,4 +3,4 @@
# key: pry # key: pry
# group: debug # group: debug
# -- # --
require IEx; IEx.pry require IEx; IEx.pry

View file

@ -0,0 +1,7 @@
## -*- mode: snippet -*-
# name : receive
# key: rcv
# --
receive do
$0
end

View file

@ -4,4 +4,4 @@
# -- # --
test "$1" do test "$1" do
$0 $0
end end

View file

@ -4,4 +4,4 @@
# -- # --
unless ${1:condition} do unless ${1:condition} do
$0 $0
end end