Add indentation hooks to kak
filetype support script
This commit is contained in:
parent
5ab60cde51
commit
4901a02e50
|
@ -1,7 +1,16 @@
|
||||||
|
# http://kakoune.org
|
||||||
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
||||||
|
|
||||||
|
# Detection
|
||||||
|
# ‾‾‾‾‾‾‾‾‾
|
||||||
|
|
||||||
hook global BufCreate (.*/)?(kakrc|.*.kak) %{
|
hook global BufCreate (.*/)?(kakrc|.*.kak) %{
|
||||||
set buffer filetype kak
|
set buffer filetype kak
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Highlighters & Completion
|
||||||
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
||||||
|
|
||||||
addhl -group / regions -default code kakrc \
|
addhl -group / regions -default code kakrc \
|
||||||
comment (^|\h)\K\# $ '' \
|
comment (^|\h)\K\# $ '' \
|
||||||
double_string %{(^|\h)"} %{(?<!\\)(\\\\)*"} '' \
|
double_string %{(^|\h)"} %{(?<!\\)(\\\\)*"} '' \
|
||||||
|
@ -37,5 +46,32 @@ addhl -group /kakrc/single_string fill string
|
||||||
addhl -group /kakrc/comment fill comment
|
addhl -group /kakrc/comment fill comment
|
||||||
addhl -group /kakrc/shell ref sh
|
addhl -group /kakrc/shell ref sh
|
||||||
|
|
||||||
|
# Commands
|
||||||
|
# ‾‾‾‾‾‾‾‾
|
||||||
|
|
||||||
|
def -hidden kak-indent-on-new-line %{
|
||||||
|
eval -draft -itersel %{
|
||||||
|
# preserve previous line indent
|
||||||
|
try %{ exec -draft <space> K <a-&> }
|
||||||
|
# cleanup trailing whitespaces from previous line
|
||||||
|
try %{ exec -draft k <a-x> s \h+$ <ret> d }
|
||||||
|
# copy '#' comment prefix and following white spaces
|
||||||
|
try %{ exec -draft k x s ^\h*#\h* <ret> y jgh P }
|
||||||
|
# indent after line ending with %[[:punct:]]
|
||||||
|
try %{ exec -draft k <a-x> <a-k> \%[[:punct:]]$ <ret> j <a-gt> }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialization
|
||||||
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
||||||
|
|
||||||
hook -group kak-highlight global WinSetOption filetype=kak %{ addhl ref kakrc }
|
hook -group kak-highlight global WinSetOption filetype=kak %{ addhl ref kakrc }
|
||||||
|
|
||||||
|
hook global WinSetOption filetype=kak %{
|
||||||
|
hook window InsertChar \n -group kak-indent kak-indent-on-new-line
|
||||||
|
# cleanup trailing whitespaces on current line insert end
|
||||||
|
hook window InsertEnd .* -group kak-indent %{ try %{ exec -draft \; <a-x> s ^\h+$ <ret> d } }
|
||||||
|
}
|
||||||
|
|
||||||
hook -group kak-highlight global WinSetOption filetype=(?!kak).* %{ rmhl kakrc }
|
hook -group kak-highlight global WinSetOption filetype=(?!kak).* %{ rmhl kakrc }
|
||||||
|
hook global WinSetOption filetype=(?!kak).* %{ rmhooks window kak-indent }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user