# http://lua.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](lua) %{ set-option buffer filetype lua } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/lua regions add-highlighter shared/lua/code default-region group add-highlighter shared/lua/double_string region '"' (?^\h*(else)$^\h*(if)s\A|\z) } try %{ execute-keys -draft ^\h*(end)$^\h*(for|function|if|while)s\A|\z) } } } define-command -hidden lua-indent-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # remove trailing white spaces from previous line try %{ execute-keys -draft ks\h+$d } # indent after start structure try %{ execute-keys -draft k^\h*(else|elseif|for|function|if|while)\bj } } } define-command -hidden lua-insert-on-new-line %[ evaluate-commands -no-hooks -draft -itersel %[ # copy -- comment prefix and following white spaces try %{ execute-keys -draft ks^\h*\K--\h*yghjP } # wisely add end structure evaluate-commands -save-regs x %[ try %{ execute-keys -draft ks^\h+"xy } catch %{ reg x '' } # Save previous line indent in register x try %[ execute-keys -draft k ^x(for|function|if|while) J}iJ ^x(else|end|elseif)$ # Validate previous line and that it is not closed yet execute-keys -draft oxend ] # auto insert end ] ] ] # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group lua-highlight global WinSetOption filetype=lua %{ add-highlighter window/lua ref lua } hook global WinSetOption filetype=lua %{ hook window InsertChar .* -group lua-indent lua-indent-on-char hook window InsertChar \n -group lua-indent lua-indent-on-new-line hook window InsertChar \n -group lua-insert lua-insert-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 }