# http://lua.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](lua) %{ set buffer filetype lua } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/ 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*yghjP } # 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 window 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 window/lua } hook global WinSetOption filetype=(?!lua).* %{ remove-hooks window lua-indent remove-hooks window lua-insert unalias window alt lua-alternative-file }