Merge remote-tracking branch 'SolitudeSF/nim'

This commit is contained in:
Maxime Coste 2017-12-11 08:48:50 +11:00
commit d494b9de34

View File

@ -4,7 +4,7 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*\.nim %{
hook global BufCreate .*\.nim(s|ble)? %{
set-option buffer filetype nim
}
@ -53,9 +53,37 @@ add-highlighter shared/nim/code regex %{'[^'\n]'} 0:string
add-highlighter shared/nim/code regex '#[^\n]+' 0:comment
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden nim-indent-on-new-line %{
eval -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ exec -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
# preserve previous line indent
try %{ exec -draft \; K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ exec -draft k <a-x> s \h+$ <ret> d }
# indent after line ending with const, let, var, ':' or '='
try %{ exec -draft <space> k x <a-k> (:|=|const|let|var)$ <ret> j <a-gt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook -group nim-highlight global WinSetOption filetype=nim %{ add-highlighter window ref nim }
hook global WinSetOption filetype=nim %{
set buffer tabstop 2
set buffer indentwidth 2
hook window InsertChar \n -group nim-indent nim-indent-on-new-line
# cleanup trailing whitespaces on current line insert end
hook window InsertEnd .* -group nim-indent %{ try %{ exec -draft \; <a-x> s ^\h+$ <ret> d } }
}
hook -group nim-highlight global WinSetOption filetype=(?!nim).* %{ remove-highlighter window/nim }
hook global WinSetOption filetype=(?!nim).* %{
remove-hooks window nim-indent
}