Skip to content
Jan-Jaap Korpershoek edited this page Nov 3, 2019 · 7 revisions

Auto closing tags

Based on https://github.com/JJK96/kakoune-config/blob/master/autoload/html.kak

define-command -hidden html-auto-close-tag %{
    evaluate-commands -draft -itersel %{
        try %{
            # Check if last entered characters are "</"
            execute-keys -draft hH<a-k><lt><ret>
            # Get tag
            execute-keys Z[
            execute-keys -with-maps t
            execute-keys lt<gt>"ay
            # Paste tag
            execute-keys zh"a<a-p>
            # Close tag
            execute-keys -with-hooks a<gt>
        }
    }
}

hook global WinSetOption filetype=(xml|html|php) %{
    # Credits to mawww for this mapping
    map -docstring "xml tag object" global object t %{c<lt>([\w.]+)\b[^>]*?(?<lt>!/)>,<lt>/([\w.]+)\b[^>]*?(?<lt>!/)><ret>}
    hook window InsertChar '/' html-auto-close-tag
}
Clone this wiki locally