From 392efda0dce11fc61771fab34f29000d786df294 Mon Sep 17 00:00:00 2001 From: Aron Griffis Date: Sat, 23 Jun 2018 20:44:59 -0400 Subject: [PATCH] Make languages & policies user-configurable Add three configurables: - g:vue_indent_languages replaces s:languages. It can be configured before or after loading indent/vue.vim, and can be modified on the fly. - g:vue_indent_open_close_tags configures the policy for indenting open/close tags. It defaults to 0 which forces open/close tags for sections in a vue single-file component to the first column. - g:vue_indent_first_line configures the policy for indenting the first line after an open tag. It defaults to -1 which uses the autoindent default, i.e. the same column as the open tag. It will also preserve existing indentation when reindenting, which means that authors can use their preferred first line indentation without needing any special configuration. Additionally g:vue_indent_first_line can be overridden per-language by specifying a value for language.first_line. We use this for the 'html' language configuration to defer to html.vim for indenting the first line of an html template. Minor changes: - Since s:get_indentexpr is called lazily, it resets indentexpr before returning. - Use searchpair() to find the closing tag instead of a hard-coded list. - For development and debugging, it's possible to :echo GetVueIndent() which also enables error reporting and echom that are normally squelched when called as indentexpr. Note that although GetVueIndent() uses getpos('.') properly if line number isn't supplied, language indenters vary between getpos('.') and v:lnum, so this is mostly useful for debugging vue.vim's internal operation. --- indent/vue.vim | 119 ++++++++++++++++++++++++++++------------- readme.md | 31 +++++++++++ test/test_indent.vader | 111 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 224 insertions(+), 37 deletions(-) diff --git a/indent/vue.vim b/indent/vue.vim index 24fa37c..e972151 100644 --- a/indent/vue.vim +++ b/indent/vue.vim @@ -6,59 +6,104 @@ if exists('b:did_indent') finish endif - -function! s:get_indentexpr(language) - unlet! b:did_indent - execute 'runtime! indent/' . a:language . '.vim' - return &indentexpr -endfunction +let b:did_indent = 1 " The order is important here, tags without attributes go last. -" HTML is left out, it will be used when there is no match. -let s:languages = [ - \ { 'name': 'pug', 'pairs': ['