summaryrefslogtreecommitdiff
path: root/rc/base/lua.kak
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-01-29 09:03:23 +0000
committerMaxime Coste <frrrwww@gmail.com>2016-01-29 09:03:23 +0000
commitfef02779981acb6153396975ceaec0dbdbfb8d57 (patch)
tree3e204705c1d1ca60d639e80637fd07e4189359d6 /rc/base/lua.kak
parentc27778497eaddb0d3099cb3f2f7165ccc6b37634 (diff)
Reorganise rc/ into subdirectories
* core: set of tools to work on kakoune source code * base: very common languages and tools * extra: less common languages and tools
Diffstat (limited to 'rc/base/lua.kak')
-rw-r--r--rc/base/lua.kak88
1 files changed, 88 insertions, 0 deletions
diff --git a/rc/base/lua.kak b/rc/base/lua.kak
new file mode 100644
index 00000000..a1454759
--- /dev/null
+++ b/rc/base/lua.kak
@@ -0,0 +1,88 @@
+# http://lua.org
+# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+
+# require commenting.kak
+
+# Detection
+# ‾‾‾‾‾‾‾‾‾
+
+hook global BufSetOption mimetype=text/x-lua %{
+ set buffer filetype lua
+}
+
+hook global BufCreate .*[.](lua) %{
+ set buffer filetype lua
+}
+
+# Highlighters
+# ‾‾‾‾‾‾‾‾‾‾‾‾
+
+addhl -group / regions -default code lua \
+ string '"' (?<!\\)(\\\\)*" '' \
+ string "'" (?<!\\)(\\\\)*' '' \
+ comment '--' '$' '' \
+ comment '\Q--[[' ']]' '' \
+
+addhl -group /lua/string fill string
+
+addhl -group /lua/comment fill comment
+
+addhl -group /lua/code regex \<(and|break|do|else|elseif|end|false|for|function|goto|if|in|local|nil|not|or|repeat|return|then|true|until|while)\> 0:keyword
+
+# Commands
+# ‾‾‾‾‾‾‾‾
+
+def -hidden _lua_filter_around_selections %{
+ eval -draft -itersel %{
+ exec <a-x>
+ # remove trailing white spaces
+ try %{ exec -draft s \h + $ <ret> d }
+ }
+}
+
+def -hidden _lua_indent_on_char %{
+ eval -draft -itersel %{
+ # align end structure to start
+ try %{ exec -draft <a-x> <a-k> ^ \h * end $ <ret> <a-\;> <a-?> ^ \h * (for|function|if|while) <ret> s \A | \Z <ret> \' <a-&> }
+ # align _else_ statements to previous _if_
+ try %{ exec -draft <a-x> <a-k> ^ \h * else (if) ? $ <ret> <a-\;> <a-?> ^ \h * if <ret> s \A | \Z <ret> \' <a-&> }
+ }
+}
+
+def -hidden _lua_indent_on_new_line %{
+ eval -draft -itersel %{
+ # preserve previous line indent
+ try %{ exec -draft K <a-&> }
+ # filter previous line
+ try %{ exec -draft k : _lua_filter_around_selections <ret> }
+ # copy -- comment prefix and following white spaces
+ try %{ exec -draft k x s ^ \h * \K -- \h * <ret> y j p }
+ # indent after start structure
+ try %{ exec -draft k x <a-k> ^ \h * (else|elseif|for|function|if|while) \b <ret> j <a-gt> }
+ # wisely add end structure
+ eval -save-regs x %{
+ try %{ exec -draft k x s ^ \h + <ret> \" x y } catch %{ reg x '' }
+ try %{ exec -draft k x <a-k> ^ <c-r> x (for|function|if|while) <ret> j <a-a> i X <a-\;> K <a-K> ^ <c-r> x (for|function|if|while) . * \n <c-r> x end $ <ret> j x y p j a end <esc> <a-lt> }
+ }
+ }
+}
+
+# Initialization
+# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+
+hook global WinSetOption filetype=lua %{
+ addhl ref lua
+
+ hook window InsertEnd .* -group lua-hooks _lua_filter_around_selections
+ hook window InsertChar .* -group lua-indent _lua_indent_on_char
+ hook window InsertChar \n -group lua-indent _lua_indent_on_new_line
+
+ set window comment_line_chars '--'
+ set window comment_selection_chars '\Q--[[:]]'
+}
+
+hook global WinSetOption filetype=(?!lua).* %{
+ rmhl lua
+ rmhooks window lua-indent
+ rmhooks window lua-hooks
+}