# http://lua.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](lua) %{ set buffer filetype lua } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter -group / regions -default code lua \ string '"' (?s\h+$d } } } def -hidden _lua_indent_on_char %{ eval -no-hooks -draft -itersel %{ # align middle and end structures to start and indent when necessary, elseif is already covered by else try %{ exec -draft ^\h*(else)$^\h*(if)s\A|\Z' } try %{ exec -draft ^\h*(end)$^\h*(for|function|if|while)s\A|\Z' } } } def -hidden _lua_indent_on_new_line %{ eval -no-hooks -draft -itersel %{ # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k:_lua_filter_around_selections } # indent after start structure try %{ exec -draft k^\h*(else|elseif|for|function|if|while)\bj } } } def -hidden _lua_insert_on_new_line %{ eval -no-hooks -draft -itersel %{ # copy -- comment prefix and following white spaces try %{ exec -draft ks^\h*\K--\h*yjp } # wisely add end structure eval -save-regs x %{ try %{ exec -draft ks^\h+"xy } catch %{ reg x '' } try %{ exec -draft k^x(for|function|if|while)jiXK^x(for|function|if|while).*\nx(else|end|elseif[^\n]*)$jxypjaend } } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group lua-highlight global WinSetOption filetype=lua %{ add-highlighter ref lua } hook global WinSetOption filetype=lua %{ hook window InsertChar .* -group lua-indent _lua_indent_on_char hook window InsertChar \n -group lua-insert _lua_insert_on_new_line hook window InsertChar \n -group lua-indent _lua_indent_on_new_line alias window alt lua-alternative-file } hook -group lua-highlight global WinSetOption filetype=(?!lua).* %{ remove-highlighter lua } hook global WinSetOption filetype=(?!lua).* %{ remove-hooks window lua-indent remove-hooks window lua-insert unalias window alt lua-alternative-file }