mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-23 23:34:12 +03:00
Merge remote-tracking branch 'greenfork/improve-elixir-hooks'
This commit is contained in:
commit
8fdda6d980
@ -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 %{
|
||||
|
1
test/indent/elixir/do-keyword/cmd
Normal file
1
test/indent/elixir/do-keyword/cmd
Normal file
@ -0,0 +1 @@
|
||||
c<ret>f()<esc>jo<ret>def f1() do<ret>1<esc>jo<ret>def f2(), do: 2<ret>
|
1
test/indent/elixir/do-keyword/in
Normal file
1
test/indent/elixir/do-keyword/in
Normal file
@ -0,0 +1 @@
|
||||
test do%( )
|
10
test/indent/elixir/do-keyword/out
Normal file
10
test/indent/elixir/do-keyword/out
Normal file
@ -0,0 +1,10 @@
|
||||
test do
|
||||
f()
|
||||
end
|
||||
|
||||
def f1() do
|
||||
1
|
||||
end
|
||||
|
||||
def f2(), do: 2
|
||||
|
3
test/indent/elixir/do-keyword/rc
Normal file
3
test/indent/elixir/do-keyword/rc
Normal file
@ -0,0 +1,3 @@
|
||||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/elixir.kak"
|
||||
set buffer filetype elixir
|
@ -0,0 +1 @@
|
||||
c<ret><esc>
|
@ -0,0 +1,4 @@
|
||||
def foo() do%( )
|
||||
|
||||
def bar() do
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
def foo() do
|
||||
|
||||
end
|
||||
|
||||
def bar() do
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/elixir.kak"
|
||||
set buffer filetype elixir
|
@ -0,0 +1 @@
|
||||
c<ret><esc>
|
@ -0,0 +1,3 @@
|
||||
defmodule Module do
|
||||
def test do%( )
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
defmodule Module do
|
||||
def test do
|
||||
|
||||
end
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/elixir.kak"
|
||||
set buffer filetype elixir
|
1
test/indent/elixir/insert-comment-hash/cmd
Normal file
1
test/indent/elixir/insert-comment-hash/cmd
Normal 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>
|
1
test/indent/elixir/insert-comment-hash/in
Normal file
1
test/indent/elixir/insert-comment-hash/in
Normal file
@ -0,0 +1 @@
|
||||
# Comment %( )comment2
|
18
test/indent/elixir/insert-comment-hash/out
Normal file
18
test/indent/elixir/insert-comment-hash/out
Normal file
@ -0,0 +1,18 @@
|
||||
# Comment
|
||||
# comment2
|
||||
|
||||
# comment3
|
||||
# comment4
|
||||
|
||||
# indented
|
||||
# indented2
|
||||
|
||||
def f() do
|
||||
# comment
|
||||
# comment2
|
||||
end
|
||||
|
||||
def f() do
|
||||
# comm
|
||||
# ent
|
||||
end
|
3
test/indent/elixir/insert-comment-hash/rc
Normal file
3
test/indent/elixir/insert-comment-hash/rc
Normal file
@ -0,0 +1,3 @@
|
||||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/elixir.kak"
|
||||
set buffer filetype elixir
|
Loading…
Reference in New Issue
Block a user