Merge remote-tracking branch 'greenfork/improve-elixir-hooks'

This commit is contained in:
Maxime Coste 2021-06-15 20:48:06 +10:00
commit 8fdda6d980
17 changed files with 84 additions and 7 deletions

View File

@ -19,8 +19,8 @@ hook global WinSetOption filetype=elixir %{
require-module elixir
hook window ModeChange pop:insert:.* -group elixir-trim-indent elixir-trim-indent
hook window InsertChar \n -group elixir-insert elixir-insert-on-new-line
hook window InsertChar \n -group elixir-indent elixir-indent-on-new-line
hook window InsertChar \n -group elixir-insert elixir-insert-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elixir-.+ }
}
@ -92,12 +92,25 @@ define-command -hidden elixir-trim-indent %{
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
}
define-command -hidden elixir-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy -- comments prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
}
}
define-command -hidden elixir-insert-on-new-line %[
evaluate-commands -no-hooks -draft -itersel %[
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y jgi P }
# wisely add end structure
evaluate-commands -save-regs x %[
try %{ execute-keys -draft k <a-x> s ^ \h + <ret> \" x y } catch %{ reg x '' }
try %[
evaluate-commands -draft %[
# Check if previous line opens a block
execute-keys -draft k<a-x> <a-k>^<c-r>x(.+\bdo$)<ret>
# Check that we do not already have an end for this indent level which is first set via `elixir-indent-on-new-line` hook
execute-keys -draft }i J <a-x> <a-K> ^<c-r>x(end|else)[^0-9A-Za-z_!?]<ret>
]
execute-keys -draft o<c-r>xend<esc> # insert a new line with containing end
]
]
]
]
define-command -hidden elixir-indent-on-new-line %{
evaluate-commands -draft -itersel %{

View File

@ -0,0 +1 @@
c<ret>f()<esc>jo<ret>def f1() do<ret>1<esc>jo<ret>def f2(), do: 2<ret>

View File

@ -0,0 +1 @@
test do%( )

View File

@ -0,0 +1,10 @@
test do
f()
end
def f1() do
1
end
def f2(), do: 2

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/elixir.kak"
set buffer filetype elixir

View File

@ -0,0 +1 @@
c<ret><esc>

View File

@ -0,0 +1,4 @@
def foo() do%( )
def bar() do
end

View File

@ -0,0 +1,6 @@
def foo() do
end
def bar() do
end

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/elixir.kak"
set buffer filetype elixir

View File

@ -0,0 +1 @@
c<ret><esc>

View File

@ -0,0 +1,3 @@
defmodule Module do
def test do%( )
end

View File

@ -0,0 +1,5 @@
defmodule Module do
def test do
end
end

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/elixir.kak"
set buffer filetype elixir

View File

@ -0,0 +1 @@
c<ret><esc><a-o>jo# comment3<ret>comment4<esc><a-o>jo# indented<ret>indented2<esc><a-o>jodef f() do<ret># comment<ret>comment2<esc>j<a-o>jodef f() do<ret># comment<esc>hhhi<ret>

View File

@ -0,0 +1 @@
# Comment %( )comment2

View File

@ -0,0 +1,18 @@
# Comment
# comment2
# comment3
# comment4
# indented
# indented2
def f() do
# comment
# comment2
end
def f() do
# comm
# ent
end

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/elixir.kak"
set buffer filetype elixir